From fb04f8d327aafa2eb5440ade12919e1f07c2c1c1 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Fri, 10 Jan 2025 16:34:43 +0700
Subject: <iman> update merchant

---
 src/lib/merchant/components/SyaratDagang.jsx | 190 +++++++--------------------
 1 file changed, 49 insertions(+), 141 deletions(-)

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

diff --git a/src/lib/merchant/components/SyaratDagang.jsx b/src/lib/merchant/components/SyaratDagang.jsx
index c09db65d..36c6e0a9 100644
--- a/src/lib/merchant/components/SyaratDagang.jsx
+++ b/src/lib/merchant/components/SyaratDagang.jsx
@@ -24,7 +24,13 @@ 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 SyaratDagang = () => {
+const SyaratDagang = ({ handleIsError }) => {
+  const isError = (value) => {
+    // Logika menentukan error
+    const result = value ? true : false;
+    handleIsError(result); // Panggil handleIsError dari Merchant
+    return result;
+  };
   const {
     register,
     handleSubmit,
@@ -302,89 +308,35 @@ const SyaratDagang = () => {
     }
   }, [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,
-      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,
-      subDistrict: values.subDistrict,
-      zip: values.zip,
-      bank_name: values.bank,
-      rekening_name: values.rekening,
-      account_number: values.accountNumber,
-      email_company: values.email,
-      email_sales: values.emailSales,
-      email_finance: values.emailFinance,
-      phone: values.phone,
-      mobile: values.mobile,
-      harga_tayang: values.hargaTayang,
-      description:
-        'Nama Perusahaan : ' +
-        values.company +
-        ' \r\n  Alamat  : ' +
-        values.address +
-        ' \r\n  Kota  : ' +
-        values.city +
-        ' \r\n  Telepon: ' +
-        values.phone +
-        ' \r\n  Email  : ' +
-        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 : '',
+      is_kembali_barang: values.isKembaliBarang,
+      text_return: values.textReturn,
+      tenggat_waktu: values.tenggatWaktu,
+      custom_tenggat_waktu: values.customTenggatWaktu,
+      sertifikat_produk: values.sertifikatProduk,
+      custom_sertifikat_produk: values.customSertifikatProduk,
+      tempo_garansi: values.tempoGaransi,
+      explain_garansi: values.explainGaransi,
+      is_order_quantity: values.isOrderQuantity,
+      minimum_pembelian: values.minimumPembelian,
     };
+    isError(true);
+    toast.dismiss(toastId);
+    toast.success('Berhasil menambahkan data');
     // 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 = () => {
@@ -491,10 +443,9 @@ const SyaratDagang = () => {
                         </Radio>
                       </Stack>
                     </RadioGroup>
-                  </div>
-
-                  <div className='text-caption-2 text-danger-500 mt-1'>
-                    {errors.isKembaliBarang?.message}
+                    <div className='text-caption-2 text-danger-500 mt-1'>
+                      {errors.isKembaliBarang?.message}
+                    </div>
                   </div>
                 </div>
               </div>
@@ -531,10 +482,9 @@ const SyaratDagang = () => {
                         </div>
                       </Stack>
                     </RadioGroup>
-                  </div>
-
-                  <div className='text-caption-2 text-danger-500 mt-1'>
-                    {errors.tenggatWaktu?.message}
+                    <div className='text-caption-2 text-danger-500 mt-1'>
+                      {errors.tenggatWaktu?.message}
+                    </div>
                   </div>
                 </div>
               </div>
@@ -690,10 +640,9 @@ const SyaratDagang = () => {
                         </Radio>
                       </Stack>
                     </RadioGroup>
-                  </div>
-
-                  <div className='text-caption-2 text-danger-500 mt-1'>
-                    {errors.isOrderQuantity?.message}
+                    <div className='text-caption-2 text-danger-500 mt-1'>
+                      {errors.isOrderQuantity?.message}
+                    </div>
                   </div>
                 </div>
               </div>
@@ -1371,60 +1320,19 @@ const SyaratDagang = () => {
   );
 };
 const validationSchema = Yup.object().shape({
-  tenggatWaktu: Yup.string().required('Harus di-isi'),
-  sertifikatProduk: Yup.string().required('Harus di-isi'),
-  merkDagang: Yup.string().required('Harus di-isi'),
-  tempoGaransi: Yup.string().required('Harus di-isi'),
+  isKembaliBarang: Yup.string().required('Harus di-pilih'),
+  tenggatWaktu: Yup.string().required('Harus di-pilih'),
+  sertifikatProduk: Yup.string().required('Harus di-pilih'),
+  tempoGaransi: Yup.string().required('Harus di-pilih'),
   explainGaransi: Yup.string().required('Harus di-isi'),
-  waktuPengiriman: Yup.string().required('Harus di-isi'),
-  terhitungSejak: Yup.string().required('Harus di-isi'),
-  pejabatName: Yup.string().required('Harus di-isi'),
-  PICName: Yup.string().required('Harus di-isi'),
-  PICPosition: Yup.string().required('Harus di-isi'),
-  email: Yup.string()
-    .email('Format harus seperti contoh@email.com')
-    .required('Harus di-isi'),
-  emailSales: Yup.string()
-    .email('Format harus seperti contoh@email.com')
-    .required('Harus di-isi'),
-  emailFinance: Yup.string()
-    .email('Format harus seperti contoh@email.com')
-    .required('Harus di-isi'),
-  phone: Yup.string().required('Harus di-isi'),
-  state: Yup.string().required('Harus dipilih'),
-  bisnisType: Yup.string().required('Harus dipilih'),
-  categoryPerusahaan: Yup.string().required('Harus dipilih'),
-  city: Yup.string().required('Harus dipilih'),
-  district: Yup.string().required('Harus dipilih'),
-  subDistrict: Yup.string().required('Harus dipilih'),
-  zip: Yup.string().required('Harus di-isi'),
-  bank: Yup.string().required('Harus di-isi'),
-  rekening: Yup.string().required('Harus di-isi'),
-  accountNumber: Yup.string().required('Harus di-isi'),
-  address: Yup.string().required('Harus di-isi'),
-  mobile: Yup.string().required('Harus di-isi'),
-  npwp: Yup.mixed().required('File is required'),
-  pricelist: Yup.mixed().required('File is required'),
+  isOrderQuantity: Yup.string().required('Harus di-isi'),
 });
 const defaultValues = {
-  company: '',
-  pejabatName: '',
-  PICName: '',
-  PICPosition: '',
-  email: '',
-  emailSales: '',
-  emailFinance: '',
-  phone: '',
-  state: '',
-  city: '',
-  district: '',
-  subDistrict: '',
-  zip: '',
-  bank: '',
-  rekening: '',
-  accountNumber: '',
-  address: '',
-  mobile: '',
+  isKembaliBarang: '',
+  tenggatWaktu: '',
+  sertifikatProduk: '',
+  explainGaransi: '',
+  isOrderQuantity: '',
 };
 
 export default SyaratDagang;
-- 
cgit v1.2.3

