refactpr(FE): Extract approval and rejection handlers

This commit is contained in:
rstubryan
2026-02-02 14:43:18 +07:00
parent 4dec97b57c
commit 68feef77fc
@@ -413,6 +413,56 @@ const PurchaseOrderDetail = ({
refetchData,
]);
// ===== APPROVAL/REJECTION HANDLERS =====
const managerApprovalHandler = async (notes: string) => {
const payload: CreateManagerApprovalRequestPayload = {
action: 'APPROVED',
notes: notes || null,
};
await createManagerApprovalHandler(payload);
await refreshApprovals();
await refetchData?.();
setApprovalNotes('');
confirmationModalWithNotes.closeModal();
};
const staffRejectionHandler = async (notes: string) => {
const payload: CreateStaffApprovalRequestPayload = {
action: 'REJECTED',
notes: notes || null,
};
await createStaffApprovalHandler(payload);
await refetchData?.();
setApprovalNotes('');
staffRejectionModal.closeModal();
};
const acceptRejectionHandler = async (notes: string) => {
const payload: CreateAcceptApprovalRequestPayload = {
action: 'REJECTED',
notes: notes || null,
};
await createAcceptApprovalHandler(payload);
await refetchData?.();
setApprovalNotes('');
acceptRejectionModal.closeModal();
};
const managerRejectionHandler = async (notes: string) => {
const payload: CreateManagerApprovalRequestPayload = {
action: 'REJECTED',
notes: notes || null,
};
await createManagerApprovalHandler(payload);
await refetchData?.();
setApprovalNotes('');
managerRejectionModal.closeModal();
};
if (!initialValues) {
return null;
}
@@ -976,18 +1026,7 @@ const PurchaseOrderDetail = ({
primaryButton={{
text: 'Ya, Lanjutkan',
color: 'success',
onClick: async (notes) => {
const payload: CreateManagerApprovalRequestPayload = {
action: 'APPROVED',
notes: notes || null,
};
await createManagerApprovalHandler(payload);
await refreshApprovals();
await refetchData?.();
setApprovalNotes('');
confirmationModalWithNotes.closeModal();
},
onClick: managerApprovalHandler,
}}
secondaryButton={{
text: 'Batal',
@@ -1083,17 +1122,7 @@ const PurchaseOrderDetail = ({
primaryButton={{
text: 'Ya, Tolak',
color: 'error',
onClick: async (notes) => {
const payload: CreateStaffApprovalRequestPayload = {
action: 'REJECTED',
notes: notes || null,
};
await createStaffApprovalHandler(payload);
await refetchData?.();
setApprovalNotes('');
staffRejectionModal.closeModal();
},
onClick: staffRejectionHandler,
}}
secondaryButton={{
text: 'Batal',
@@ -1115,17 +1144,7 @@ const PurchaseOrderDetail = ({
primaryButton={{
text: 'Ya, Tolak',
color: 'error',
onClick: async (notes) => {
const payload: CreateAcceptApprovalRequestPayload = {
action: 'REJECTED',
notes: notes || null,
};
await createAcceptApprovalHandler(payload);
await refetchData?.();
setApprovalNotes('');
acceptRejectionModal.closeModal();
},
onClick: acceptRejectionHandler,
}}
secondaryButton={{
text: 'Batal',
@@ -1147,17 +1166,7 @@ const PurchaseOrderDetail = ({
primaryButton={{
text: 'Ya, Tolak',
color: 'error',
onClick: async (notes) => {
const payload: CreateManagerApprovalRequestPayload = {
action: 'REJECTED',
notes: notes || null,
};
await createManagerApprovalHandler(payload);
await refetchData?.();
setApprovalNotes('');
managerRejectionModal.closeModal();
},
onClick: managerRejectionHandler,
}}
secondaryButton={{
text: 'Batal',