26 lines
657 B
TypeScript
26 lines
657 B
TypeScript
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)
|
|
}
|
|
})
|
|
}
|
|
}
|