From c42e3256fa8f059a937629b1e44a2dc50d736928 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 10 Jan 2025 13:33:16 +0700 Subject: 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 ? ( - - ) : ( + {zips.length < 0 ? ( // Jika zips kosong, tampilkan input manual { className='form-input' disabled={!watchsubDistrict} /> + ) : ( + )} )} @@ -748,26 +738,6 @@ const CreateMerchant = () => { -
-
- -
-
- -
- {errors.hargaTayang?.message} -
-
-
-
@@ -856,352 +826,6 @@ const CreateMerchant = () => {
-
-
- - - Pastikan dokumen yang anda upload sudah benar - -
-
-
- - { - handleFileChange(e); // Untuk update UI (opsional) - }} - aria-invalid={errors.npwp?.message} - /> - - {fileNames.npwp} - -
- - Format: pdf, jpeg, jpg, png. max file size 2MB - - -
- {errors.npwp?.message} -
-
-
-
-
-
- - - Pastikan dokumen yang anda upload sudah benar - -
-
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' - > - - -

Lihat Contoh

-
-
-
-
- - - - {fileNames.sppkp} - -
- - Format: pdf, jpeg, jpg, png. max file size 2MB - - -
- {errors.sppkp?.message} -
-
-
- -
-
- - - Pastikan dokumen yang anda upload sudah benar - -
-
-
- - - - {fileNames.dokumenKtpDirut} - -
- - Format: pdf, jpeg, jpg, png. max file size 2MB - - -
- {errors.dokumenKtpDirut?.message} -
-
-
- -
-
- - - Pastikan dokumen yang anda upload sudah benar - -
-
-
- - - - {fileNames.kartuNama} - -
- - Format: pdf, jpeg, jpg, png. max file size 2MB - - -
- {errors.kartuNama?.message} -
-
-
- -
-
-
- - - Wajib diisi jika nomor rekening berbeda dengan nama - perusahaan - -
- -

Download Template

-
-
-
-
- - - - {fileNames.suratPernyataan} - -
- - Format: pdf, jpeg, jpg, png. max file size 2MB - - -
- {errors.suratPernyataan?.message} -
-
-
-
-
- - - Pastikan dokumen yang anda upload sudah benar - -
-
-
- - - - {fileNames.fotoKantor} - -
- - Format: pdf, jpeg, jpg, png. max file size 2MB - - -
- {errors.fotoKantor?.message} -
-
-
-
-
- - - Pastikan dokumen yang anda upload sudah benar - -
-
-
- - - - {fileNames.dataProduk} - -
- - Format: pdf, jpeg, jpg, png. max file size 2MB - - -
- {errors.fotoKantor?.message} -
-
-
-
-
- - - Pastikan dokumen yang anda upload sudah benar - -
-
-
- - - - {fileNames.pricelist} - -
- - Format: pdf, jpeg, jpg, png. max file size 2MB - - -
- {errors.pricelist?.message} -
-
-
{/*