mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-23 14:55:44 +00:00
refactpr(FE): Extract approval and rejection handlers
This commit is contained in:
@@ -413,6 +413,56 @@ const PurchaseOrderDetail = ({
|
|||||||
refetchData,
|
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) {
|
if (!initialValues) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -976,18 +1026,7 @@ const PurchaseOrderDetail = ({
|
|||||||
primaryButton={{
|
primaryButton={{
|
||||||
text: 'Ya, Lanjutkan',
|
text: 'Ya, Lanjutkan',
|
||||||
color: 'success',
|
color: 'success',
|
||||||
onClick: async (notes) => {
|
onClick: managerApprovalHandler,
|
||||||
const payload: CreateManagerApprovalRequestPayload = {
|
|
||||||
action: 'APPROVED',
|
|
||||||
notes: notes || null,
|
|
||||||
};
|
|
||||||
|
|
||||||
await createManagerApprovalHandler(payload);
|
|
||||||
await refreshApprovals();
|
|
||||||
await refetchData?.();
|
|
||||||
setApprovalNotes('');
|
|
||||||
confirmationModalWithNotes.closeModal();
|
|
||||||
},
|
|
||||||
}}
|
}}
|
||||||
secondaryButton={{
|
secondaryButton={{
|
||||||
text: 'Batal',
|
text: 'Batal',
|
||||||
@@ -1083,17 +1122,7 @@ const PurchaseOrderDetail = ({
|
|||||||
primaryButton={{
|
primaryButton={{
|
||||||
text: 'Ya, Tolak',
|
text: 'Ya, Tolak',
|
||||||
color: 'error',
|
color: 'error',
|
||||||
onClick: async (notes) => {
|
onClick: staffRejectionHandler,
|
||||||
const payload: CreateStaffApprovalRequestPayload = {
|
|
||||||
action: 'REJECTED',
|
|
||||||
notes: notes || null,
|
|
||||||
};
|
|
||||||
|
|
||||||
await createStaffApprovalHandler(payload);
|
|
||||||
await refetchData?.();
|
|
||||||
setApprovalNotes('');
|
|
||||||
staffRejectionModal.closeModal();
|
|
||||||
},
|
|
||||||
}}
|
}}
|
||||||
secondaryButton={{
|
secondaryButton={{
|
||||||
text: 'Batal',
|
text: 'Batal',
|
||||||
@@ -1115,17 +1144,7 @@ const PurchaseOrderDetail = ({
|
|||||||
primaryButton={{
|
primaryButton={{
|
||||||
text: 'Ya, Tolak',
|
text: 'Ya, Tolak',
|
||||||
color: 'error',
|
color: 'error',
|
||||||
onClick: async (notes) => {
|
onClick: acceptRejectionHandler,
|
||||||
const payload: CreateAcceptApprovalRequestPayload = {
|
|
||||||
action: 'REJECTED',
|
|
||||||
notes: notes || null,
|
|
||||||
};
|
|
||||||
|
|
||||||
await createAcceptApprovalHandler(payload);
|
|
||||||
await refetchData?.();
|
|
||||||
setApprovalNotes('');
|
|
||||||
acceptRejectionModal.closeModal();
|
|
||||||
},
|
|
||||||
}}
|
}}
|
||||||
secondaryButton={{
|
secondaryButton={{
|
||||||
text: 'Batal',
|
text: 'Batal',
|
||||||
@@ -1147,17 +1166,7 @@ const PurchaseOrderDetail = ({
|
|||||||
primaryButton={{
|
primaryButton={{
|
||||||
text: 'Ya, Tolak',
|
text: 'Ya, Tolak',
|
||||||
color: 'error',
|
color: 'error',
|
||||||
onClick: async (notes) => {
|
onClick: managerRejectionHandler,
|
||||||
const payload: CreateManagerApprovalRequestPayload = {
|
|
||||||
action: 'REJECTED',
|
|
||||||
notes: notes || null,
|
|
||||||
};
|
|
||||||
|
|
||||||
await createManagerApprovalHandler(payload);
|
|
||||||
await refetchData?.();
|
|
||||||
setApprovalNotes('');
|
|
||||||
managerRejectionModal.closeModal();
|
|
||||||
},
|
|
||||||
}}
|
}}
|
||||||
secondaryButton={{
|
secondaryButton={{
|
||||||
text: 'Batal',
|
text: 'Batal',
|
||||||
|
|||||||
Reference in New Issue
Block a user