From c42e3256fa8f059a937629b1e44a2dc50d736928 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Fri, 10 Jan 2025 13:33:16 +0700
Subject: <iman> update code

---
 src/lib/merchant/components/InformasiVendor.jsx | 109 ++++++++++++------------
 1 file changed, 55 insertions(+), 54 deletions(-)

(limited to 'src/lib/merchant/components/InformasiVendor.jsx')

diff --git a/src/lib/merchant/components/InformasiVendor.jsx b/src/lib/merchant/components/InformasiVendor.jsx
index b53bd52f..9aea7811 100644
--- a/src/lib/merchant/components/InformasiVendor.jsx
+++ b/src/lib/merchant/components/InformasiVendor.jsx
@@ -24,7 +24,14 @@ import MobileView from '@/core/components/views/MobileView';
 import DesktopView from '@/core/components/views/DesktopView';
 import getFileBase64 from '@/core/utils/getFileBase64';
 import odooApi from '~/libs/odooApi';
-const InformasiVendor = () => {
+import { formatValue } from 'react-currency-input-field';
+const InformasiVendor = ({ handleIsError }) => {
+  const isError = (value) => {
+    // Logika menentukan error
+    const result = value ? true : false;
+    handleIsError(result); // Panggil handleIsError dari Merchant
+    return result;
+  };
   const {
     register,
     handleSubmit,
@@ -125,6 +132,24 @@ const InformasiVendor = () => {
   const midIndex = Math.ceil(category_produk.length / 2);
   const firstColumn = category_produk.slice(0, midIndex);
   const secondColumn = category_produk.slice(midIndex);
+  const [kreditLimitFormat, setKreditLimitFormat] = useState();
+
+  const handleKreditLimitChange = (e) => {
+    let value = e.target.value;
+
+    // Hapus semua karakter non-numeric
+    value = value.replace(/[^\d]/g, '');
+
+    // Format angka sebagai Rupiah tanpa mengubah nilai sebenarnya
+    const formattedValue1 = formatValue({
+      value: value,
+      groupSeparator: '.',
+      decimalSeparator: ',',
+      prefix: 'Rp ',
+    });
+
+    setKreditLimitFormat(formattedValue1);
+  };
 
   const [selectedIds, setSelectedIds] = useState(
     watch('categoryProduk')
@@ -151,6 +176,13 @@ const InformasiVendor = () => {
     setValue('isPengajuanTempo', `${value}`);
   };
 
+  useEffect(() => {
+    window.scrollTo({
+      top: 0,
+      behavior: 'smooth',
+    });
+  }, []);
+
   useEffect(() => {
     const loadProfile = async () => {
       try {
@@ -295,41 +327,17 @@ const InformasiVendor = () => {
     }
   }, [watchsubDistrict, subDistricts]);
   const onSubmitHandler = async (values) => {
-    const npwp = DeatailFile.npwp;
-    const sppkp = DeatailFile.sppkp;
-    const dokumenKtpDirut = DeatailFile.dokumenKtpDirut;
-    const kartuNama = DeatailFile.kartuNama;
-    const suratPernyataan = DeatailFile.suratPernyataan;
-    const fotoKantor = DeatailFile.fotoKantor;
-    const dataProduk = DeatailFile.dataProduk;
-    const pricelist = DeatailFile.pricelist;
-    if (!npwp && isPkp) {
-      toast.error('NPWP wajib di tambahkan');
-      return;
-    }
-    if (!sppkp && isPkp) {
-      toast.error('SPPKP wajib di tambahkan');
-      return;
-    }
-    if (!dokumenKtpDirut && !isPkp) {
-      toast.error('KTP Dirut/Direktur wajib di tambahkan');
-      return;
-    }
-    if (!fotoKantor) {
-      toast.error('Foto Gudang / Kantor Bagian Depan wajib di tambahkan');
-      return;
-    }
-    if (!pricelist) {
-      toast.error('Pricelist wajib di tambahkan');
-      return;
-    }
     const toastId = toast.loading('Mengirimkan formulir merchant...');
     const data = {
       ...values,
+      harga_tayang: values.hargaTayang,
+      category_produk: values.categoryProduk,
+      merk_dagang: values.merkDagang,
+      is_pengajuan_tempo: values.isPengajuanTempo,
+      tempo_duration: values.tempoDuration,
+      kredit_limit: values.kreditLimit,
       name_merchant: 'Form Merchant - ' + values.company,
-      pic_merchant: values.PICName,
       partner_id: auth.partnerId,
-      address: values.address,
       state: values.state,
       city: values.city,
       district: values.district,
@@ -343,7 +351,6 @@ const InformasiVendor = () => {
       email_finance: values.emailFinance,
       phone: values.phone,
       mobile: values.mobile,
-      harga_tayang: values.hargaTayang,
       description:
         'Nama Perusahaan : ' +
         values.company +
@@ -357,27 +364,19 @@ const InformasiVendor = () => {
         values.email +
         ' \r\n No Hp : ' +
         values.mobile,
-      file_dokumenKtpDirut: dokumenKtpDirut ? dokumenKtpDirut : '',
-      file_kartuNama: kartuNama ? kartuNama : '',
-      file_npwp: npwp ? npwp : '',
-      file_sppkp: sppkp ? sppkp : '',
-      file_suratPernyataan: suratPernyataan ? suratPernyataan : '',
-      file_fotoKantor: fotoKantor ? fotoKantor : '',
-      file_dataProduk: dataProduk ? dataProduk : '',
-      file_pricelist: pricelist ? pricelist : '',
     };
     // const formData = new FormData();
     // formData.append('npwp', values.npwp[0]);
-    const create_leads = await createMerchantApi({ data });
-    if (create_leads) {
-      toast.dismiss(toastId);
-      toast.success('Berhasil menambahkan data');
-      reset();
-      router.push('/');
-    } else {
-      toast.dismiss(toastId);
-      toast.error('Gagal menambahkan data');
-    }
+    // const create_leads = await createMerchantApi({ data });
+    // if (create_leads) {
+    //   toast.dismiss(toastId);
+    //   toast.success('Berhasil menambahkan data');
+    //   reset();
+    //   router.push('/');
+    // } else {
+    //   toast.dismiss(toastId);
+    //   toast.error('Gagal menambahkan data');
+    // }
   };
 
   // const DownLoadSurat = () => {
@@ -423,6 +422,7 @@ const InformasiVendor = () => {
       [fieldName]: file ? file.name : '', // Tambahkan atau perbarui file di state
     }));
   };
+
   return (
     <>
       <BottomPopup
@@ -461,10 +461,10 @@ const InformasiVendor = () => {
                   </label>
                 </div>
                 <div className='w-3/5'>
-                  <input
+                  <textarea
                     {...register('hargaTayang')}
-                    placeholder='Masukkan Harga Tayang (HET)'
-                    type='text'
+                    placeholder='Jelaskan detail HET yang anda miliki'
+                    type='textarea'
                     className='form-input'
                   />
                   <div className='text-caption-2 text-danger-500 mt-1'>
@@ -605,7 +605,8 @@ const InformasiVendor = () => {
                 </div>
                 <div className='w-3/5'>
                   <input
-                    {...register('kreditLimit')}
+                    value={kreditLimitFormat}
+                    onChange={handleKreditLimitChange}
                     placeholder='Masukkan jumlah kredit limit'
                     type='text'
                     className='form-input'
-- 
cgit v1.2.3

