From 77f9843ad5072583cb1797d7ecf5ac80394bad3f Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Mon, 2 Dec 2024 09:31:44 +0700
Subject: <iman> pengajuan tempo

---
 .../pengajuan-tempo/component/PengajuanTempo.jsx   | 43 ++++++++++++++++------
 1 file changed, 31 insertions(+), 12 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 ab66f94f..97e64030 100644
--- a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
+++ b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
@@ -8,6 +8,8 @@ import Referensi from './Referensi';
 import Dokumen from './Dokumen';
 import Konfirmasi from './Konfirmasi';
 import { getAuth } from '~/libs/auth';
+import { setAuth } from '@/core/utils/auth';
+import useAuth from '@/core/hooks/useAuth';
 import { useRouter } from 'next/router';
 import { Controller, useForm } from 'react-hook-form';
 import {
@@ -24,6 +26,7 @@ import clsxm from '~/libs/clsxm';
 import { toast } from 'react-hot-toast';
 import useDevice from '@/core/hooks/useDevice';
 import odooApi from '~/libs/odooApi';
+import editAuthTempo from '../api/editAuthTempo';
 const PengajuanTempo = () => {
   const { isDesktop, isMobile } = useDevice();
   const [currentStep, setCurrentStep] = React.useState(0);
@@ -33,7 +36,7 @@ const PengajuanTempo = () => {
   const [idTempo, setIdTempo] = useState(0);
   const { form, errors, validate, updateForm } = usePengajuanTempoStore();
   const { control, watch, setValue } = useForm();
-  const auth = getAuth();
+  const auth = useAuth();
   const router = useRouter();
   const { formDokumen, errorsDokumen, validateDokumen, updateFormDokumen } =
     usePengajuanTempoStoreDokumen();
@@ -363,6 +366,7 @@ const PengajuanTempo = () => {
       console.error(error);
     }
   };
+
   const handleDaftarTempo = async () => {
     for (const error of stepDivsError) {
       if (error.length > 0) {
@@ -386,46 +390,55 @@ const PengajuanTempo = () => {
       },
     }));
 
-    const data2 = {
-      user_id: auth.id,
-      ...form,
-      ...formKontakPerson,
-      ...formPengiriman,
-      formDocs: JSON.stringify(formattedDokumen),
-      formSupplier: JSON.stringify(productOrder),
-    };
+    // const data2 = {
+    //   user_id: auth.id,
+    //   ...form,
+    //   ...formKontakPerson,
+    //   ...formPengiriman,
+    //   formDocs: JSON.stringify(formattedDokumen),
+    //   formSupplier: JSON.stringify(productOrder),
+    // };
     const toastId = toast.loading('Mengirimkan formulir pengajuan tempo...');
     setIsLoading(true);
     try {
       let address5;
+      console.log('MASUK SINI');
       const address = await createPengajuanTempoApi({
         id: 0,
+        partner_id: auth.partnerId,
         user_id: auth.parentId,
-        tempo_request: tempoRequest,
+        tempo_request: false,
         ...form,
       });
       console.log('address', address);
       if (address.id) {
         const address2 = await createPengajuanTempoApi({
           id: address.id,
+          partner_id: auth.partnerId,
           user_id: address.userId,
+          tempo_request: false,
           ...formKontakPerson,
         });
         if (address2.id) {
           const address3 = await createPengajuanTempoApi({
             id: address2.id,
+            partner_id: auth.partnerId,
             user_id: address2.userId,
+            tempo_request: false,
             ...formPengiriman,
           });
           if (address3.id) {
             const address4 = await createPengajuanTempoApi({
               id: address3.id,
+              partner_id: auth.partnerId,
               user_id: address3.userId,
+              tempo_request: false,
               formDocs: JSON.stringify(formattedDokumen),
             });
             if (address4.id) {
               address5 = await createPengajuanTempoApi({
                 id: address4.id,
+                partner_id: auth.partnerId,
                 user_id: address4.userId,
                 tempo_request: true,
                 formSupplier: JSON.stringify(productOrder),
@@ -439,8 +452,14 @@ const PengajuanTempo = () => {
 
       if (address5.id) {
         toast.success('Pengajuan tempo berhasil dilakukan');
-        removeFromLocalStorage();
-        router.push('/pengajuan-tempo/finish?tempo_id=SO-2023-06480');
+        const isUpdated = await editAuthTempo();
+        if (isUpdated?.user) {
+          setAuth(isUpdated.user);
+          toast.success('Berhasil mengubah status akun', { duration: 1000 });
+          removeFromLocalStorage();
+          router.push('/pengajuan-tempo/finish?tempo_id=SO-2023-06480');
+          return;
+        }
       }
     } catch (error) {
       toast.dismiss(toastId);
-- 
cgit v1.2.3

