From daaf32f9dd3af860013b70d04c89f4cca84724b1 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Tue, 29 Oct 2024 16:22:33 +0700
Subject: <iman> updarte pengajuan tempo

---
 .../pengajuan-tempo/component/PengajuanTempo.jsx   | 50 ++++++++++++++++++++--
 1 file changed, 47 insertions(+), 3 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 d44d44e6..0efea807 100644
--- a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
+++ b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
@@ -18,6 +18,7 @@ import {
   usePengajuanTempoStoreDokumen,
 } from '../../../../src-migrate/modules/register/stores/usePengajuanTempoStore';
 import { ChevronRightIcon, ChevronLeftIcon } from '@heroicons/react/24/outline';
+import createPengajuanTempoApi from '../api/createPengajuanTempoApi';
 const PengajuanTempo = () => {
   const [currentStep, setCurrentStep] = React.useState(0);
   const NUMBER_OF_STEPS = 6;
@@ -71,7 +72,7 @@ const PengajuanTempo = () => {
     formPengiriman,
     formSupplier,
     formDokumen,
-    <div>Konfirmasi</div>,
+    '',
   ];
   const stepDivsUpdateForm = [
     updateForm,
@@ -89,6 +90,21 @@ const PengajuanTempo = () => {
     'Dokumen',
     'Konfirmasi',
   ];
+  const combineForms = () => {
+    return stepDivsForm.reduce((accumulator, currentForm, index) => {
+      if (currentForm && typeof currentForm === 'object') {
+        if (index === 3) {
+          if (!accumulator.formSupplier) {
+            accumulator.formSupplier = [];
+          }
+          accumulator.formSupplier.push(...currentForm);
+        } else {
+          return { ...accumulator, ...currentForm };
+        }
+      }
+      return accumulator;
+    }, {});
+  };
 
   // const stepLabels = [
   //   `${auth.partnerId}_informasi_perusahaan`,
@@ -148,8 +164,36 @@ const PengajuanTempo = () => {
     }
     setCurrentStep((prev) => (prev === NUMBER_OF_STEPS - 1 ? prev : prev + 1));
   };
-  const handleDaftarTempo = () => {
-    router.push('/pengajuan-tempo/finish?tempo_id=SO-2023-06480');
+  const handleDaftarTempo = async () => {
+    for (const error of stepDivsError) {
+      if (error.length > 0) {
+        console.log('ada yang salah');
+        return; // Keluar dari fungsi jika ada error
+      }
+    }
+    const combinedData = combineForms();
+    console.log('combinedData', combinedData);
+    const data = {
+      ...combinedData,
+      parent_id: auth.partnerId,
+    };
+
+    const productOrder = formSupplier.map((product) => ({
+      supplier: product.supplier,
+      pic: product.pic,
+      telepon: product.telepon,
+      quantitydurasiTempo: product.durasiTempo,
+      creditLimit: product.creditLimit,
+    }));
+    const data2 = {
+      form: JSON.stringify(productOrder),
+      parent_id: auth.partnerId,
+    };
+    const address = await createPengajuanTempoApi({ combinedData });
+
+    console.log('Sukses Daftar');
+    // router.push('/pengajuan-tempo/finish?tempo_id=SO-2023-06480');
+
     // if (!isFormValid) {
     //   setNotValid(true);
     //   setButtonSubmitClick(!buttonSubmitClick);
-- 
cgit v1.2.3

