diff --git a/src/components/pages/master-data/uom/form/UomForm.tsx b/src/components/pages/master-data/uom/form/UomForm.tsx index 87cbdf34..8ece22a8 100644 --- a/src/components/pages/master-data/uom/form/UomForm.tsx +++ b/src/components/pages/master-data/uom/form/UomForm.tsx @@ -8,6 +8,8 @@ import { toast } from 'react-hot-toast'; import { Icon } from '@iconify/react'; import Button from '@/components/Button'; import TextInput from '@/components/input/TextInput'; +import { useModal } from '@/components/Modal'; +import ConfirmationModal from '@/components/modal/ConfirmationModal'; import { UomFormSchema, @@ -21,6 +23,7 @@ import { UpdateUomPayload, } from '@/types/api/master-data/uom'; import { UomApi } from '@/services/api/master-data'; +import { cn } from '@/lib/helper'; interface UomFormProps { type?: 'add' | 'edit' | 'detail'; @@ -29,8 +32,10 @@ interface UomFormProps { const UomForm = ({ type = 'add', initialValues }: UomFormProps) => { const router = useRouter(); + const deleteModal = useModal(); const [uomFormErrorMessage, setUomFormErrorMessage] = useState(''); + const [isDeleteLoading, setIsDeleteLoading] = useState(false); const createUomHandler = useCallback( async (payload: CreateUomPayload) => { @@ -93,81 +98,138 @@ const UomForm = ({ type = 'add', initialValues }: UomFormProps) => { const { setValues: formikSetValues } = formik; + const deleteUomClickHandler = () => { + deleteModal.openModal(); + }; + + const confirmationModalDeleteClickHandler = async () => { + setIsDeleteLoading(true); + + await UomApi.delete(initialValues?.id as number); + + deleteModal.closeModal(); + toast.success('Successfully delete UOM!'); + setIsDeleteLoading(false); + router.push('/master-data/uom'); + }; + useEffect(() => { formikSetValues(formikInitialValues); }, [formikSetValues, formikInitialValues]); return ( -
-
- + +

+ {type === 'add' && 'Tambah UOM'} + {type === 'edit' && 'Edit UOM'} + {type === 'detail' && 'Detail UOM'} +

+
+ +
- - Kembali - +
+ +
-

- {type === 'add' && 'Tambah UOM'} - {type === 'edit' && 'Edit UOM'} - {type === 'detail' && 'Detail UOM'} -

- - - -
- -
- - {type !== 'detail' && ( - <> -
- - - -
- - {uomFormErrorMessage && ( -
- - {uomFormErrorMessage} +
+ {type !== 'add' && ( +
+
)} - - )} - -
+ + {type !== 'detail' && ( +
+ + + +
+ )} + + + {uomFormErrorMessage && ( +
+ + {uomFormErrorMessage} +
+ )} + + + + {type !== 'add' && ( + + )} + ); };