From 494909f40b918e4273d6258a74f12ac42253a4a7 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Mon, 25 Nov 2024 17:04:51 +0700
Subject: <iman> pengajuan tempo

---
 src/lib/pengajuan-tempo/component/Pengiriman.jsx | 125 ++++++-----------------
 1 file changed, 29 insertions(+), 96 deletions(-)

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

diff --git a/src/lib/pengajuan-tempo/component/Pengiriman.jsx b/src/lib/pengajuan-tempo/component/Pengiriman.jsx
index 0c96c060..7b0a9455 100644
--- a/src/lib/pengajuan-tempo/component/Pengiriman.jsx
+++ b/src/lib/pengajuan-tempo/component/Pengiriman.jsx
@@ -33,49 +33,19 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
   const [tukarInvoicePembayaran, setTukarInvoicePembayaran] = useState(false);
   const [selectedRadio, setSelectedRadio] = useState('');
   const [selectedRadioInvoice, setSelectedRadioInvoice] = useState('');
-  const dokumen_kirim = [
-    ['Surat Tanda Terima Barang (STTB)', '0'],
-    ['Good Receipt (GR)', '1'],
-    ['Surat Terima Barang (STB)', '2'],
-    ['Lembar Penerimaan Barang (LPB)', '3'],
-  ];
-  const Dokumen_invoice = [
-    ['Invoice Pembelian', '0'],
-    ['Surat Jalan', '1'],
-    ['Berita Acara Serah Terima (BAST)', '2'],
-    ['Faktur Pajak', '3'],
-    ['Good Receipt (GR)', '4'],
-  ];
-  const [selectedIds, setSelectedIds] = useState(() => {
-    if (formPengiriman.dokumenPengiriman) {
-      const selectedDocuments = formPengiriman.dokumenPengiriman
-        .split(',')
-        .map((item) => item.trim());
-
-      return selectedDocuments.map((docName) => {
-        const match = dokumen_kirim.find(([name]) => name === docName);
-        return match ? Number(match[1]) : 5; // Jika cocok, gunakan ID; jika tidak, gunakan 5
-      });
-    }
-    return [];
-  });
 
-  const [selectedIdsDokumenInvoice, setSelectedIdsDokumenInvoice] = useState(
-    () => {
-      if (formPengiriman.dokumenPengirimanInvoice) {
-        // Pisahkan string dokumen berdasarkan koma dan hilangkan spasi ekstra
-        const selectedDocuments = formPengiriman.dokumenPengirimanInvoice
-          .split(',')
-          .map((item) => item.trim());
-        // Cari ID berdasarkan posisi nama dokumen di array Dokumen_invoice
-        return selectedDocuments.map((docName) => {
-          const match = Dokumen_invoice.find(([name]) => name === docName);
-          return match ? Number(match[1]) : 5; // Jika cocok, gunakan ID; jika tidak, gunakan 5
-        });
-      }
-      return [];
-    }
+  const [selectedIds, setSelectedIds] = useState(
+    formPengiriman.dokumenPengiriman
+      ? formPengiriman.dokumenPengiriman.split(',').map(Number)
+      : []
   );
+  console.log('selectedIds', selectedIds);
+  const [selectedIdsDokumenInvoice, setSelectedIdsselectedIdsDokumenInvoice] =
+    useState(
+      formPengiriman.dokumenPengirimanInvoice
+        ? formPengiriman.dokumenPengirimanInvoice.split(',').map(Number)
+        : []
+    );
 
   const handleCheckboxChange = (id) => {
     const updatedSelected = selectedIds.includes(id)
@@ -94,7 +64,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
       ? selectedIdsDokumenInvoice.filter((selectedId) => selectedId !== id)
       : [...selectedIdsDokumenInvoice, id];
 
-    setSelectedIdsDokumenInvoice(updatedSelected);
+    setSelectedIdsselectedIdsDokumenInvoice(updatedSelected);
 
     // Jika checkbox 'Lainnya' dipilih, aktifkan input custom
 
@@ -104,37 +74,14 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
 
   useEffect(() => {
     if (formPengiriman.dokumenPengiriman) {
-      // Pisahkan string berdasarkan koma dan trim spasi
-      const selectedDocuments = formPengiriman.dokumenPengiriman
-        .split(',')
-        .map((item) => item.trim());
-
-      // Map setiap dokumen, cocokkan nama dokumen dengan ID yang sesuai, atau set ke 5 jika tidak cocok
-      const matchingIds = selectedDocuments.map((docName) => {
-        const match = dokumen_kirim.find(([name]) => name === docName);
-        return match ? Number(match[1]) : 5; // Jika cocok gunakan ID; jika tidak, gunakan 5
-      });
-
-      // Set hasil ID yang sesuai atau default ke state selectedIds
-      setSelectedIds(matchingIds);
+      setSelectedIds(formPengiriman.dokumenPengiriman.split(',').map(Number)); // Parse string menjadi array angka
     }
   }, [formPengiriman.dokumenPengiriman]);
-
   useEffect(() => {
     if (formPengiriman.dokumenPengirimanInvoice) {
-      // Pisahkan string berdasarkan koma dan trim spasi
-      const selectedDocuments = formPengiriman.dokumenPengirimanInvoice
-        .split(',')
-        .map((item) => item.trim());
-
-      // Temukan ID berdasarkan posisi dokumen di dalam array Dokumen_invoice
-      const matchingIds = selectedDocuments.map((docName) => {
-        const match = Dokumen_invoice.find(([name]) => name === docName);
-        return match ? Number(match[1]) : 5; // Jika cocok gunakan ID; jika tidak, gunakan 5
-      });
-
-      // Set hasil ID yang cocok ke state selectedIdsDokumenInvoice
-      setSelectedIdsDokumenInvoice(matchingIds);
+      setSelectedIdsselectedIdsDokumenInvoice(
+        formPengiriman.dokumenPengirimanInvoice.split(',').map(Number)
+      ); // Parse string menjadi array angka
     }
   }, [formPengiriman.dokumenPengirimanInvoice]);
 
@@ -424,7 +371,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
       setValue('statePengiriman', '');
       setValue('cityPengiriman', '');
     }
-    updateFormPengiriman('isSameAddrees', `${sameAddress}`);
+    updateFormPengiriman('isSameAddreesStreet', `${sameAddressStreet}`);
     validatePengiriman();
   }, [sameAddressStreet]);
 
@@ -901,10 +848,8 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
                   <Checkbox
                     colorScheme='red'
                     key='0'
-                    isChecked={isChecked('Surat Tanda Terima Barang (STTB)')}
-                    onChange={() =>
-                      handleCheckboxChange('Surat Tanda Terima Barang (STTB)')
-                    }
+                    isChecked={isChecked(0)}
+                    onChange={() => handleCheckboxChange(0)}
                   >
                     Surat Tanda Terima Barang (STTB)
                   </Checkbox>
@@ -912,7 +857,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
                     colorScheme='red'
                     key='1'
                     isChecked={isChecked(1)}
-                    onChange={() => handleCheckboxChange('Good Receipt (GR)')}
+                    onChange={() => handleCheckboxChange(1)}
                   >
                     Good Receipt (GR)
                   </Checkbox>
@@ -920,9 +865,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
                     colorScheme='red'
                     key='2'
                     isChecked={isChecked(2)}
-                    onChange={() =>
-                      handleCheckboxChange('Surat Terima Barang (STB)')
-                    }
+                    onChange={() => handleCheckboxChange(2)}
                   >
                     Surat Terima Barang (STB)
                   </Checkbox>
@@ -930,9 +873,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
                     colorScheme='red'
                     key='3'
                     isChecked={isChecked(3)}
-                    onChange={() =>
-                      handleCheckboxChange('Lembar Penerimaan Barang (LPB)')
-                    }
+                    onChange={() => handleCheckboxChange(3)}
                   >
                     Lembar Penerimaan Barang (LPB)
                   </Checkbox>
@@ -942,7 +883,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
                       colorScheme='red'
                       key='4'
                       isChecked={isChecked(4)}
-                      onChange={() => handleCheckboxChange('Lainnya')}
+                      onChange={() => handleCheckboxChange(4)}
                     >
                       Lainnya
                     </Checkbox>
@@ -985,9 +926,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
                     key='0'
                     isChecked={isCheckedInvoice(0)}
                     onChange={() =>
-                      handleCheckboxChangeDokumenPengirimanInvoice(
-                        'Invoice Pembelian'
-                      )
+                      handleCheckboxChangeDokumenPengirimanInvoice(0)
                     }
                   >
                     Invoice Pembelian
@@ -997,9 +936,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
                     key='1'
                     isChecked={isCheckedInvoice(1)}
                     onChange={() =>
-                      handleCheckboxChangeDokumenPengirimanInvoice(
-                        ' Surat Jalan'
-                      )
+                      handleCheckboxChangeDokumenPengirimanInvoice(1)
                     }
                   >
                     Surat Jalan
@@ -1009,7 +946,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
                     key='2'
                     isChecked={isCheckedInvoice(2)}
                     onChange={() =>
-                      handleCheckboxChangeDokumenPengirimanInvoice('')
+                      handleCheckboxChangeDokumenPengirimanInvoice(2)
                     }
                   >
                     Berita Acara Serah Terima (BAST)
@@ -1019,9 +956,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
                     key='3'
                     isChecked={isCheckedInvoice(3)}
                     onChange={() =>
-                      handleCheckboxChangeDokumenPengirimanInvoice(
-                        'Faktur Pajak'
-                      )
+                      handleCheckboxChangeDokumenPengirimanInvoice(3)
                     }
                   >
                     Faktur Pajak
@@ -1031,9 +966,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
                     key='4'
                     isChecked={isCheckedInvoice(4)}
                     onChange={() =>
-                      handleCheckboxChangeDokumenPengirimanInvoice(
-                        'Good Receipt (GR)'
-                      )
+                      handleCheckboxChangeDokumenPengirimanInvoice(4)
                     }
                   >
                     Good Receipt (GR)
@@ -1045,7 +978,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
                       key='5'
                       isChecked={isCheckedInvoice(5)}
                       onChange={() =>
-                        handleCheckboxChangeDokumenPengirimanInvoice('Lainnya')
+                        handleCheckboxChangeDokumenPengirimanInvoice(5)
                       }
                     >
                       Lainnya
-- 
cgit v1.2.3

