>
)
}
diff --git a/src/components/layout/shared/Loading.tsx b/src/components/layout/shared/Loading.tsx
index 7df9989..83e8039 100644
--- a/src/components/layout/shared/Loading.tsx
+++ b/src/components/layout/shared/Loading.tsx
@@ -2,7 +2,7 @@ import { CircularProgress } from '@mui/material'
export default function Loading({ size = 60 }: { size?: number }) {
return (
-
+
)
diff --git a/src/services/api.ts b/src/services/api.ts
index 25cad69..ab43ede 100644
--- a/src/services/api.ts
+++ b/src/services/api.ts
@@ -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)
diff --git a/src/services/mutations/inventories.ts b/src/services/mutations/inventories.ts
index d4e800f..16804fa 100644
--- a/src/services/mutations/inventories.ts
+++ b/src/services/mutations/inventories.ts
@@ -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 }
}
diff --git a/src/types/services/inventory.ts b/src/types/services/inventory.ts
index 7d22234..d018108 100644
--- a/src/types/services/inventory.ts
+++ b/src/types/services/inventory.ts
@@ -29,3 +29,15 @@ export interface InventoryAdjustRequest {
delta: number
reason: string
}
+
+export interface Item {
+ item_id: string
+ item_type: string
+ quantity: number | string
+}
+
+export interface InventoryRestockRequest {
+ outlet_id: string
+ items: Item[]
+ reason: string
+}
diff --git a/src/utils/transform.ts b/src/utils/transform.ts
index a33ecfc..9f1e131 100644
--- a/src/utils/transform.ts
+++ b/src/utils/transform.ts
@@ -36,12 +36,22 @@ export const formatDate = (dateString: any) => {
export const formatDateDDMMYYYY = (dateString: Date | string) => {
const date = new Date(dateString)
+ date.setHours(0, 0, 0, 0)
const day = String(date.getDate()).padStart(2, '0')
const month = String(date.getMonth() + 1).padStart(2, '0')
const year = date.getFullYear()
return `${day}-${month}-${year}`
}
+export const formatForInputDate = (dateString: Date | string) => {
+ const date = new Date(dateString)
+ const day = String(date.getDate()).padStart(2, '0')
+ const month = String(date.getMonth() + 1).padStart(2, '0')
+ const year = date.getFullYear()
+ return `${year}-${month}-${day}`
+}
+
+
export const formatDatetime = (dateString: string | number | Date) => {
const date = new Date(dateString)
diff --git a/src/views/apps/ecommerce/products/list/ProductListTable.tsx b/src/views/apps/ecommerce/products/list/ProductListTable.tsx
index f864f2d..9114005 100644
--- a/src/views/apps/ecommerce/products/list/ProductListTable.tsx
+++ b/src/views/apps/ecommerce/products/list/ProductListTable.tsx
@@ -220,13 +220,13 @@ const ProductListTable = () => {
diff --git a/src/views/apps/ecommerce/stock/adjustment/AdjustmentStockDrawer.tsx b/src/views/apps/ecommerce/stock/adjustment/AdjustmentStockDrawer.tsx
index fbc0800..6f1b75c 100644
--- a/src/views/apps/ecommerce/stock/adjustment/AdjustmentStockDrawer.tsx
+++ b/src/views/apps/ecommerce/stock/adjustment/AdjustmentStockDrawer.tsx
@@ -14,12 +14,12 @@ import Typography from '@mui/material/Typography'
// Components Imports
import CustomTextField from '@core/components/mui/TextField'
-import { Autocomplete, CircularProgress } from '@mui/material'
+import { Autocomplete, CircularProgress, MenuItem } from '@mui/material'
import { useDebounce } from 'use-debounce'
import { useInventoriesMutation } from '../../../../../services/mutations/inventories'
import { useOutlets } from '../../../../../services/queries/outlets'
import { useProducts } from '../../../../../services/queries/products'
-import { InventoryAdjustRequest } from '../../../../../types/services/inventory'
+import { InventoryRestockRequest, Item } from '../../../../../types/services/inventory'
type Props = {
open: boolean
@@ -30,17 +30,22 @@ const AdjustmentStockDrawer = (props: Props) => {
// Props
const { open, handleClose } = props
- const { mutate: adjustInventory, isPending: isCreating } = useInventoriesMutation().adjustInventory
+ const { restockInventory } = useInventoriesMutation()
// States
const [productInput, setProductInput] = useState('')
const [productDebouncedInput] = useDebounce(productInput, 500) // debounce for better UX
const [outletInput, setOutletInput] = useState('')
const [outletDebouncedInput] = useDebounce(outletInput, 500) // debounce for better UX
- const [formData, setFormData] = useState
({
- product_id: '',
+ const [formData, setFormData] = useState({
outlet_id: '',
- delta: 0,
+ items: [
+ {
+ item_id: '',
+ item_type: '',
+ quantity: 0
+ }
+ ],
reason: ''
})
@@ -58,14 +63,11 @@ const AdjustmentStockDrawer = (props: Props) => {
const handleFormSubmit = (e: any) => {
e.preventDefault()
- adjustInventory(
- { ...formData, delta: Number(formData.delta) },
- {
- onSuccess: () => {
- handleReset()
- }
+ restockInventory.mutate(formData, {
+ onSuccess: () => {
+ handleReset()
}
- )
+ })
}
const handleInputChange = (e: any) => {
@@ -79,9 +81,14 @@ const AdjustmentStockDrawer = (props: Props) => {
const handleReset = () => {
handleClose()
setFormData({
- product_id: '',
outlet_id: '',
- delta: 0,
+ items: [
+ {
+ item_id: '',
+ item_type: '',
+ quantity: 0
+ }
+ ],
reason: ''
})
}
@@ -136,18 +143,33 @@ const AdjustmentStockDrawer = (props: Props) => {
/>
)}
/>
+ setFormData({ ...formData, items: [{ ...formData.items[0], item_type: e.target.value }] })}
+ >
+
+
+
option.name}
- value={options.find(p => p.id === formData.product_id) || null}
+ value={options.find(p => p.id === formData.items[0].item_id) || null}
onInputChange={(event, newProductInput) => {
setProductInput(newProductInput)
}}
onChange={(event, newValue) => {
setFormData({
...formData,
- product_id: newValue?.id || ''
+ items: [
+ {
+ ...formData.items[0],
+ item_id: newValue?.id || ''
+ }
+ ]
})
}}
renderInput={params => (
@@ -170,10 +192,20 @@ const AdjustmentStockDrawer = (props: Props) => {
/>
+ setFormData({
+ ...formData,
+ items: [
+ {
+ ...formData.items[0],
+ quantity: e.target.value
+ }
+ ]
+ })
+ }
placeholder='0'
/>
{
placeholder='Write a Comment...'
/>
-