fix: add product
This commit is contained in:
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user