From 654fbb128ab331c3272d6e8733dda1b5b71f4253 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Mon, 25 Nov 2024 10:05:02 +0700
Subject: <iman> update pengajuan tempo

---
 src/lib/pengajuan-tempo/component/Pengiriman.jsx | 34 ++++++++++++++++--------
 1 file changed, 23 insertions(+), 11 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 adf2ee37..bae3214b 100644
--- a/src/lib/pengajuan-tempo/component/Pengiriman.jsx
+++ b/src/lib/pengajuan-tempo/component/Pengiriman.jsx
@@ -33,12 +33,24 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
   const [tukarInvoicePembayaran, setTukarInvoicePembayaran] = useState(false);
   const [selectedRadio, setSelectedRadio] = useState('');
   const [selectedRadioInvoice, setSelectedRadioInvoice] = useState('');
-
-  const [selectedIds, setSelectedIds] = useState(
-    formPengiriman.dokumenPengiriman
-      ? formPengiriman.dokumenPengiriman.split(',').map(Number)
-      : []
-  );
+  const dokumen_kirim = [
+    ['Surat Tanda Terima Barang (STTB)', '0'],
+    ['Good Receipt (GR)', '1'],
+    ['Surat Terima Barang (STB)', '2'],
+    ['Lembar Penerimaan Barang (LPB)', '3'],
+  ];
+  const [selectedIds, setSelectedIds] = useState(() => {
+    if (formPengiriman.dokumenPengiriman) {
+      const selectedDocuments = formPengiriman.dokumenPengiriman
+        .split(',')
+        .map((item) => item.trim());
+      return dokumen_kirim
+        .filter(([name]) => selectedDocuments.includes(name))
+        .map(([, id]) => Number(id));
+    }
+    return [];
+  });
+  console.log('selectedIds', selectedIds);
   const [selectedIdsDokumenInvoice, setSelectedIdsselectedIdsDokumenInvoice] =
     useState(
       formPengiriman.dokumenPengirimanInvoice
@@ -71,11 +83,11 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
     validatePengiriman();
   };
 
-  useEffect(() => {
-    if (formPengiriman.dokumenPengiriman) {
-      setSelectedIds(formPengiriman.dokumenPengiriman.split(',').map(Number)); // Parse string menjadi array angka
-    }
-  }, [formPengiriman.dokumenPengiriman]);
+  // useEffect(() => {
+  //   if (formPengiriman.dokumenPengiriman) {
+  //     setSelectedIds(formPengiriman.dokumenPengiriman.split(',').map(Number)); // Parse string menjadi array angka
+  //   }
+  // }, [formPengiriman.dokumenPengiriman]);
   useEffect(() => {
     if (formPengiriman.dokumenPengirimanInvoice) {
       setSelectedIdsselectedIdsDokumenInvoice(
-- 
cgit v1.2.3

