fix: reset product #5

Merged
aefril merged 1 commits from efril into main 2025-09-03 06:05:59 +00:00
2 changed files with 21 additions and 19 deletions

View File

@ -26,7 +26,7 @@ import '@/libs/styles/tiptapEditor.css'
import { useDispatch, useSelector } from 'react-redux'
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 { useParams } from 'next/navigation'
import { useProductById } from '../../../../../services/queries/products'
@ -133,22 +133,27 @@ const ProductInformation = () => {
const isEdit = !!params?.id
useEffect(() => {
if (product) {
dispatch(
setProduct({
name: product.name,
sku: product.sku || '',
description: product.description || '',
price: product.price,
cost: product.cost,
category_id: product.category_id,
printer_type: product.printer_type,
image_url: product.image_url || '',
variants: product.variants || []
})
)
if (params?.id) {
// Mode edit → set product dari API
if (product) {
dispatch(
setProduct({
name: product.name,
sku: product.sku || '',
description: product.description || '',
price: product.price,
cost: product.cost,
category_id: product.category_id,
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) => {
dispatch(setProductField({ field, value }))

View File

@ -73,9 +73,6 @@ const ProductOrganize = () => {
/>
)}
/>
<CustomIconButton variant='tonal' color='primary' className='min-is-fit'>
<i className='tabler-plus' />
</CustomIconButton>
</div>
<CustomTextField
select