From 0f84963214ee6dc5b5a44d945540826a66bec9e0 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Wed, 11 Dec 2024 11:51:45 +0700
Subject: <iman> update pengajuan tempo

---
 .../pengajuan-tempo/component/PengajuanTempo.jsx   | 25 ++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

(limited to 'src/lib/pengajuan-tempo/component/PengajuanTempo.jsx')

diff --git a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
index 58794b31..aff49373 100644
--- a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
+++ b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
@@ -178,6 +178,7 @@ const PengajuanTempo = () => {
           `/api/v1/partner/detail-tempo/${auth.parentId}`
         );
         const transformedData = transformKeysToCamelCase(dataPaymentTerm);
+
         setBigData(transformedData);
       } catch (error) {
         console.error('Error loading dataPaymentTerm:', error);
@@ -454,16 +455,28 @@ const PengajuanTempo = () => {
         }
       }
 
+      toast.dismiss(toastId);
+      setIsLoading(false);
+      toast.success('Pengajuan tempo berhasil dilakukan');
       if (address4?.id) {
+        const toastId = toast.loading('Mengubah status akun...');
+        setIsLoading(true);
         const isUpdated = await editAuthTempo();
         if (isUpdated?.user) {
-          setAuth(isUpdated.user);
-          toast.dismiss(toastId);
-          setIsLoading(false);
-          toast.success('Pengajuan tempo berhasil dilakukan');
-          toast.success('Berhasil mengubah status akun', { duration: 1000 });
+          const update = await setAuth(isUpdated.user);
+          if (update) {
+            toast.dismiss(toastId);
+            setIsLoading(false);
+            toast.success('Berhasil mengubah status akun', { duration: 1000 });
+            router.push('/pengajuan-tempo/finish');
+          } else {
+            toast.dismiss(toastId);
+            setIsLoading(false);
+            toast.success('Pengajuan tempo berhasil dilakukan');
+            toast.error('Gagal mengubah status akun', { duration: 1000 });
+            router.push('/pengajuan-tempo');
+          }
           removeFromLocalStorage();
-          router.push('/pengajuan-tempo/finish');
           return;
         }
       }
-- 
cgit v1.2.3

