fix: add product

This commit is contained in:
ferdiansyah783
2025-08-05 21:31:53 +07:00
parent 0fde122ac4
commit 799837e82e
14 changed files with 393 additions and 68 deletions
+25
View File
@@ -0,0 +1,25 @@
import { useMutation } from '@tanstack/react-query'
import { api } from '../api'
import { toast } from 'react-toastify'
export const useFilesMutation = {
uploadFile: () => {
return useMutation({
mutationFn: async (newFile: FormData) => {
const response = await api.post('/files/upload', newFile, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
return response.data.data
},
onSuccess: data => {
toast.success('File uploaded successfully!')
},
onError: (error: any) => {
toast.error(error.response.data.errors[0].cause)
}
})
}
}
+21
View File
@@ -0,0 +1,21 @@
import { useMutation } from '@tanstack/react-query'
import { api } from '../api'
import { toast } from 'react-toastify'
import { ProductRequest } from '../../types/services/product'
export const useProductsMutation = {
createProduct: () => {
return useMutation({
mutationFn: async (newProduct: ProductRequest) => {
const response = await api.post('/products', newProduct)
return response.data
},
onSuccess: data => {
toast.success('Product created successfully!')
},
onError: (error: any) => {
toast.error(error.response.data.errors[0].cause)
}
})
}
}