mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 15:25:46 +00:00
refactor(FE-208,212): add refreshApprovals and onModalClose props to approval forms
This commit is contained in:
@@ -27,12 +27,16 @@ interface PurchaseOrderAcceptApprovalFormProps {
|
|||||||
type?: 'add' | 'edit';
|
type?: 'add' | 'edit';
|
||||||
initialValues?: Purchase;
|
initialValues?: Purchase;
|
||||||
onCancel?: () => void;
|
onCancel?: () => void;
|
||||||
|
refreshApprovals?: () => void;
|
||||||
|
onModalClose?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PurchaseOrderAcceptApprovalForm = ({
|
const PurchaseOrderAcceptApprovalForm = ({
|
||||||
type = 'add',
|
type = 'add',
|
||||||
initialValues,
|
initialValues,
|
||||||
onCancel,
|
onCancel,
|
||||||
|
refreshApprovals,
|
||||||
|
onModalClose,
|
||||||
}: PurchaseOrderAcceptApprovalFormProps) => {
|
}: PurchaseOrderAcceptApprovalFormProps) => {
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const [purchaseOrderFormErrorMessage, setPurchaseOrderFormErrorMessage] =
|
const [purchaseOrderFormErrorMessage, setPurchaseOrderFormErrorMessage] =
|
||||||
@@ -99,9 +103,12 @@ const PurchaseOrderAcceptApprovalForm = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
toast.success(res?.message as string);
|
toast.success(res?.message as string);
|
||||||
|
refreshApprovals?.();
|
||||||
|
formik.resetForm();
|
||||||
onCancel?.();
|
onCancel?.();
|
||||||
|
onModalClose?.();
|
||||||
},
|
},
|
||||||
[initialValues?.id, searchParams]
|
[initialValues?.id, searchParams, refreshApprovals, onModalClose]
|
||||||
);
|
);
|
||||||
|
|
||||||
const updateAcceptApprovalHandler = useCallback(
|
const updateAcceptApprovalHandler = useCallback(
|
||||||
@@ -112,10 +119,13 @@ const PurchaseOrderAcceptApprovalForm = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
toast.success(res?.message as string);
|
toast.success(res?.message as string);
|
||||||
|
refreshApprovals?.();
|
||||||
|
formik.resetForm();
|
||||||
onCancel?.();
|
onCancel?.();
|
||||||
|
onModalClose?.();
|
||||||
window.location.href = '/purchase';
|
window.location.href = '/purchase';
|
||||||
},
|
},
|
||||||
[]
|
[refreshApprovals, onModalClose]
|
||||||
);
|
);
|
||||||
|
|
||||||
// ===== FORM CONFIGURATION =====
|
// ===== FORM CONFIGURATION =====
|
||||||
@@ -652,7 +662,12 @@ const PurchaseOrderAcceptApprovalForm = ({
|
|||||||
type='button'
|
type='button'
|
||||||
color='warning'
|
color='warning'
|
||||||
className='px-4'
|
className='px-4'
|
||||||
onClick={onCancel}
|
onClick={() => {
|
||||||
|
formik.resetForm();
|
||||||
|
setPurchaseOrderFormErrorMessage('');
|
||||||
|
onCancel?.();
|
||||||
|
onModalClose?.();
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -27,12 +27,16 @@ interface PurchaseOrderStaffApprovalFormProps {
|
|||||||
type?: 'add' | 'edit';
|
type?: 'add' | 'edit';
|
||||||
initialValues?: Purchase;
|
initialValues?: Purchase;
|
||||||
onCancel?: () => void;
|
onCancel?: () => void;
|
||||||
|
refreshApprovals?: () => void;
|
||||||
|
onModalClose?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PurchaseOrderStaffApprovalForm = ({
|
const PurchaseOrderStaffApprovalForm = ({
|
||||||
type = 'add',
|
type = 'add',
|
||||||
initialValues,
|
initialValues,
|
||||||
onCancel,
|
onCancel,
|
||||||
|
refreshApprovals,
|
||||||
|
onModalClose,
|
||||||
}: PurchaseOrderStaffApprovalFormProps) => {
|
}: PurchaseOrderStaffApprovalFormProps) => {
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const [purchaseOrderFormErrorMessage, setPurchaseOrderFormErrorMessage] =
|
const [purchaseOrderFormErrorMessage, setPurchaseOrderFormErrorMessage] =
|
||||||
@@ -90,9 +94,12 @@ const PurchaseOrderStaffApprovalForm = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
toast.success(res?.message as string);
|
toast.success(res?.message as string);
|
||||||
|
refreshApprovals?.();
|
||||||
|
formik.resetForm();
|
||||||
onCancel?.();
|
onCancel?.();
|
||||||
|
onModalClose?.();
|
||||||
},
|
},
|
||||||
[initialValues?.id, searchParams]
|
[initialValues?.id, searchParams, refreshApprovals, onModalClose]
|
||||||
);
|
);
|
||||||
|
|
||||||
const updateStaffApprovalHandler = useCallback(
|
const updateStaffApprovalHandler = useCallback(
|
||||||
@@ -106,10 +113,13 @@ const PurchaseOrderStaffApprovalForm = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
toast.success(res?.message as string);
|
toast.success(res?.message as string);
|
||||||
|
refreshApprovals?.();
|
||||||
|
formik.resetForm();
|
||||||
onCancel?.();
|
onCancel?.();
|
||||||
|
onModalClose?.();
|
||||||
await router.push(`/purchase/detail?purchaseId=${purchaseId}`);
|
await router.push(`/purchase/detail?purchaseId=${purchaseId}`);
|
||||||
},
|
},
|
||||||
[]
|
[refreshApprovals, onModalClose]
|
||||||
);
|
);
|
||||||
|
|
||||||
// ===== FORM CONFIGURATION =====
|
// ===== FORM CONFIGURATION =====
|
||||||
@@ -451,7 +461,12 @@ const PurchaseOrderStaffApprovalForm = ({
|
|||||||
type='button'
|
type='button'
|
||||||
color='warning'
|
color='warning'
|
||||||
className='px-4'
|
className='px-4'
|
||||||
onClick={onCancel}
|
onClick={() => {
|
||||||
|
formik.resetForm();
|
||||||
|
setPurchaseOrderFormErrorMessage('');
|
||||||
|
onCancel?.();
|
||||||
|
onModalClose?.();
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -544,11 +544,7 @@ const PurchaseOrderDetail = ({
|
|||||||
Approve
|
Approve
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button
|
<Button variant='outline' color='error' className='w-full sm:w-fit'>
|
||||||
variant='outline'
|
|
||||||
color='error'
|
|
||||||
className='w-full sm:w-fit'
|
|
||||||
>
|
|
||||||
<Icon icon='material-symbols:close' width={24} height={24} />
|
<Icon icon='material-symbols:close' width={24} height={24} />
|
||||||
Reject
|
Reject
|
||||||
</Button>
|
</Button>
|
||||||
@@ -864,6 +860,7 @@ const PurchaseOrderDetail = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
await createManagerApprovalHandler(payload);
|
await createManagerApprovalHandler(payload);
|
||||||
|
await refreshApprovals();
|
||||||
confirmationModalWithNotes.closeModal();
|
confirmationModalWithNotes.closeModal();
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
@@ -884,6 +881,8 @@ const PurchaseOrderDetail = ({
|
|||||||
type='add'
|
type='add'
|
||||||
initialValues={purchaseData}
|
initialValues={purchaseData}
|
||||||
onCancel={handleStaffApprovalModalClose}
|
onCancel={handleStaffApprovalModalClose}
|
||||||
|
refreshApprovals={refreshApprovals}
|
||||||
|
onModalClose={staffApprovalModal.closeModal}
|
||||||
/>
|
/>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
@@ -899,6 +898,8 @@ const PurchaseOrderDetail = ({
|
|||||||
type='add'
|
type='add'
|
||||||
initialValues={purchaseData}
|
initialValues={purchaseData}
|
||||||
onCancel={acceptApprovalModal.closeModal}
|
onCancel={acceptApprovalModal.closeModal}
|
||||||
|
refreshApprovals={refreshApprovals}
|
||||||
|
onModalClose={acceptApprovalModal.closeModal}
|
||||||
/>
|
/>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
@@ -914,6 +915,8 @@ const PurchaseOrderDetail = ({
|
|||||||
type='edit'
|
type='edit'
|
||||||
initialValues={purchaseData}
|
initialValues={purchaseData}
|
||||||
onCancel={handleEditModalClose}
|
onCancel={handleEditModalClose}
|
||||||
|
refreshApprovals={refreshApprovals}
|
||||||
|
onModalClose={editModal.closeModal}
|
||||||
/>
|
/>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
@@ -929,6 +932,8 @@ const PurchaseOrderDetail = ({
|
|||||||
type='edit'
|
type='edit'
|
||||||
initialValues={purchaseData}
|
initialValues={purchaseData}
|
||||||
onCancel={penerimaanBarangModal.closeModal}
|
onCancel={penerimaanBarangModal.closeModal}
|
||||||
|
refreshApprovals={refreshApprovals}
|
||||||
|
onModalClose={penerimaanBarangModal.closeModal}
|
||||||
/>
|
/>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user