From c42e3256fa8f059a937629b1e44a2dc50d736928 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 10 Jan 2025 13:33:16 +0700 Subject: update code --- package.json | 1 + src/lib/merchant/components/Dokumen.jsx | 1476 ++++++++++++++++++++ .../merchant/components/InformasiPerusahaan.jsx | 500 +------ src/lib/merchant/components/InformasiVendor.jsx | 109 +- src/lib/merchant/components/Merchant.jsx | 57 +- src/lib/merchant/components/SyaratDagang.jsx | 188 ++- 6 files changed, 1788 insertions(+), 543 deletions(-) create mode 100644 src/lib/merchant/components/Dokumen.jsx diff --git a/package.json b/package.json index fd8dee81..4bf50620 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "next-seo": "^5.15.0", "nodemailer": "^6.8.0", "react": "18.2.0", + "react-currency-input-field": "^3.9.0", "react-dom": "18.2.0", "react-google-recaptcha": "^2.1.0", "react-hook-form": "^7.42.1", diff --git a/src/lib/merchant/components/Dokumen.jsx b/src/lib/merchant/components/Dokumen.jsx new file mode 100644 index 00000000..c03c5eec --- /dev/null +++ b/src/lib/merchant/components/Dokumen.jsx @@ -0,0 +1,1476 @@ +import HookFormSelect from '@/core/components/elements/Select/HookFormSelect'; +import cityApi from '@/lib/address/api/cityApi'; +import stateApi from '@/lib/address/api/stateApi.js'; +import districtApi from '@/lib/address/api/districtApi'; +import subDistrictApi from '@/lib/address/api/subDistrictApi'; +import { yupResolver } from '@hookform/resolvers/yup'; +import React, { useEffect, useRef, useState } from 'react'; +import ReCAPTCHA from 'react-google-recaptcha'; +import { Controller, useForm } from 'react-hook-form'; +import { toast } from 'react-hot-toast'; +import * as Yup from 'yup'; +import createMerchantApi from '../../form/api/createMerchantApi'; +import addressApi from '@/lib/address/api/addressApi'; +import PageContent from '@/lib/content/components/PageContent'; +import { useRouter } from 'next/router'; +import useAuth from '@/core/hooks/useAuth'; +import { Radio, RadioGroup, Stack, Divider, Button } from '@chakra-ui/react'; +import { EyeIcon } from '@heroicons/react/24/outline'; +import BottomPopup from '@/core/components/elements/Popup/BottomPopup'; +import Image from 'next/image'; +import ImageBanner from '~/components/ui/image'; +import { ChevronRightIcon } from '@heroicons/react/24/outline'; +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 Dokumen = () => { + const { + register, + handleSubmit, + formState: { errors }, + control, + reset, + watch, + setValue, + getValues, + } = useForm({ + resolver: yupResolver(validationSchema), + defaultValues, + }); + const list_unit = [ + { + value: 'Manufacturing', + label: 'Manufacturing', + }, + { + value: 'Hospitality', + label: 'Hospitality', + }, + { + value: 'Automotive', + label: 'Automotive', + }, + { + value: 'Retail', + label: 'Retail', + }, + { + value: 'Maining', + label: 'Maining', + }, + { + value: 'Lain - Lain', + label: 'Lain - Lain', + }, + ]; + const [state, setState] = useState([]); + const [cities, setCities] = useState([]); + const [districts, setDistricts] = useState([]); + const [fileNames, setFileNames] = useState({}); + const [DeatailFile, setDetailFile] = useState({}); + const [subDistricts, setSubDistricts] = useState([]); + const [zips, setZips] = useState([]); + const [isExample, setIsExample] = useState(false); + const [BannerMerchant, setBannerMerchant] = useState(); + const [isPkp, setIsPkp] = useState(false); + + const recaptchaRef = useRef(null); + const router = useRouter(); + + const auth = useAuth(); + if (auth == false) { + router.push(`/login?next=${encodeURIComponent('/daftar-merchant')}`); + } + const dataBisnisType = [ + { value: 1, label: 'PT' }, + { value: 2, label: 'CV' }, + { value: 3, label: 'Perorangan' }, + ]; + const dataCategoryPerusahaan = [ + { value: 1, label: 'Principal (Pemegang merk/Produsen)' }, + { value: 2, label: 'Sole Distributor (Distributor Tunggal)' }, + { value: 3, label: 'Authorized Distributor (Distributor Resmi)' }, + { value: 4, label: 'Importer (Pengimpor Barang)' }, + { value: 5, label: 'Wholesaler (Pedagang Besar)' }, + ]; + + useEffect(() => { + window.scrollTo({ + top: 0, + behavior: 'smooth', + }); + }, []); + + useEffect(() => { + const loadProfile = async () => { + try { + const dataProfile = await addressApi({ + id: auth.parentId ? auth.parentId : auth.partnerId, + }); + if (dataProfile.companyType == 'pkp') { + setIsPkp(true); + } + setValue('company', dataProfile?.name); + setValue('address', dataProfile?.alamatBisnis); + setValue('state', parseInt(dataProfile.stateId.id)); + setValue('city', parseInt(dataProfile.city.id)); + setValue('district', parseInt(dataProfile.district.id)); + setValue('subDistrict', parseInt(dataProfile.subDistrict.id)); + setValue('zip', parseInt(dataProfile.zip)); + } catch (error) { + console.error('Error loading profile:', error); + } + }; + + loadProfile(); + }, [auth?.parentId]); + + useEffect(() => { + const loadState = async () => { + let dataState = await stateApi({ tempo: false }); + dataState = dataState.map((state) => ({ + value: state.id, + label: state.name, + })); + setState(dataState); + }; + loadState(); + }, []); + + const watchState = watch('state'); + useEffect(() => { + if (auth == false) { + return; + } + if (watchState) { + // setValue('city', ''); + const loadCities = async () => { + let dataCities = await cityApi({ stateId: watchState }); + dataCities = dataCities?.map((city) => ({ + value: city.id, + label: city.name, + })); + setCities(dataCities); + }; + loadCities(); + } + }, [auth, watchState]); + + const watchCity = watch('city'); + + useEffect(() => { + if (watchCity) { + setValue('district', ''); + const loadDistricts = async () => { + let dataDistricts = await districtApi({ cityId: watchCity }); + dataDistricts = dataDistricts.map((district) => ({ + value: district.id, + label: district.name, + })); + setDistricts(dataDistricts); + }; + loadDistricts(); + } + }, [watchCity]); + + const watchDistrict = watch('district'); + useEffect(() => { + if (watchDistrict) { + setValue('subDistrict', ''); + const loadSubDistricts = async () => { + let dataSubDistricts = await subDistrictApi({ + districtId: watchDistrict, + }); + dataSubDistricts = dataSubDistricts.map((district) => ({ + value: district.id, + label: district.name, + })); + setSubDistricts(dataSubDistricts); + }; + loadSubDistricts(); + } + }, [watchDistrict]); + + const watchsubDistrict = watch('subDistrict'); + + useEffect(() => { + let kelurahan = ''; + let kecamatan = ''; + + if (watchDistrict) { + setValue('zip', ''); + for (const data in districts) { + if (districts[data].value == watchDistrict) { + kecamatan = districts[data].label.toLowerCase(); + } + } + } + + if (watchsubDistrict) { + for (const data in subDistricts) { + if (subDistricts[data].value == watchsubDistrict) { + kelurahan = subDistricts[data].label.toLowerCase(); + } + } + const loadZip = async () => { + const response = await fetch( + `https://alamat.thecloudalert.com/api/cari/index/?keyword=${kelurahan}` + ); + + let dataMasuk = []; // Array untuk menyimpan kode pos yang sudah diproses + + const result = await response.json(); + + // Filter dan map data + const dataZips = result.result + .filter((zip) => zip.kecamatan.toLowerCase() === kecamatan) // Filter berdasarkan kecamatan + .filter((zip) => { + // Pastikan zip.kodepos belum ada di dataMasuk + if (dataMasuk.includes(zip.kodepos)) { + return false; // Jika sudah ada, maka skip (tidak akan ditambahkan) + } else { + dataMasuk.push(zip.kodepos); // Tambahkan ke dataMasuk + return true; // Tambahkan zip ke hasil + } + }) + .map((zip) => ({ + value: parseInt(zip.kodepos), + label: zip.kodepos, + })); + + setZips(dataZips); // Set hasil ke state + }; + + loadZip(); + } + }, [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 : '', + }; + // 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 DownLoadSurat = () => { + // download surat dari /public/file/Surat Pernyataan Nomor Rekening.docx + // }; + + if (!auth) { + return; + } + // Tetap di bagian atas, tidak boleh ada kondisi sebelum hook + + const handleFileChange = async (event) => { + let fileBase64 = ''; + const file = event.target.files[0]; + + if (file.size > 500000) { + try { + const toastId = toast.loading('mencoba mengompresi file...'); + // Compress image file + const options = { + maxSizeMB: 0.5, // Target size in MB + maxWidthOrHeight: 1920, // Adjust as needed + useWebWorker: true, + }; + const compressedFile = await imageCompression(file, options); + toast.success('berhasil mengompresi file', { duration: 4000 }); + // Convert compressed file to Base64 + fileBase64 = await getFileBase64(compressedFile); + } catch (error) { + toast.error('Gagal mengompresi file', { duration: 4000 }); + } + } else { + // Convert file to Base64 + fileBase64 = await getFileBase64(file); + } + const fieldName = event.target.name; // Nama input file + setDetailFile((prev) => ({ + ...prev, + [fieldName]: file ? fileBase64 : '', // Tambahkan atau perbarui file di state + })); + setFileNames((prev) => ({ + ...prev, + [fieldName]: file ? file.name : '', // Tambahkan atau perbarui file di state + })); + }; + return ( + <> + setIsExample(false)} + > +
+ Contoh SPPKP +
+
+ +
+

+ Dokumen +

+ +
+
+
+
+ + + 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} +
+
+
+
+ {/*
+ +
*/} +
+
+ {/* */} +
+ +
+
+
+ +
+
+
+ +
+ {BannerMerchant && ( + + )} +

+ Form Merchant +

+
+ Lorem ipsum dolor sit amet consectetur. Commodo suspendisse at enim + magnis ut quisque rhoncus. Felis volutpat fringilla sollicitudin + ultricies. Enim non eget in lorem netus. Nisl pharetra accumsan diam + suspendisse. +
+

Informasi Perusahaan

+ +
+
+
+
+ + +
+ {errors.company?.message} +
+ + Isi detail perusahaan sesuai dengan nama yang terdaftar{' '} + +
+
+
+
+ + +
+ {errors.PICName?.message} +
+ + Isi dengan nama sales / penanggung jawab + +
+
+
+
+ + +
+ {errors.address?.message} +
+
+
+ ( + + )} + /> +
+ {errors.state?.message} +
+
+
+ ( + + )} + /> +
+ {errors.city?.message} +
+
+
+
+
+ ( + + )} + /> +
+ {errors.district?.message} +
+
+
+ ( + + )} + /> +
+ {errors.subDistrict?.message} +
+
+
+ ( + <> + {zips.length > 0 ? ( + + ) : ( + + )} + + )} + /> +
+ {errors.zip?.message} +
+
+
+
+ + Alamat sesuai dengan alamat perusahaan + +
+
+ +
+
+ +
+ {errors.bank?.message} +
+
+
+ +
+ {errors.rekening?.message} +
+
+
+ +
+ {errors.accountNumber?.message} +
+
+
+ + Isi detail data bank perusahaan anda + +
+
+ + +
+ {errors.email?.message} +
+ + Isi detail perusahaan sesuai dengan data yang terdaftar + +
+
+ + +
+ {errors.emailSales?.message} +
+ + Isi detail perusahaan sesuai dengan data yang terdaftar + +
+
+ + +
+ {errors.emailFinance?.message} +
+ + Isi detail perusahaan sesuai dengan data yang terdaftar + +
+
+ + +
+ {errors.phone?.message} +
+ + Isi detail perusahaan sesuai dengan data yang terdaftar + +
+
+ + +
+ {errors.mobile?.message} +
+ + Isi detail perusahaan sesuai dengan data yang terdaftar + +
+
+ + +
+ {errors.hargaTayang?.message} +
+
+ +
+ +
+ + { + 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} +
+
+
+
+ +
setIsExample(!isExample)} + className='h-fit 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} +
+
+ +
+ +
+ + + + {fileNames.dokumenKtpDirut} + +
+ + Format: pdf, jpeg, jpg, png. max file size 2MB + + +
+ {errors.dokumenKtpDirut?.message} +
+
+ +
+ +
+ + + + {fileNames.kartuNama} + +
+ + Format: pdf, jpeg, jpg, png. max file size 2MB + + +
+ {errors.kartuNama?.message} +
+
+ +
+
+ + +

+ Download Template +

+
+
+
+ + + + {fileNames.suratPernyataan} + +
+ + Format: pdf, jpeg, jpg, png. max file size 2MB + + +
+ {errors.suratPernyataan?.message} +
+
+
+ +
+ + + + {fileNames.fotoKantor} + +
+ + Format: pdf, jpeg, jpg, png. max file size 2MB + + +
+ {errors.fotoKantor?.message} +
+
+
+ +
+ + + + {fileNames.dataProduk} + +
+ + Format: pdf, jpeg, jpg, png. max file size 2MB + + +
+ {errors.fotoKantor?.message} +
+
+
+ +
+ + + + {fileNames.pricelist} + +
+ + Format: pdf, jpeg, jpg, png. max file size 2MB + + +
+ {errors.pricelist?.message} +
+
+
+ {/*
+ +
*/} +
+
+ +
+ {/* */} +
+
+
+ +
+
+
+ + ); +}; +const validationSchema = Yup.object().shape({ + company: 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'), +}); +const defaultValues = { + company: '', + pejabatName: '', + PICName: '', + PICPosition: '', + email: '', + emailSales: '', + emailFinance: '', + phone: '', + state: '', + city: '', + district: '', + subDistrict: '', + zip: '', + bank: '', + rekening: '', + accountNumber: '', + address: '', + mobile: '', +}; + +export default Dokumen; 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} -
-
-
{/*
{ +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 ( <> {
-
@@ -605,7 +605,8 @@ const InformasiVendor = () => {
{ const { isDesktop, isMobile } = useDevice(); const [currentStep, setCurrentStep] = React.useState(0); - const NUMBER_OF_STEPS = 6; + const NUMBER_OF_STEPS = 5; const [isLoading, setIsLoading] = useState(false); const [bigData, setBigData] = useState(); const [idTempo, setIdTempo] = useState(0); @@ -30,10 +31,19 @@ const Merchant = () => { const [BannerTempo, setBannerTempo] = useState(); const [notValid, setNotValid] = useState(false); const [buttonSubmitClick, setButtonSubmitClick] = useState(false); + + const [error, setError] = useState(false); + + const handleIsError = (value) => { + console.log('value yang dihasilkan', value); + goToNextStep(); + setError(value); // Memperbarui state berdasarkan isError + }; const stepDivs = [ - , - , + , + , , + , ]; const stepLabels = [ @@ -45,6 +55,13 @@ const Merchant = () => { 'Konfirmasi', ]; + useEffect(() => { + window.scrollTo({ + top: 0, + behavior: 'smooth', + }); + }, [currentStep]); + // useEffect(() => { // const loadBigData = async () => { // const toCamelCase = (str) => @@ -170,9 +187,7 @@ const Merchant = () => { className='w-full mt-6' /> )} -

- Form Pengajuan Tempo -

+

Form Merchant

{ )} {currentStep < 5 && ( <> - - - + + Langkah Selanjutnya + + {} + )}

diff --git a/src/lib/merchant/components/SyaratDagang.jsx b/src/lib/merchant/components/SyaratDagang.jsx index 0e34c5cf..c09db65d 100644 --- a/src/lib/merchant/components/SyaratDagang.jsx +++ b/src/lib/merchant/components/SyaratDagang.jsx @@ -78,6 +78,13 @@ const SyaratDagang = () => { const recaptchaRef = useRef(null); const router = useRouter(); + useEffect(() => { + window.scrollTo({ + top: 0, + behavior: 'smooth', + }); + }, []); + const auth = useAuth(); if (auth == false) { router.push(`/login?next=${encodeURIComponent('/daftar-merchant')}`); @@ -92,11 +99,15 @@ const SyaratDagang = () => { { value: 2, label: 'CV' }, { value: 3, label: 'Perorangan' }, ]; - const dataTempo = [ - { value: 24, label: 'Tempo 14 Hari' }, - { value: 25, label: 'Tempo 30 Hari' }, - { value: 28, label: 'Tempo 60 Hari' }, - { value: 31, label: 'Tempo 90 Hari' }, + const dataGaransi = [ + { value: 1, label: '6 Bulan Garansi' }, + { value: 2, label: '1 Tahun Garansi' }, + { value: 3, label: '2 Tahun Garansi' }, + ]; + const dataMinimumOrderQuantity = [ + { value: 1, label: 'Dus' }, + { value: 2, label: 'Lusin' }, + { value: 3, label: 'Minimum pembelian' }, ]; const dataCategoryPerusahaan = [ @@ -117,10 +128,10 @@ const SyaratDagang = () => { const firstColumn = category_produk; const [selectedIds, setSelectedIds] = useState( - watch('categoryProduk') - ? watch('categoryProduk').split(',').map(Number) + watch('sertifikatProduk') + ? watch('sertifikatProduk').split(',').map(Number) : [] - // form.categoryProduk ? form.categoryProduk.split(',').map(Number) : [] // Parse string menjadi array angka + // form.sertifikatProduk ? form.sertifikatProduk.split(',').map(Number) : [] // Parse string menjadi array angka // [] // Parse string menjadi array angka ); @@ -132,7 +143,7 @@ const SyaratDagang = () => { setSelectedIds(updatedSelected); // Mengubah array kembali menjadi string yang dipisahkan oleh koma - setValue('categoryProduk', updatedSelected.join(',')); + setValue('sertifikatProduk', updatedSelected.join(',')); }; const isChecked = (id) => selectedIds.includes(id); @@ -140,6 +151,9 @@ const SyaratDagang = () => { const handleCheckboxReturChange = (value) => { setValue('isKembaliBarang', `${value}`); }; + const handleCheckboxOrderQuantityChange = (value) => { + setValue('isOrderQuantity', `${value}`); + }; const handleCheckboxTenggatWaktuChange = (value) => { setValue('tenggatWaktu', `${value}`); @@ -528,32 +542,158 @@ const SyaratDagang = () => {
Pilih dokumen/sertifikat bisa lebih dari 1
-
+
- {firstColumn.map((item) => ( + handleCheckboxChange(1)} + isChecked={isChecked(1)} + > + TKDN + + handleCheckboxChange(2)} + isChecked={isChecked(2)} + > + SNI + + handleCheckboxChange(3)} + isChecked={isChecked(3)} + > + K3L + +
handleCheckboxChange(item.id)} - isChecked={isChecked(item.id)} - > - {item.name} - - ))} + key={4} + onChange={() => handleCheckboxChange(4)} + isChecked={isChecked(4)} + > + setSelectedIds([...selectedIds, 4])} + onChange={() => setSelectedIds([...selectedIds, 4])} + className='form-input mt-2' + /> +
+
+
+
+ {errors.sertifikatProduk?.message} +
+
+
+ +
+
+ + + Pilih waktu garansi yang diberikan + +
+
+
+
+ ( + + )} + /> + +
+ {errors.tempoGaransi?.message} +
+
+
+ +
+
+ +
+
+