fix: add loading state to approve modal

This commit is contained in:
ValdiANS
2026-05-13 15:29:03 +07:00
parent 910a36857e
commit fe2a2dfb43
@@ -297,6 +297,8 @@ const MarketingTable = () => {
const [isLoadingExportingToExcel, setIsLoadingExportingToExcel] = const [isLoadingExportingToExcel, setIsLoadingExportingToExcel] =
useState(false); useState(false);
const [isApproveLoading, setIsApproveLoading] = useState(false);
const [isDeliveryLoading, setIsDeliveryLoading] = useState(false);
const filterResetHandler = () => { const filterResetHandler = () => {
updateFilter('product_ids', '', true); updateFilter('product_ids', '', true);
@@ -452,23 +454,33 @@ const MarketingTable = () => {
return; return;
} }
const approveMarketingRes: BaseApiResponse<unknown> | undefined = setIsApproveLoading(true);
approveAction === 'APPROVED'
? await MarketingApi.bulkApprovals(
idsToProcess,
nextApprovalStatus as 'SALES_ORDER' | 'DELIVERY_ORDER',
'',
notes || `APPROVED marketing ${idsToProcess.join(', ')}`
)
: await SalesOrderApi.bulkApprovals(idsToProcess, approveAction, notes);
if (isResponseSuccess(approveMarketingRes)) { try {
confirmationModal.closeModal(); const approveMarketingRes: BaseApiResponse<unknown> | undefined =
toast.success(approveMarketingRes?.message as string); approveAction === 'APPROVED'
setRowSelection({}); ? await MarketingApi.bulkApprovals(
idsToProcess,
nextApprovalStatus as 'SALES_ORDER' | 'DELIVERY_ORDER',
'',
notes || `APPROVED marketing ${idsToProcess.join(', ')}`
)
: await SalesOrderApi.bulkApprovals(
idsToProcess,
approveAction,
notes
);
if (isResponseSuccess(approveMarketingRes)) {
confirmationModal.closeModal();
toast.success(approveMarketingRes?.message as string);
setRowSelection({});
}
refreshMarketing();
} finally {
setIsApproveLoading(false);
} }
refreshMarketing();
}; };
const bulkDeliveryDateChangeHandler: ChangeEventHandler<HTMLInputElement> = ( const bulkDeliveryDateChangeHandler: ChangeEventHandler<HTMLInputElement> = (
@@ -530,13 +542,21 @@ const MarketingTable = () => {
}; };
const confirmationModalDeliveryClickHandler = async (notes: string) => { const confirmationModalDeliveryClickHandler = async (notes: string) => {
const res = await SalesOrderApi.delivery(selectedItem?.id as number, notes); setIsDeliveryLoading(true);
deliveryModal.closeModal(); try {
toast.success(res?.message as string); const res = await SalesOrderApi.delivery(
refreshMarketing?.(); selectedItem?.id as number,
router.push( notes
`/marketing/detail/delivery-orders/edit?id=${selectedItem?.id}` );
); deliveryModal.closeModal();
toast.success(res?.message as string);
refreshMarketing?.();
router.push(
`/marketing/detail/delivery-orders/edit?id=${selectedItem?.id}`
);
} finally {
setIsDeliveryLoading(false);
}
}; };
const getRowCanSelect = useCallback( const getRowCanSelect = useCallback(
@@ -1020,11 +1040,13 @@ const MarketingTable = () => {
text={`Apakah anda yakin ingin ${approveAction == 'APPROVED' ? 'approve' : 'reject'} data penjualan tahap ${selectedApprovalStep ?? '-'} (${idsToProcess.length} data)?`} text={`Apakah anda yakin ingin ${approveAction == 'APPROVED' ? 'approve' : 'reject'} data penjualan tahap ${selectedApprovalStep ?? '-'} (${idsToProcess.length} data)?`}
secondaryButton={{ secondaryButton={{
text: 'Tidak', text: 'Tidak',
isLoading: isApproveLoading,
onClick: confirmationModal.closeModal, onClick: confirmationModal.closeModal,
}} }}
primaryButton={{ primaryButton={{
text: 'Ya', text: 'Ya',
color: approveAction === 'APPROVED' ? 'success' : 'error', color: approveAction === 'APPROVED' ? 'success' : 'error',
isLoading: isApproveLoading,
onClick: approveMarketingHandler, onClick: approveMarketingHandler,
}} }}
/> />
@@ -1048,10 +1070,12 @@ const MarketingTable = () => {
text={`Apakah anda yakin ingin deliver penjualan ${selectedItem?.so_number}?`} text={`Apakah anda yakin ingin deliver penjualan ${selectedItem?.so_number}?`}
secondaryButton={{ secondaryButton={{
text: 'Tidak', text: 'Tidak',
isLoading: isDeliveryLoading,
}} }}
primaryButton={{ primaryButton={{
text: 'Ya', text: 'Ya',
color: 'success', color: 'success',
isLoading: isDeliveryLoading,
onClick: confirmationModalDeliveryClickHandler, onClick: confirmationModalDeliveryClickHandler,
}} }}
/> />
@@ -1111,6 +1135,7 @@ const MarketingTable = () => {
<Button <Button
variant='outline' variant='outline'
color='none' color='none'
disabled={isSubmittingBulkDelivery}
onClick={() => { onClick={() => {
bulkDeliveryModal.closeModal(); bulkDeliveryModal.closeModal();
setBulkDeliveryDate(''); setBulkDeliveryDate('');
@@ -1123,6 +1148,7 @@ const MarketingTable = () => {
<Button <Button
color='success' color='success'
isLoading={isSubmittingBulkDelivery} isLoading={isSubmittingBulkDelivery}
disabled={isSubmittingBulkDelivery}
onClick={() => onClick={() =>
submitBulkDeliveryApprovalHandler( submitBulkDeliveryApprovalHandler(
idsToProcess, idsToProcess,