mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 21:41:57 +00:00
refactor(FE): Add approval modal and handler for marketing approval
This commit is contained in:
@@ -111,6 +111,7 @@ const DeliveryOrderFormModal = ({
|
||||
const successModal = useModal();
|
||||
const rejectModal = useModal();
|
||||
const deleteModal = useModal();
|
||||
const approveModal = useModal();
|
||||
const formRef = useRef<HTMLFormElement>(null);
|
||||
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||
|
||||
@@ -333,6 +334,33 @@ const DeliveryOrderFormModal = ({
|
||||
refreshApproval();
|
||||
};
|
||||
|
||||
const approveMarketingHandler = async (notes: string) => {
|
||||
if (!marketingId) {
|
||||
toast.error(`Tidak ada data yang valid untuk di approve.`);
|
||||
approveModal.closeModal();
|
||||
return;
|
||||
}
|
||||
|
||||
const approveMarketingRes = await SalesOrderApi.singleApproval(
|
||||
Number(marketingId),
|
||||
'APPROVED',
|
||||
notes
|
||||
);
|
||||
|
||||
if (isResponseSuccess(approveMarketingRes)) {
|
||||
approveModal.closeModal();
|
||||
toast.success(approveMarketingRes?.message as string);
|
||||
closeModalHandler();
|
||||
router.push('/marketing');
|
||||
}
|
||||
if (isResponseError(approveMarketingRes)) {
|
||||
approveModal.closeModal();
|
||||
toast.error(approveMarketingRes?.message as string);
|
||||
}
|
||||
refreshMarketing();
|
||||
refreshApproval();
|
||||
};
|
||||
|
||||
const deleteClickHandler = () => {
|
||||
deleteModal.openModal();
|
||||
};
|
||||
@@ -723,7 +751,15 @@ const DeliveryOrderFormModal = ({
|
||||
type='button'
|
||||
color='primary'
|
||||
onClick={() => {
|
||||
formRef.current?.requestSubmit();
|
||||
// Jika masih di step 1 approval, gunakan single approval API
|
||||
if (
|
||||
marketing?.data?.latest_approval?.step_number === 1
|
||||
) {
|
||||
approveModal.openModal();
|
||||
} else {
|
||||
// Jika sudah di step 2/3, gunakan form submit (delivery products)
|
||||
formRef.current?.requestSubmit();
|
||||
}
|
||||
}}
|
||||
className='p-3 shadow-button-soft text-base-100 rounded-lg text-sm font-semibold'
|
||||
disabled={deliveryRejected}
|
||||
@@ -795,6 +831,21 @@ const DeliveryOrderFormModal = ({
|
||||
onClick: confirmationModalDeleteClickHandler,
|
||||
}}
|
||||
/>
|
||||
|
||||
<ConfirmationModalWithNotes
|
||||
ref={approveModal.ref}
|
||||
type={'success'}
|
||||
text={`Apakah anda yakin ingin approve data penjualan?`}
|
||||
secondaryButton={{
|
||||
text: 'Tidak',
|
||||
onClick: approveModal.closeModal,
|
||||
}}
|
||||
primaryButton={{
|
||||
text: 'Ya',
|
||||
color: 'success',
|
||||
onClick: approveMarketingHandler,
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user