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

---
 .../merchant/components/InformasiPerusahaan.jsx    | 500 +++------------------
 1 file changed, 61 insertions(+), 439 deletions(-)

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

diff --git a/src/lib/merchant/components/InformasiPerusahaan.jsx b/src/lib/merchant/components/InformasiPerusahaan.jsx
index 87d8ff9b..bf968aad 100644
--- a/src/lib/merchant/components/InformasiPerusahaan.jsx
+++ b/src/lib/merchant/components/InformasiPerusahaan.jsx
@@ -24,7 +24,17 @@ 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 CreateMerchant = () => {
+
+const CreateMerchant = ({ handleIsError }) => {
+  const isError = (value) => {
+    // Logika menentukan error
+    const result = value ? true : false;
+    handleIsError(result); // Panggil handleIsError dari Merchant
+    return result;
+  };
+  // React.useEffect(() => {
+  //   handleIsError(isError());
+  // }, [handleIsError]);
   const {
     register,
     handleSubmit,
@@ -38,6 +48,8 @@ const CreateMerchant = () => {
     resolver: yupResolver(validationSchema),
     defaultValues,
   });
+  console.log('errors', errors);
+  console.log('errors length', errors.length);
   const list_unit = [
     {
       value: 'Manufacturing',
@@ -75,6 +87,13 @@ const CreateMerchant = () => {
   const [BannerMerchant, setBannerMerchant] = useState();
   const [isPkp, setIsPkp] = useState(false);
 
+  useEffect(() => {
+    window.scrollTo({
+      top: 0,
+      behavior: 'smooth',
+    });
+  }, []);
+
   const recaptchaRef = useRef(null);
   const router = useRouter();
 
@@ -239,39 +258,14 @@ const CreateMerchant = () => {
     }
   }, [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;
-    }
+    console.log('data yang mau dikirim', values);
     const toastId = toast.loading('Mengirimkan formulir merchant...');
     const data = {
       ...values,
       name_merchant: 'Form Merchant - ' + values.company,
+      pejabat_name: values.pejabatName,
       pic_merchant: values.PICName,
+      pic_position: values.PICPosition,
       partner_id: auth.partnerId,
       address: values.address,
       state: values.state,
@@ -287,7 +281,8 @@ const CreateMerchant = () => {
       email_finance: values.emailFinance,
       phone: values.phone,
       mobile: values.mobile,
-      harga_tayang: values.hargaTayang,
+      bisnis_type: values.bisnisType,
+      category_perusahaan: values.categoryPerusahaan,
       description:
         'Nama Perusahaan : ' +
         values.company +
@@ -301,27 +296,22 @@ const CreateMerchant = () => {
         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 : '',
     };
+    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 = () => {
@@ -576,14 +566,7 @@ const CreateMerchant = () => {
                         render={(props) => (
                           <>
                             {/* Jika zips tidak kosong, tampilkan dropdown */}
-                            {zips.length > 0 ? (
-                              <HookFormSelect
-                                {...props}
-                                options={zips}
-                                disabled={!watchsubDistrict}
-                                placeholder='Zip'
-                              />
-                            ) : (
+                            {zips.length < 0 ? (
                               // Jika zips kosong, tampilkan input manual
                               <input
                                 {...register('zip')}
@@ -592,6 +575,13 @@ const CreateMerchant = () => {
                                 className='form-input'
                                 disabled={!watchsubDistrict}
                               />
+                            ) : (
+                              <HookFormSelect
+                                {...props}
+                                options={zips}
+                                disabled={!watchsubDistrict}
+                                placeholder='Zip'
+                              />
                             )}
                           </>
                         )}
@@ -748,26 +738,6 @@ const CreateMerchant = () => {
                 </div>
               </div>
 
-              <div className='w-full flex flex-row'>
-                <div className='w-2/5'>
-                  <label className='form-label  text-nowrap'>
-                    Harga Tayang (HET){' '}
-                    <span className=' opacity-60'>(Opsional)</span>
-                  </label>
-                </div>
-                <div className='w-3/5'>
-                  <input
-                    {...register('hargaTayang')}
-                    placeholder='Masukkan Harga Tayang (HET)'
-                    type='text'
-                    className='form-input'
-                  />
-                  <div className='text-caption-2 text-danger-500 mt-1'>
-                    {errors.hargaTayang?.message}
-                  </div>
-                </div>
-              </div>
-
               <div className='flex flex-row  justify-between items-center'>
                 <div className='w-2/5'>
                   <label className='form-label text-nowrap'>Tipe Bisnis</label>
@@ -856,352 +826,6 @@ const CreateMerchant = () => {
                 </div>
               </div>
 
-              <div className='w-full flex flex-row'>
-                <div className='w-2/5'>
-                  <label className='form-label  text-nowrap'>
-                    NPWP{' '}
-                    {!isPkp && <span className=' opacity-60'>(Opsional)</span>}
-                  </label>
-                  <span className='opacity-65 text-xs'>
-                    Pastikan dokumen yang anda upload sudah benar
-                  </span>
-                </div>
-                <div className='w-3/5 flex flex-col justify-start items-start'>
-                  <div className='flex flex-row items-start justify-start gap-2'>
-                    <label
-                      htmlFor='npwp'
-                      className='cursor-pointer min-w-40 text-center bg-gray-200 hover:bg-gray-300 text-gray-700 py-2 px-4 rounded'
-                    >
-                      {fileNames.npwp ? 'Ubah Dokumen' : 'Upload Dokumen'}
-                    </label>
-                    <input
-                      {...register('npwp')}
-                      type='file'
-                      className='form-input hidden'
-                      accept='.pdf,.png,.jpg,.jpeg'
-                      id='npwp'
-                      onChange={(e) => {
-                        handleFileChange(e); // Untuk update UI (opsional)
-                      }}
-                      aria-invalid={errors.npwp?.message}
-                    />
-                    <span className='mt-2 text-gray-600 line-clamp-2'>
-                      {fileNames.npwp}
-                    </span>
-                  </div>
-                  <span className='text-xs opacity-60 text-red-500'>
-                    Format: pdf, jpeg, jpg, png. max file size 2MB
-                  </span>
-
-                  <div className='text-caption-2 text-danger-500 mt-1'>
-                    {errors.npwp?.message}
-                  </div>
-                </div>
-              </div>
-              <div className='w-full flex flex-row items-start'>
-                <div className='w-2/5 flex flex-row justify-between items-center'>
-                  <div>
-                    <label className='form-label  text-nowrap'>
-                      SPPKP{' '}
-                      {!isPkp && (
-                        <span className=' opacity-60'>(Opsional)</span>
-                      )}
-                    </label>
-                    <span className='opacity-65 text-xs'>
-                      Pastikan dokumen yang anda upload sudah benar
-                    </span>
-                  </div>
-                  <div
-                    onClick={() => setIsExample(!isExample)}
-                    className='h-fit mr-8  rounded text-white p-2 flex flex-row items-center bg-red-500 hover:cursor-pointer hover:bg-red-400'
-                  >
-                    <EyeIcon className={`w-4 mr-2 `} />
-
-                    <p className='font-light text-xs '>Lihat Contoh</p>
-                  </div>
-                </div>
-                <div className='w-3/5 flex flex-col justify-between items-start'>
-                  <div className='flex flex-row items-start justify-start gap-2'>
-                    <label
-                      htmlFor='sppkp'
-                      className='cursor-pointer min-w-40 text-center bg-gray-200 hover:bg-gray-300 text-gray-700 py-2 px-4 rounded'
-                    >
-                      {fileNames.sppkp ? 'Ubah Dokumen' : 'Upload Dokumen'}
-                    </label>
-                    <input
-                      {...register('sppkp')}
-                      type='file'
-                      className='form-input hidden'
-                      accept='.pdf,.png,.jpg,.jpeg'
-                      id='sppkp'
-                      onChange={handleFileChange}
-                      aria-invalid={errors.sppkp?.message}
-                    />
-                    <span className='mt-2 text-gray-600 line-clamp-2'>
-                      {fileNames.sppkp}
-                    </span>
-                  </div>
-                  <span className='text-xs opacity-60 text-red-500'>
-                    Format: pdf, jpeg, jpg, png. max file size 2MB
-                  </span>
-
-                  <div className='text-caption-2 text-danger-500 mt-1'>
-                    {errors.sppkp?.message}
-                  </div>
-                </div>
-              </div>
-
-              <div className='w-full flex flex-row'>
-                <div className='w-2/5'>
-                  <label className='form-label  text-nowrap'>
-                    KTP Dirut/Direktur{' '}
-                    {isPkp && <span className=' opacity-60'>(Opsional)</span>}
-                  </label>
-                  <span className='opacity-65 text-xs'>
-                    Pastikan dokumen yang anda upload sudah benar
-                  </span>
-                </div>
-                <div className='w-3/5 flex flex-col justify-start items-start'>
-                  <div className='flex flex-row items-start justify-start gap-2'>
-                    <label
-                      htmlFor='dokumenKtpDirut'
-                      className='cursor-pointer min-w-40 text-center bg-gray-200 hover:bg-gray-300 text-gray-700 py-2 px-4 rounded'
-                    >
-                      {fileNames.dokumenKtpDirut
-                        ? 'Ubah Dokumen'
-                        : 'Upload Dokumen'}
-                    </label>
-                    <input
-                      {...register('dokumenKtpDirut')}
-                      type='file'
-                      className='form-input hidden'
-                      accept='.pdf,.png,.jpg,.jpeg'
-                      id='dokumenKtpDirut'
-                      onChange={handleFileChange}
-                      aria-invalid={errors.dokumenKtpDirut?.message}
-                    />
-                    <span className='mt-2 text-gray-600 line-clamp-2'>
-                      {fileNames.dokumenKtpDirut}
-                    </span>
-                  </div>
-                  <span className='text-xs opacity-60 text-red-500'>
-                    Format: pdf, jpeg, jpg, png. max file size 2MB
-                  </span>
-
-                  <div className='text-caption-2 text-danger-500 mt-1'>
-                    {errors.dokumenKtpDirut?.message}
-                  </div>
-                </div>
-              </div>
-
-              <div className='w-full flex flex-row'>
-                <div className='w-2/5'>
-                  <label className='form-label  text-nowrap'>
-                    Kartu Nama <span className=' opacity-60'>(Opsional)</span>{' '}
-                  </label>
-                  <span className='opacity-65 text-xs'>
-                    Pastikan dokumen yang anda upload sudah benar
-                  </span>
-                </div>
-                <div className='w-3/5 flex flex-col justify-start items-start'>
-                  <div className='flex flex-row items-start justify-start gap-2'>
-                    <label
-                      htmlFor='kartuNama'
-                      className='cursor-pointer min-w-40 text-center bg-gray-200 hover:bg-gray-300 text-gray-700 py-2 px-4 rounded'
-                    >
-                      {fileNames.kartuNama ? 'Ubah Dokumen' : 'Upload Dokumen'}
-                    </label>
-                    <input
-                      {...register('kartuNama')}
-                      type='file'
-                      className='form-input hidden'
-                      accept='.pdf,.png,.jpg,.jpeg'
-                      id='kartuNama'
-                      onChange={handleFileChange}
-                      aria-invalid={errors.kartuNama?.message}
-                    />
-                    <span className='mt-2 text-gray-600 line-clamp-2'>
-                      {fileNames.kartuNama}
-                    </span>
-                  </div>
-                  <span className='text-xs opacity-60 text-red-500'>
-                    Format: pdf, jpeg, jpg, png. max file size 2MB
-                  </span>
-
-                  <div className='text-caption-2 text-danger-500 mt-1'>
-                    {errors.kartuNama?.message}
-                  </div>
-                </div>
-              </div>
-
-              <div className='w-full flex flex-row items-start '>
-                <div className='w-2/5 flex flex-row justify-between items-center '>
-                  <div>
-                    <label className='form-label  text-nowrap'>
-                      Surat Pernyataan Nomor Rekening{' '}
-                      <span className=' opacity-60'>(Opsional)</span>
-                    </label>
-                    <span className='opacity-65 text-xs'>
-                      Wajib diisi jika nomor rekening berbeda dengan nama
-                      perusahaan
-                    </span>
-                  </div>
-                  <a
-                    href='/file/Surat Pernyataan Nomor Rekening.docx'
-                    download='Surat Pernyataan Nomor Rekening.docx'
-                    className='h-fit mr-8 rounded text-white p-2 flex flex-row items-center bg-red-500 hover:cursor-pointer hover:bg-red-400'
-                  >
-                    <p className='font-light text-xs'>Download Template</p>
-                  </a>
-                </div>
-                <div className='w-3/5 flex flex-col justify-between items-start'>
-                  <div className='flex flex-row items-start justify-start gap-2'>
-                    <label
-                      htmlFor='suratPernyataan'
-                      className='cursor-pointer min-w-40 text-center bg-gray-200 hover:bg-gray-300 text-gray-700 py-2 px-4 rounded'
-                    >
-                      {fileNames.suratPernyataan
-                        ? 'Ubah Dokumen'
-                        : 'Upload Dokumen'}
-                    </label>
-                    <input
-                      {...register('suratPernyataan')}
-                      type='file'
-                      className='form-input hidden'
-                      accept='.pdf,.png,.jpg,.jpeg'
-                      id='suratPernyataan'
-                      onChange={handleFileChange}
-                      aria-invalid={errors.suratPernyataan?.message}
-                    />
-                    <span className='mt-2 text-gray-600 line-clamp-2'>
-                      {fileNames.suratPernyataan}
-                    </span>
-                  </div>
-                  <span className='text-xs opacity-60 text-red-500'>
-                    Format: pdf, jpeg, jpg, png. max file size 2MB
-                  </span>
-
-                  <div className='text-caption-2 text-danger-500 mt-1'>
-                    {errors.suratPernyataan?.message}
-                  </div>
-                </div>
-              </div>
-              <div className='w-full flex flex-row items-start '>
-                <div className='w-2/5 flex flex-col justify-start items-start '>
-                  <label className='form-label  text-nowrap'>
-                    Foto Gudang / Kantor Bagian Depan
-                  </label>
-                  <span className='opacity-65 text-xs'>
-                    Pastikan dokumen yang anda upload sudah benar
-                  </span>
-                </div>
-                <div className='w-3/5 flex flex-col justify-between items-start'>
-                  <div className='flex flex-row items-start justify-start gap-2'>
-                    <label
-                      htmlFor='fotoKantor'
-                      className='cursor-pointer min-w-40 text-center bg-gray-200 hover:bg-gray-300 text-gray-700 py-2 px-4 rounded'
-                    >
-                      {fileNames.fotoKantor ? 'Ubah Dokumen' : 'Upload Dokumen'}
-                    </label>
-                    <input
-                      {...register('fotoKantor')}
-                      type='file'
-                      className='form-input hidden'
-                      accept='.pdf,.png,.jpg,.jpeg'
-                      id='fotoKantor'
-                      onChange={handleFileChange}
-                      aria-invalid={errors.fotoKantor?.message}
-                    />
-                    <span className='mt-2 text-gray-600 line-clamp-2'>
-                      {fileNames.fotoKantor}
-                    </span>
-                  </div>
-                  <span className='text-xs opacity-60 text-red-500'>
-                    Format: pdf, jpeg, jpg, png. max file size 2MB
-                  </span>
-
-                  <div className='text-caption-2 text-danger-500 mt-1'>
-                    {errors.fotoKantor?.message}
-                  </div>
-                </div>
-              </div>
-              <div className='w-full flex flex-row items-start '>
-                <div className='w-2/5 flex flex-col justify-start items-start '>
-                  <label className='form-label  text-nowrap'>
-                    Data Produk (Item Name, Gambar, Deskripsi){' '}
-                    <span className=' opacity-60'>(Opsional)</span>{' '}
-                  </label>
-                  <span className='opacity-65 text-xs'>
-                    Pastikan dokumen yang anda upload sudah benar
-                  </span>
-                </div>
-                <div className='w-3/5 flex flex-col justify-between items-start'>
-                  <div className='flex flex-row items-start justify-start gap-2'>
-                    <label
-                      htmlFor='dataProduk'
-                      className='cursor-pointer min-w-40 text-center bg-gray-200 hover:bg-gray-300 text-gray-700 py-2 px-4 rounded'
-                    >
-                      {fileNames.dataProduk ? 'Ubah Dokumen' : 'Upload Dokumen'}
-                    </label>
-                    <input
-                      {...register('dataProduk')}
-                      type='file'
-                      className='form-input hidden'
-                      accept='.pdf,.png,.jpg,.jpeg'
-                      id='dataProduk'
-                      onChange={handleFileChange}
-                      aria-invalid={errors.dataProduk?.message}
-                    />
-                    <span className='mt-2 text-gray-600 line-clamp-2'>
-                      {fileNames.dataProduk}
-                    </span>
-                  </div>
-                  <span className='text-xs opacity-60 text-red-500'>
-                    Format: pdf, jpeg, jpg, png. max file size 2MB
-                  </span>
-
-                  <div className='text-caption-2 text-danger-500 mt-1'>
-                    {errors.fotoKantor?.message}
-                  </div>
-                </div>
-              </div>
-              <div className='w-full flex flex-row items-start '>
-                <div className='w-2/5 flex flex-col justify-start items-start '>
-                  <label className='form-label  text-nowrap'>Pricelist</label>
-                  <span className='opacity-65 text-xs'>
-                    Pastikan dokumen yang anda upload sudah benar
-                  </span>
-                </div>
-                <div className='w-3/5 flex flex-col justify-between items-start'>
-                  <div className='flex flex-row items-start justify-start gap-2'>
-                    <label
-                      htmlFor='pricelist'
-                      className='cursor-pointer min-w-40 text-center bg-gray-200 hover:bg-gray-300 text-gray-700 py-2 px-4 rounded'
-                    >
-                      {fileNames.pricelist ? 'Ubah Dokumen' : 'Upload Dokumen'}
-                    </label>
-                    <input
-                      {...register('pricelist')}
-                      type='file'
-                      className='form-input hidden'
-                      accept='.pdf,.png,.jpg,.jpeg'
-                      id='pricelist'
-                      onChange={handleFileChange}
-                      aria-invalid={errors.pricelist?.message}
-                    />
-                    <span className='mt-2 text-gray-600 line-clamp-2'>
-                      {fileNames.pricelist}
-                    </span>
-                  </div>
-                  <span className='text-xs opacity-60 text-red-500'>
-                    Format: pdf, jpeg, jpg, png. max file size 2MB
-                  </span>
-
-                  <div className='text-caption-2 text-danger-500 mt-1'>
-                    {errors.pricelist?.message}
-                  </div>
-                </div>
-              </div>
               <div className=''>
                 {/* <div>
                   <ReCAPTCHA
@@ -1879,6 +1503,15 @@ const validationSchema = Yup.object().shape({
   pejabatName: Yup.string().required('Harus di-isi'),
   PICName: Yup.string().required('Harus di-isi'),
   PICPosition: Yup.string().required('Harus di-isi'),
+  address: Yup.string().required('Harus di-isi'),
+  state: 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'),
   email: Yup.string()
     .email('Format harus seperti contoh@email.com')
     .required('Harus di-isi'),
@@ -1889,39 +1522,28 @@ const validationSchema = Yup.object().shape({
     .email('Format harus seperti contoh@email.com')
     .required('Harus di-isi'),
   phone: Yup.string().required('Harus di-isi'),
-  state: Yup.string().required('Harus dipilih'),
+  mobile: Yup.string().required('Harus di-isi'),
   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'),
 });
 const defaultValues = {
   company: '',
   pejabatName: '',
   PICName: '',
   PICPosition: '',
-  email: '',
-  emailSales: '',
-  emailFinance: '',
-  phone: '',
+  address: '',
   state: '',
   city: '',
   district: '',
   subDistrict: '',
   zip: '',
+  email: '',
+  emailSales: '',
+  emailFinance: '',
   bank: '',
   rekening: '',
   accountNumber: '',
-  address: '',
+  phone: '',
   mobile: '',
 };
 
-- 
cgit v1.2.3

