From 7eb1cec305b015a6e4bffbd19a0ac8946ec41797 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Mon, 30 Dec 2024 14:08:31 +0700
Subject: <iman> update merchant

---
 src/lib/form/components/Merchant.jsx | 99 +++++++++++++++++-------------------
 1 file changed, 48 insertions(+), 51 deletions(-)

(limited to 'src/lib/form/components/Merchant.jsx')

diff --git a/src/lib/form/components/Merchant.jsx b/src/lib/form/components/Merchant.jsx
index 4dd50983..ce0b5430 100644
--- a/src/lib/form/components/Merchant.jsx
+++ b/src/lib/form/components/Merchant.jsx
@@ -82,8 +82,9 @@ const CreateMerchant = () => {
   useEffect(() => {
     const loadProfile = async () => {
       try {
-        const dataProfile = await addressApi({ id: auth.parentId });
-        console.log('dataProfile', dataProfile);
+        const dataProfile = await addressApi({
+          id: auth.parentId ? auth.parentId : auth.partnerId,
+        });
         setValue('company', dataProfile?.name);
         setValue('address', dataProfile?.alamatBisnis);
         setValue('state', parseInt(dataProfile.stateId.id));
@@ -96,9 +97,7 @@ const CreateMerchant = () => {
       }
     };
 
-    if (auth?.parentId) {
-      loadProfile();
-    }
+    loadProfile();
   }, [auth?.parentId, setValue]);
 
   useEffect(() => {
@@ -218,7 +217,6 @@ const CreateMerchant = () => {
       loadZip();
     }
   }, [watchsubDistrict, setValue, subDistricts]);
-
   const onSubmitHandler = async (values) => {
     const dokumenKtpDirut = document.getElementById('dokumenKtpDirut').files[0];
     const kartuNama = document.getElementById('kartuNama').files[0];
@@ -238,12 +236,11 @@ const CreateMerchant = () => {
       toast.error('Foto Gudang / Kantor Bagian Depan wajib di tambahkan');
       return;
     }
-    console.log('Submitted Values:', values);
-    console.log('values.npwp[0]:', values.npwp[0]);
-    console.log('npwp:', npwp);
+    const toastId = toast.loading('Mengirimkan formulir merchant...');
     const data = {
       ...values,
-      name: 'Form Merchant - ' + values.company,
+      name_merchant: 'Form Merchant - ' + values.company,
+      partner_id: auth.partnerId,
       address: values.address,
       state: values.state,
       city: values.city,
@@ -255,7 +252,7 @@ const CreateMerchant = () => {
       account_number: values.accountNumber,
       email_company: values.email,
       email_sales: values.emailSales,
-      email_finnance: values.emailFinance,
+      email_finance: values.emailFinance,
       phone: values.phone,
       mobile: values.mobile,
       description:
@@ -271,12 +268,8 @@ const CreateMerchant = () => {
         values.phone +
         ' \r\n  Email  : ' +
         values.email +
-        ' \r\n  Website : ' +
-        values.website +
         ' \r\n No Hp : ' +
-        values.mobile +
-        'Keterangan  : ' +
-        values.description,
+        values.mobile,
       file_dokumenKtpDirut: dokumenKtpDirut
         ? await getFileBase64(dokumenKtpDirut)
         : '',
@@ -291,10 +284,15 @@ const CreateMerchant = () => {
     // const formData = new FormData();
     // formData.append('npwp', values.npwp[0]);
     const create_leads = await createMerchantApi({ data });
-    // if (create_leads) {
-    //   toast.success('Berhasil menambahkan data');
-    //   reset();
-    // }
+    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 = () => {
@@ -308,8 +306,8 @@ const CreateMerchant = () => {
 
   const handleFileChange = (event) => {
     const file = event.target.files[0];
-    if (file.size > 2000000) {
-      toast.error('Maksimal ukuran file adalah 2MB');
+    if (file.size > 1000000) {
+      toast.error('Maksimal ukuran file adalah 1MB');
       event.target.value = '';
       return;
     }
@@ -320,7 +318,6 @@ const CreateMerchant = () => {
     }));
   };
 
-  console.log('errors', errors);
   return (
     <>
       <BottomPopup
@@ -676,7 +673,7 @@ const CreateMerchant = () => {
                       {...register('dokumenKtpDirut')}
                       type='file'
                       className='form-input hidden'
-                      accept='.pdf'
+                      accept='application/pdf'
                       id='dokumenKtpDirut'
                       onChange={handleFileChange}
                       aria-invalid={errors.dokumenKtpDirut?.message}
@@ -686,7 +683,7 @@ const CreateMerchant = () => {
                     </span>
                   </div>
                   <span className='text-xs opacity-60 text-red-500'>
-                    Format: pdf, jpeg, jpg, png. max file size 2MB
+                    Format: pdf. max file size 1MB
                   </span>
 
                   <div className='text-caption-2 text-danger-500 mt-1'>
@@ -716,7 +713,7 @@ const CreateMerchant = () => {
                       {...register('kartuNama')}
                       type='file'
                       className='form-input hidden'
-                      accept='.pdf'
+                      accept='application/pdf'
                       id='kartuNama'
                       onChange={handleFileChange}
                       aria-invalid={errors.kartuNama?.message}
@@ -726,7 +723,7 @@ const CreateMerchant = () => {
                     </span>
                   </div>
                   <span className='text-xs opacity-60 text-red-500'>
-                    Format: pdf, jpeg, jpg, png. max file size 2MB
+                    Format: pdf. max file size 1MB
                   </span>
 
                   <div className='text-caption-2 text-danger-500 mt-1'>
@@ -754,7 +751,7 @@ const CreateMerchant = () => {
                       {...register('npwp')}
                       type='file'
                       className='form-input hidden'
-                      accept='.pdf'
+                      accept='application/pdf'
                       id='npwp'
                       onChange={(e) => {
                         handleFileChange(e); // Untuk update UI (opsional)
@@ -766,7 +763,7 @@ const CreateMerchant = () => {
                     </span>
                   </div>
                   <span className='text-xs opacity-60 text-red-500'>
-                    Format: pdf, jpeg, jpg, png. max file size 2MB
+                    Format: pdf. max file size 1MB
                   </span>
 
                   <div className='text-caption-2 text-danger-500 mt-1'>
@@ -805,7 +802,7 @@ const CreateMerchant = () => {
                       {...register('sppkp')}
                       type='file'
                       className='form-input hidden'
-                      accept='.pdf'
+                      accept='application/pdf'
                       id='sppkp'
                       onChange={handleFileChange}
                       aria-invalid={errors.sppkp?.message}
@@ -815,7 +812,7 @@ const CreateMerchant = () => {
                     </span>
                   </div>
                   <span className='text-xs opacity-60 text-red-500'>
-                    Format: pdf, jpeg, jpg, png. max file size 2MB
+                    Format: pdf. max file size 1MB
                   </span>
 
                   <div className='text-caption-2 text-danger-500 mt-1'>
@@ -855,7 +852,7 @@ const CreateMerchant = () => {
                       {...register('suratPernyataan')}
                       type='file'
                       className='form-input hidden'
-                      accept='.pdf'
+                      accept='application/pdf'
                       id='suratPernyataan'
                       onChange={handleFileChange}
                       aria-invalid={errors.suratPernyataan?.message}
@@ -865,7 +862,7 @@ const CreateMerchant = () => {
                     </span>
                   </div>
                   <span className='text-xs opacity-60 text-red-500'>
-                    Format: pdf, jpeg, jpg, png. max file size 2MB
+                    Format: pdf. max file size 1MB
                   </span>
 
                   <div className='text-caption-2 text-danger-500 mt-1'>
@@ -894,7 +891,7 @@ const CreateMerchant = () => {
                       {...register('fotoKantor')}
                       type='file'
                       className='form-input hidden'
-                      accept='.pdf,.png,.jpg,.jpeg'
+                      accept='.png,.jpg,.jpeg'
                       id='fotoKantor'
                       onChange={handleFileChange}
                       aria-invalid={errors.fotoKantor?.message}
@@ -904,7 +901,7 @@ const CreateMerchant = () => {
                     </span>
                   </div>
                   <span className='text-xs opacity-60 text-red-500'>
-                    Format: pdf, jpeg, jpg, png. max file size 2MB
+                    Format: jpeg, jpg, png. max file size 1MB
                   </span>
 
                   <div className='text-caption-2 text-danger-500 mt-1'>
@@ -913,12 +910,12 @@ const CreateMerchant = () => {
                 </div>
               </div>
               <div className=''>
-                <div>
+                {/* <div>
                   <ReCAPTCHA
                     ref={recaptchaRef}
                     sitekey={process.env.NEXT_PUBLIC_RECAPTCHA_GOOGLE}
                   />
-                </div>
+                </div> */}
               </div>
               <div className='flex justify-end'>
                 {/* <Button
@@ -1238,7 +1235,7 @@ const CreateMerchant = () => {
                     {...register('dokumenKtpDirut')}
                     type='file'
                     className='form-input hidden'
-                    accept='.pdf'
+                    accept='application/pdf'
                     id='dokumenKtpDirut'
                     onChange={handleFileChange}
                     aria-invalid={errors.dokumenKtpDirut?.message}
@@ -1248,7 +1245,7 @@ const CreateMerchant = () => {
                   </span>
                 </div>
                 <span className='text-xs opacity-60 text-red-500'>
-                  Format: pdf, jpeg, jpg, png. max file size 2MB
+                  Format: pdf. max file size 1MB
                 </span>
 
                 <div className='text-caption-2 text-danger-500 mt-1'>
@@ -1271,7 +1268,7 @@ const CreateMerchant = () => {
                     {...register('kartuNama')}
                     type='file'
                     className='form-input hidden'
-                    accept='.pdf'
+                    accept='application/pdf'
                     id='kartuNama'
                     onChange={handleFileChange}
                     aria-invalid={errors.kartuNama?.message}
@@ -1281,7 +1278,7 @@ const CreateMerchant = () => {
                   </span>
                 </div>
                 <span className='text-xs opacity-60 text-red-500'>
-                  Format: pdf, jpeg, jpg, png. max file size 2MB
+                  Format: pdf. max file size 1MB
                 </span>
 
                 <div className='text-caption-2 text-danger-500 mt-1'>
@@ -1302,7 +1299,7 @@ const CreateMerchant = () => {
                     {...register('npwp')}
                     type='file'
                     className='form-input hidden'
-                    accept='.pdf'
+                    accept='application/pdf'
                     id='npwp'
                     onChange={(e) => {
                       handleFileChange(e); // Untuk update UI (opsional)
@@ -1314,7 +1311,7 @@ const CreateMerchant = () => {
                   </span>
                 </div>
                 <span className='text-xs opacity-60 text-red-500'>
-                  Format: pdf, jpeg, jpg, png. max file size 2MB
+                  Format: pdf. max file size 1MB
                 </span>
 
                 <div className='text-caption-2 text-danger-500 mt-1'>
@@ -1346,7 +1343,7 @@ const CreateMerchant = () => {
                     {...register('sppkp')}
                     type='file'
                     className='form-input hidden'
-                    accept='.pdf'
+                    accept='application/pdf'
                     id='sppkp'
                     onChange={handleFileChange}
                     aria-invalid={errors.sppkp?.message}
@@ -1356,7 +1353,7 @@ const CreateMerchant = () => {
                   </span>
                 </div>
                 <span className='text-xs opacity-60 text-red-500'>
-                  Format: pdf, jpeg, jpg, png. max file size 2MB
+                  Format: pdf. max file size 1MB
                 </span>
 
                 <div className='text-caption-2 text-danger-500 mt-1'>
@@ -1391,7 +1388,7 @@ const CreateMerchant = () => {
                     {...register('suratPernyataan')}
                     type='file'
                     className='form-input hidden'
-                    accept='.pdf'
+                    accept='application/pdf'
                     id='suratPernyataan'
                     onChange={handleFileChange}
                     aria-invalid={errors.suratPernyataan?.message}
@@ -1401,7 +1398,7 @@ const CreateMerchant = () => {
                   </span>
                 </div>
                 <span className='text-xs opacity-60 text-red-500'>
-                  Format: pdf, jpeg, jpg, png. max file size 2MB
+                  Format: pdf. max file size 1MB
                 </span>
 
                 <div className='text-caption-2 text-danger-500 mt-1'>
@@ -1423,7 +1420,7 @@ const CreateMerchant = () => {
                     {...register('fotoKantor')}
                     type='file'
                     className='form-input hidden'
-                    accept='.pdf,.png,.jpg,.jpeg'
+                    accept='.png,.jpg,.jpeg'
                     id='fotoKantor'
                     onChange={handleFileChange}
                     aria-invalid={errors.fotoKantor?.message}
@@ -1433,7 +1430,7 @@ const CreateMerchant = () => {
                   </span>
                 </div>
                 <span className='text-xs opacity-60 text-red-500'>
-                  Format: pdf, jpeg, jpg, png. max file size 2MB
+                  Format: jpeg, jpg, png. max file size 1MB
                 </span>
 
                 <div className='text-caption-2 text-danger-500 mt-1'>
@@ -1441,12 +1438,12 @@ const CreateMerchant = () => {
                 </div>
               </div>
               <div className=''>
-                <div>
+                {/* <div>
                   <ReCAPTCHA
                     ref={recaptchaRef}
                     sitekey={process.env.NEXT_PUBLIC_RECAPTCHA_GOOGLE}
                   />
-                </div>
+                </div> */}
               </div>
               <div className='flex justify-end'>
                 <Button
-- 
cgit v1.2.3

