From 915dc67e1ce31eab1f2415cc8df95cebb75a137d Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Fri, 13 Dec 2024 14:18:03 +0700
Subject: <iman>update pengajuan tempo request

---
 .../pengajuan-tempo/component/PengajuanTempo.jsx   | 23 +++++++++++++++-------
 1 file changed, 16 insertions(+), 7 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 aff49373..b4f4ac9b 100644
--- a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
+++ b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
@@ -178,7 +178,6 @@ const PengajuanTempo = () => {
           `/api/v1/partner/detail-tempo/${auth.parentId}`
         );
         const transformedData = transformKeysToCamelCase(dataPaymentTerm);
-
         setBigData(transformedData);
       } catch (error) {
         console.error('Error loading dataPaymentTerm:', error);
@@ -419,6 +418,7 @@ const PengajuanTempo = () => {
     setIsLoading(true);
     try {
       let address4;
+      let address3;
       const address = await createPengajuanTempoApi({
         id: 0,
         partner_id: auth.partnerId,
@@ -435,7 +435,7 @@ const PengajuanTempo = () => {
           ...formKontakPerson,
         });
         if (address2.id) {
-          const address3 = await createPengajuanTempoApi({
+          address3 = await createPengajuanTempoApi({
             id: address2.id,
             partner_id: auth.partnerId,
             user_id: address2.userId,
@@ -451,16 +451,20 @@ const PengajuanTempo = () => {
               tempo_request: true,
               formDocs: JSON.stringify(formattedDokumen),
             });
+          } else {
+            address4 = await createPengajuanTempoApi({
+              id: address3.id,
+              partner_id: auth.partnerId,
+              user_id: address3.userId,
+              tempo_request: true,
+            });
           }
         }
       }
 
-      toast.dismiss(toastId);
-      setIsLoading(false);
-      toast.success('Pengajuan tempo berhasil dilakukan');
       if (address4?.id) {
+        toast.success('Pengajuan tempo berhasil dilakukan');
         const toastId = toast.loading('Mengubah status akun...');
-        setIsLoading(true);
         const isUpdated = await editAuthTempo();
         if (isUpdated?.user) {
           const update = await setAuth(isUpdated.user);
@@ -479,6 +483,11 @@ const PengajuanTempo = () => {
           removeFromLocalStorage();
           return;
         }
+      } else {
+        toast.dismiss(toastId);
+        setIsLoading(false);
+
+        toast.error('Terjadi kesalahan dalam pengiriman formulir');
       }
     } catch (error) {
       toast.dismiss(toastId);
@@ -518,7 +527,7 @@ const PengajuanTempo = () => {
   return (
     <>
       <div className='container flex flex-col items-center '>
-        <h1 className='text-h-sm md:text-title-sm font-semibold text-center mb-6'>
+        <h1 className=' font-semibold text-center mb-6'>
           Form Pengajuan Tempo
         </h1>
         <p className='text-center mb-4'>
-- 
cgit v1.2.3

