fix: re stock
This commit is contained in:
@@ -220,13 +220,13 @@ const ProductListTable = () => {
|
||||
<div className='flex items-center'>
|
||||
<IconButton
|
||||
LinkComponent={Link}
|
||||
href={getLocalizedUrl(`/apps/ecommerce/products/${row.original.id}/detail`, locale as Locale)}
|
||||
href={getLocalizedUrl(`/apps/inventory/products/${row.original.id}/detail`, locale as Locale)}
|
||||
>
|
||||
<i className='tabler-eye text-textSecondary' />
|
||||
</IconButton>
|
||||
<IconButton
|
||||
LinkComponent={Link}
|
||||
href={getLocalizedUrl(`/apps/ecommerce/products/${row.original.id}/edit`, locale as Locale)}
|
||||
href={getLocalizedUrl(`/apps/inventory/products/${row.original.id}/edit`, locale as Locale)}
|
||||
>
|
||||
<i className='tabler-edit text-textSecondary' />
|
||||
</IconButton>
|
||||
|
||||
@@ -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<InventoryAdjustRequest>({
|
||||
product_id: '',
|
||||
const [formData, setFormData] = useState<InventoryRestockRequest>({
|
||||
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) => {
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
<CustomTextField
|
||||
select
|
||||
fullWidth
|
||||
label='Item Type'
|
||||
value={formData.items[0]?.item_type || ''}
|
||||
onChange={e => setFormData({ ...formData, items: [{ ...formData.items[0], item_type: e.target.value }] })}
|
||||
>
|
||||
<MenuItem value='PRODUCT'>Product</MenuItem>
|
||||
<MenuItem value='IGREDIENT'>Ingredient</MenuItem>
|
||||
</CustomTextField>
|
||||
<Autocomplete
|
||||
options={options}
|
||||
loading={isLoading}
|
||||
getOptionLabel={option => 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) => {
|
||||
/>
|
||||
<CustomTextField
|
||||
fullWidth
|
||||
label='Delta'
|
||||
name='delta'
|
||||
value={formData.delta}
|
||||
onChange={handleInputChange}
|
||||
label='Quantity'
|
||||
name='quantity'
|
||||
value={formData.items[0].quantity}
|
||||
onChange={e =>
|
||||
setFormData({
|
||||
...formData,
|
||||
items: [
|
||||
{
|
||||
...formData.items[0],
|
||||
quantity: e.target.value
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
placeholder='0'
|
||||
/>
|
||||
<CustomTextField
|
||||
@@ -187,8 +219,8 @@ const AdjustmentStockDrawer = (props: Props) => {
|
||||
placeholder='Write a Comment...'
|
||||
/>
|
||||
<div className='flex items-center gap-4'>
|
||||
<Button variant='contained' type='submit' disabled={isCreating}>
|
||||
{isCreating ? 'Adjusting...' : 'Adjust'}
|
||||
<Button variant='contained' type='submit' disabled={restockInventory.isPending}>
|
||||
{restockInventory.isPending ? 'Saving...' : 'Save'}
|
||||
</Button>
|
||||
<Button variant='tonal' color='error' type='reset' onClick={handleReset}>
|
||||
Discard
|
||||
|
||||
Reference in New Issue
Block a user