From fc837f851c89614f392e5a17cd6a2ceda3f706f3 Mon Sep 17 00:00:00 2001
From: Miqdad <ahmadmiqdad27@gmail.com>
Date: Mon, 11 Aug 2025 16:32:03 +0700
Subject: <miqdad> more vals in confirm page

---
 .../pengajuan-tempo/component/PengajuanTempo.jsx   | 250 +++++++++++++--------
 1 file changed, 161 insertions(+), 89 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 d59bfd75..5f3dd08c 100644
--- a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
+++ b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
@@ -38,7 +38,7 @@ const PengajuanTempo = () => {
   const [bigData, setBigData] = useState();
   const [idTempo, setIdTempo] = useState(0);
   const { form, errors, validate, updateForm } = usePengajuanTempoStore();
-  const { control, watch, setValue } = useForm();
+  const { control, watch, setValue, setError } = useForm();
   const auth = useAuth();
   const router = useRouter();
   const [BannerTempo, setBannerTempo] = useState();
@@ -426,111 +426,185 @@ const PengajuanTempo = () => {
     }
   };
 
-  const handleDaftarTempo = async () => {
-    for (const error of stepDivsError) {
-      if (error.length > 0) {
-        return;
+const handleDaftarTempo = async () => {
+  const phones = [
+    { key: 'mobile', label: 'No. HP Perusahaan', value: form.mobile },
+    {
+      key: 'direkturMobile',
+      label: 'No. HP Direktur',
+      value: formKontakPerson.direkturMobile,
+    },
+    {
+      key: 'purchasingMobile',
+      label: 'No. HP Purchasing',
+      value: formKontakPerson.purchasingMobile,
+    },
+    {
+      key: 'financeMobile',
+      label: 'No. HP Finance',
+      value: formKontakPerson.financeMobile,
+    },
+    {
+      key: 'PICBarangMobile',
+      label: 'No. HP PIC Barang',
+      value: formKontakPerson.PICBarangMobile,
+    },
+    {
+      key: 'invoicePicMobile',
+      label: 'No. HP PIC Invoice',
+      value: formKontakPerson.invoicePicMobile,
+    },
+  ].filter((p) => p.value);
+
+  const seen = new Map();
+  let firstErrorField = null;
+
+  // 🔹 Reset error manual sebelum cek ulang
+  phones.forEach((p) => setError(p.key, { type: 'manual', message: '' }));
+
+  for (const phone of phones) {
+    if (!seen.has(phone.value)) {
+      seen.set(phone.value, phone);
+    } else {
+      const first = seen.get(phone.value);
+
+      // 🔹 Tampilkan toast
+      toast.error(`${phone.label} tidak boleh sama dengan ${first.label}`);
+
+      // 🔹 Tampilkan error merah di bawah input
+      setError(phone.key, {
+        type: 'manual',
+        message: `${phone.label} tidak boleh sama dengan ${first.label}`,
+      });
+
+      // 🔹 Juga beri error untuk pasangan duplikat pertama
+      setError(first.key, {
+        type: 'manual',
+        message: `${first.label} tidak boleh sama dengan ${phone.label}`,
+      });
+
+      // 🔹 Simpan field pertama yang salah untuk scroll
+      if (!firstErrorField) {
+        firstErrorField = phone.key;
       }
     }
+  }
+
+  if (firstErrorField) {
+    setTimeout(() => {
+      const el = document.querySelector(`[name="${firstErrorField}"]`);
+      if (el) {
+        el.scrollIntoView({ behavior: 'smooth', block: 'center' });
+        el.focus();
+      }
+    }, 100);
+    return; // ⛔ hentikan proses submit
+  }
 
-    // Filter hanya dokumen dengan `format` yang tidak undefined
-    const formattedDokumen = Object.entries(formDokumen)
-      .filter(([_, doc]) => doc.format !== undefined) // Hanya dokumen dengan `format` tidak undefined
-      .map(([key, doc]) => ({
-        documentName: key,
-        details: {
-          name: doc.name,
-          format: doc.format,
-          base64: doc.base64,
-        },
-      }));
+  for (const error of stepDivsError) {
+    if (error.length > 0) {
+      return;
+    }
+  }
+
+  const formattedDokumen = Object.entries(formDokumen)
+    .filter(([_, doc]) => doc.format !== undefined)
+    .map(([key, doc]) => ({
+      documentName: key,
+      details: {
+        name: doc.name,
+        format: doc.format,
+        base64: doc.base64,
+      },
+    }));
 
-    const toastId = toast.loading('Mengirimkan formulir pengajuan tempo...');
-    setIsLoading(true);
-    try {
-      let address4;
-      let address3;
-      const address = await createPengajuanTempoApi({
-        id: 0,
+  const toastId = toast.loading('Mengirimkan formulir pengajuan tempo...');
+  setIsLoading(true);
+
+  try {
+    let address4;
+    let address3;
+    const address = await createPengajuanTempoApi({
+      id: 0,
+      partner_id: auth.partnerId,
+      user_id: auth.parentId ? auth.parentId : auth.partnerId,
+      tempo_request: false,
+      ...form,
+    });
+
+    if (address.id) {
+      const address2 = await createPengajuanTempoApi({
+        id: address.id,
         partner_id: auth.partnerId,
-        user_id: auth.parentId ? auth.parentId : auth.partnerId,
+        user_id: address.userId,
         tempo_request: false,
-        ...form,
+        ...formKontakPerson,
       });
-      if (address.id) {
-        const address2 = await createPengajuanTempoApi({
-          id: address.id,
+
+      if (address2.id) {
+        address3 = await createPengajuanTempoApi({
+          id: address2.id,
           partner_id: auth.partnerId,
-          user_id: address.userId,
+          user_id: address2.userId,
           tempo_request: false,
-          ...formKontakPerson,
-        });
-        if (address2.id) {
-          address3 = await createPengajuanTempoApi({
-            id: address2.id,
-            partner_id: auth.partnerId,
-            user_id: address2.userId,
-            tempo_request: false,
-            ...formPengiriman,
-            formDokumenProsedur: formPengiriman.dokumenProsedur
+          ...formPengiriman,
+          formDokumenProsedur: formPengiriman.dokumenProsedur
             ? JSON.stringify(formPengiriman.dokumenProsedur)
             : false,
+        });
+
+        if (address3.id && formattedDokumen.length > 0) {
+          address4 = await createPengajuanTempoApi({
+            id: address3.id,
+            partner_id: auth.partnerId,
+            user_id: address3.userId,
+            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,
           });
-          if (address3.id && formattedDokumen.length > 0) {
-            // Kirim dokumen yang sudah difilter
-            address4 = await createPengajuanTempoApi({
-              id: address3.id,
-              partner_id: auth.partnerId,
-              user_id: address3.userId,
-              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,
-            });
-          }
         }
       }
+    }
 
-      if (address4?.id) {
-        toast.success('Pengajuan tempo berhasil dilakukan');
-        const toastId = toast.loading('Mengubah status akun...');
-        const isUpdated = await editAuthTempo();
-        if (isUpdated?.user) {
-          const update = await setAuth(isUpdated.user);
-          if (update) {
-            toast.dismiss(toastId);
-            setIsLoading(false);
-            toast.success('Berhasil mengubah status akun', { duration: 1000 });
-            router.push('/pengajuan-tempo/finish');
-          } else {
-            toast.dismiss(toastId);
-            setIsLoading(false);
-            toast.success('Pengajuan tempo berhasil dilakukan');
-            toast.error('Gagal mengubah status akun', { duration: 1000 });
-            router.push('/pengajuan-tempo');
-          }
-          removeFromLocalStorage();
-          return;
+    if (address4?.id) {
+      toast.success('Pengajuan tempo berhasil dilakukan');
+      const toastId2 = toast.loading('Mengubah status akun...');
+      const isUpdated = await editAuthTempo();
+      if (isUpdated?.user) {
+        const update = await setAuth(isUpdated.user);
+        if (update) {
+          toast.dismiss(toastId2);
+          setIsLoading(false);
+          toast.success('Berhasil mengubah status akun', { duration: 1000 });
+          router.push('/pengajuan-tempo/finish');
+        } else {
+          toast.dismiss(toastId2);
+          setIsLoading(false);
+          toast.success('Pengajuan tempo berhasil dilakukan');
+          toast.error('Gagal mengubah status akun', { duration: 1000 });
+          router.push('/pengajuan-tempo');
         }
-      } else {
-        toast.dismiss(toastId);
-        setIsLoading(false);
-
-        toast.error('Terjadi kesalahan dalam pengiriman formulir');
+        removeFromLocalStorage();
+        return;
       }
-    } catch (error) {
+    } else {
       toast.dismiss(toastId);
       setIsLoading(false);
-
       toast.error('Terjadi kesalahan dalam pengiriman formulir');
-      console.error(error);
     }
-  };
+  } catch (error) {
+    toast.dismiss(toastId);
+    setIsLoading(false);
+    toast.error('Terjadi kesalahan dalam pengiriman formulir');
+    console.error(error);
+  }
+};
 
   const removeFromLocalStorage = () => {
     for (const key of stepLabels) {
@@ -660,10 +734,8 @@ const PengajuanTempo = () => {
                 isDisabled={!isCheckedTNC || isLoading}
                 onClick={handleDaftarTempo}
               >
-                {isLoading
-                  ? 'Loading...'
-                  : 'Daftar Tempo'}
-                  {!isLoading && <ChevronRightIcon className='w-5' />}
+                {isLoading ? 'Loading...' : 'Daftar Tempo'}
+                {!isLoading && <ChevronRightIcon className='w-5' />}
               </Button>
             </div>
           )}
-- 
cgit v1.2.3


From 3b92b629711f9afce8d7678814160e800d7211e0 Mon Sep 17 00:00:00 2001
From: Miqdad <ahmadmiqdad27@gmail.com>
Date: Mon, 11 Aug 2025 18:09:39 +0700
Subject: <miqdad>push

---
 src/lib/pengajuan-tempo/component/PengajuanTempo.jsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(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 5f3dd08c..fe50f8a4 100644
--- a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
+++ b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
@@ -498,7 +498,7 @@ const handleDaftarTempo = async () => {
         el.focus();
       }
     }, 100);
-    return; // ⛔ hentikan proses submit
+    return;
   }
 
   for (const error of stepDivsError) {
-- 
cgit v1.2.3


From 286f4bd39d54a13e21a3c163f92ad4138739ab1d Mon Sep 17 00:00:00 2001
From: Miqdad <ahmadmiqdad27@gmail.com>
Date: Tue, 12 Aug 2025 13:31:21 +0700
Subject: <miqdad>Done

---
 .../pengajuan-tempo/component/PengajuanTempo.jsx   | 66 +++++++++++-----------
 1 file changed, 33 insertions(+), 33 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 fe50f8a4..ae3d97fd 100644
--- a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
+++ b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
@@ -427,39 +427,40 @@ const PengajuanTempo = () => {
   };
 
 const handleDaftarTempo = async () => {
-  const phones = [
-    { key: 'mobile', label: 'No. HP Perusahaan', value: form.mobile },
-    {
-      key: 'direkturMobile',
-      label: 'No. HP Direktur',
-      value: formKontakPerson.direkturMobile,
-    },
-    {
-      key: 'purchasingMobile',
-      label: 'No. HP Purchasing',
-      value: formKontakPerson.purchasingMobile,
-    },
-    {
-      key: 'financeMobile',
-      label: 'No. HP Finance',
-      value: formKontakPerson.financeMobile,
-    },
-    {
-      key: 'PICBarangMobile',
-      label: 'No. HP PIC Barang',
-      value: formKontakPerson.PICBarangMobile,
-    },
-    {
-      key: 'invoicePicMobile',
-      label: 'No. HP PIC Invoice',
-      value: formKontakPerson.invoicePicMobile,
-    },
-  ].filter((p) => p.value);
+const phones = [
+  { key: 'mobile', label: 'No. HP Perusahaan', value: form.mobile?.trim() },
+  {
+    key: 'direkturMobile',
+    label: 'No. HP Direktur',
+    value: formKontakPerson.direkturMobile?.trim(),
+  },
+  {
+    key: 'purchasingMobile',
+    label: 'No. HP Purchasing',
+    value: formKontakPerson.purchasingMobile?.trim(),
+  },
+  {
+    key: 'financeMobile',
+    label: 'No. HP Finance',
+    value: formKontakPerson.financeMobile?.trim(),
+  },
+  {
+    key: 'PICBarangMobile',
+    label: 'No. HP PIC Barang',
+    value: formPengiriman.PICBarangMobile?.trim(),
+  },
+  {
+    key: 'invoicePicMobile',
+    label: 'No. HP PIC Invoice',
+    value: formPengiriman.invoicePicMobile?.trim(),
+  },
+].filter((p) => p.value);
+
 
   const seen = new Map();
   let firstErrorField = null;
 
-  // 🔹 Reset error manual sebelum cek ulang
+  // Reset error manual
   phones.forEach((p) => setError(p.key, { type: 'manual', message: '' }));
 
   for (const phone of phones) {
@@ -468,22 +469,21 @@ const handleDaftarTempo = async () => {
     } else {
       const first = seen.get(phone.value);
 
-      // 🔹 Tampilkan toast
+      // Tampilkan toast
       toast.error(`${phone.label} tidak boleh sama dengan ${first.label}`);
 
-      // 🔹 Tampilkan error merah di bawah input
+      // Error merah di bawah input
       setError(phone.key, {
         type: 'manual',
         message: `${phone.label} tidak boleh sama dengan ${first.label}`,
       });
 
-      // 🔹 Juga beri error untuk pasangan duplikat pertama
+      // Pasangan pertama yang duplikat
       setError(first.key, {
         type: 'manual',
         message: `${first.label} tidak boleh sama dengan ${phone.label}`,
       });
 
-      // 🔹 Simpan field pertama yang salah untuk scroll
       if (!firstErrorField) {
         firstErrorField = phone.key;
       }
-- 
cgit v1.2.3


From b1bdfbb9f780a1a1305e02c4b9c338b98c7a4556 Mon Sep 17 00:00:00 2001
From: "Indoteknik ." <andrifebriyadiputra@gmail.com>
Date: Fri, 15 Aug 2025 13:58:59 +0700
Subject: (andri) fix switch account

---
 src/lib/pengajuan-tempo/component/PengajuanTempo.jsx | 1 +
 1 file changed, 1 insertion(+)

(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 d59bfd75..3dac0015 100644
--- a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
+++ b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
@@ -40,6 +40,7 @@ const PengajuanTempo = () => {
   const { form, errors, validate, updateForm } = usePengajuanTempoStore();
   const { control, watch, setValue } = useForm();
   const auth = useAuth();
+  console.log('auth', auth);
   const router = useRouter();
   const [BannerTempo, setBannerTempo] = useState();
   const { formDokumen, errorsDokumen, validateDokumen, updateFormDokumen } =
-- 
cgit v1.2.3

