fix: reset product

This commit is contained in:
efrilm 2025-09-03 13:01:48 +07:00
parent 1fc2b41d36
commit d3417fae9a
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 { 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,6 +133,8 @@ const ProductInformation = () => {
const isEdit = !!params?.id const isEdit = !!params?.id
useEffect(() => { useEffect(() => {
if (params?.id) {
// Mode edit → set product dari API
if (product) { if (product) {
dispatch( dispatch(
setProduct({ setProduct({
@ -148,7 +150,10 @@ const ProductInformation = () => {
}) })
) )
} }
}, [product, dispatch]) } else {
dispatch(resetProduct())
}
}, [params?.id, product, dispatch])
const handleInputChange = (field: any, value: any) => { const handleInputChange = (field: any, value: any) => {
dispatch(setProductField({ field, value })) 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> </div>
<CustomTextField <CustomTextField
select select