mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 23:35:45 +00:00
fix: add loading state to approve modal
This commit is contained in:
@@ -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,6 +454,9 @@ const MarketingTable = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setIsApproveLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
const approveMarketingRes: BaseApiResponse<unknown> | undefined =
|
const approveMarketingRes: BaseApiResponse<unknown> | undefined =
|
||||||
approveAction === 'APPROVED'
|
approveAction === 'APPROVED'
|
||||||
? await MarketingApi.bulkApprovals(
|
? await MarketingApi.bulkApprovals(
|
||||||
@@ -460,7 +465,11 @@ const MarketingTable = () => {
|
|||||||
'',
|
'',
|
||||||
notes || `APPROVED marketing ${idsToProcess.join(', ')}`
|
notes || `APPROVED marketing ${idsToProcess.join(', ')}`
|
||||||
)
|
)
|
||||||
: await SalesOrderApi.bulkApprovals(idsToProcess, approveAction, notes);
|
: await SalesOrderApi.bulkApprovals(
|
||||||
|
idsToProcess,
|
||||||
|
approveAction,
|
||||||
|
notes
|
||||||
|
);
|
||||||
|
|
||||||
if (isResponseSuccess(approveMarketingRes)) {
|
if (isResponseSuccess(approveMarketingRes)) {
|
||||||
confirmationModal.closeModal();
|
confirmationModal.closeModal();
|
||||||
@@ -469,6 +478,9 @@ const MarketingTable = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
refreshMarketing();
|
refreshMarketing();
|
||||||
|
} finally {
|
||||||
|
setIsApproveLoading(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
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);
|
||||||
|
try {
|
||||||
|
const res = await SalesOrderApi.delivery(
|
||||||
|
selectedItem?.id as number,
|
||||||
|
notes
|
||||||
|
);
|
||||||
deliveryModal.closeModal();
|
deliveryModal.closeModal();
|
||||||
toast.success(res?.message as string);
|
toast.success(res?.message as string);
|
||||||
refreshMarketing?.();
|
refreshMarketing?.();
|
||||||
router.push(
|
router.push(
|
||||||
`/marketing/detail/delivery-orders/edit?id=${selectedItem?.id}`
|
`/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,
|
||||||
|
|||||||
Reference in New Issue
Block a user