Create Purchase
This commit is contained in:
@@ -3,20 +3,22 @@ import { toast } from 'react-toastify'
|
||||
import { api } from '../api'
|
||||
import { PurchaseOrderRequest } from '@/types/services/purchaseOrder'
|
||||
|
||||
export const useVendorsMutation = () => {
|
||||
export const usePurchaseOrdersMutation = () => {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
const createVendor = useMutation({
|
||||
mutationFn: async (newVendor: PurchaseOrderRequest) => {
|
||||
const response = await api.post('/vendors', newVendor)
|
||||
const createPurchaseOrder = useMutation({
|
||||
mutationFn: async (newPurchaseOrder: PurchaseOrderRequest) => {
|
||||
const response = await api.post('/purchase-orders', newPurchaseOrder)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Vendor created successfully!')
|
||||
queryClient.invalidateQueries({ queryKey: ['vendors'] })
|
||||
toast.success('Purchase Order created successfully!')
|
||||
queryClient.invalidateQueries({ queryKey: ['purchase-orders'] })
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Create failed')
|
||||
}
|
||||
})
|
||||
|
||||
return { createPurchaseOrder }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user