Merge pull request 'fix: reset product' (#5) from efril into main
Reviewed-on: #5
This commit is contained in:
commit
0528cfa053
@ -26,7 +26,7 @@ import '@/libs/styles/tiptapEditor.css'
|
|||||||
|
|
||||||
import { useDispatch, useSelector } from 'react-redux'
|
import { useDispatch, useSelector } from 'react-redux'
|
||||||
import { RootState } from '../../../../../redux-store'
|
import { RootState } from '../../../../../redux-store'
|
||||||
import { setProduct, setProductField } from '@/redux-store/slices/product'
|
import { resetProduct, setProduct, setProductField } from '@/redux-store/slices/product'
|
||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
import { useParams } from 'next/navigation'
|
import { useParams } from 'next/navigation'
|
||||||
import { useProductById } from '../../../../../services/queries/products'
|
import { useProductById } from '../../../../../services/queries/products'
|
||||||
@ -133,22 +133,27 @@ const ProductInformation = () => {
|
|||||||
const isEdit = !!params?.id
|
const isEdit = !!params?.id
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (product) {
|
if (params?.id) {
|
||||||
dispatch(
|
// Mode edit → set product dari API
|
||||||
setProduct({
|
if (product) {
|
||||||
name: product.name,
|
dispatch(
|
||||||
sku: product.sku || '',
|
setProduct({
|
||||||
description: product.description || '',
|
name: product.name,
|
||||||
price: product.price,
|
sku: product.sku || '',
|
||||||
cost: product.cost,
|
description: product.description || '',
|
||||||
category_id: product.category_id,
|
price: product.price,
|
||||||
printer_type: product.printer_type,
|
cost: product.cost,
|
||||||
image_url: product.image_url || '',
|
category_id: product.category_id,
|
||||||
variants: product.variants || []
|
printer_type: product.printer_type,
|
||||||
})
|
image_url: product.image_url || '',
|
||||||
)
|
variants: product.variants || []
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dispatch(resetProduct())
|
||||||
}
|
}
|
||||||
}, [product, dispatch])
|
}, [params?.id, product, dispatch])
|
||||||
|
|
||||||
const handleInputChange = (field: any, value: any) => {
|
const handleInputChange = (field: any, value: any) => {
|
||||||
dispatch(setProductField({ field, value }))
|
dispatch(setProductField({ field, value }))
|
||||||
|
|||||||
@ -73,9 +73,6 @@ const ProductOrganize = () => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<CustomIconButton variant='tonal' color='primary' className='min-is-fit'>
|
|
||||||
<i className='tabler-plus' />
|
|
||||||
</CustomIconButton>
|
|
||||||
</div>
|
</div>
|
||||||
<CustomTextField
|
<CustomTextField
|
||||||
select
|
select
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user