fix: re stock
This commit is contained in:
+2
-1
@@ -1,4 +1,5 @@
|
||||
import axios from 'axios'
|
||||
import { toast } from 'react-toastify'
|
||||
|
||||
const getToken = () => {
|
||||
return localStorage.getItem('authToken')
|
||||
@@ -40,7 +41,7 @@ api.interceptors.response.use(
|
||||
}
|
||||
|
||||
if (status >= 500) {
|
||||
console.error('Server error:', error.response?.data?.message || 'Terjadi kesalahan server.')
|
||||
toast.error(error.response?.data?.errors[0].cause || 'Terjadi kesalahan server.')
|
||||
}
|
||||
|
||||
return Promise.reject(error)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { api } from '../api'
|
||||
import { toast } from 'react-toastify'
|
||||
import { InventoryAdjustRequest, InventoryRequest } from '../../types/services/inventory'
|
||||
import { InventoryAdjustRequest, InventoryRequest, InventoryRestockRequest } from '../../types/services/inventory'
|
||||
|
||||
export const useInventoriesMutation = () => {
|
||||
const queryClient = useQueryClient()
|
||||
@@ -34,6 +34,24 @@ export const useInventoriesMutation = () => {
|
||||
}
|
||||
})
|
||||
|
||||
const restockInventory = useMutation({
|
||||
mutationFn: async (newInventory: InventoryRestockRequest) => {
|
||||
newInventory.items.map(item => {
|
||||
item.quantity = Number(item.quantity)
|
||||
})
|
||||
|
||||
const response = await api.post('/inventory/restock', newInventory)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Inventory restock successfully!')
|
||||
queryClient.invalidateQueries({ queryKey: ['inventories'] })
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Create failed')
|
||||
}
|
||||
})
|
||||
|
||||
const deleteInventory = useMutation({
|
||||
mutationFn: async (id: string) => {
|
||||
const response = await api.delete(`/inventory/${id}`)
|
||||
@@ -48,5 +66,5 @@ export const useInventoriesMutation = () => {
|
||||
}
|
||||
})
|
||||
|
||||
return { createInventory, adjustInventory, deleteInventory }
|
||||
return { createInventory, adjustInventory, deleteInventory, restockInventory }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user