diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2025-01-15 13:21:48 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2025-01-15 13:21:48 +0700 |
| commit | b9b4eb3ed751a69c023a45e7cdca8da01ae6b1cd (patch) | |
| tree | 081e67309f0b0a7795c685cf933caed23e52e296 /src/lib/merchant/components/InformasiPerusahaan.jsx | |
| parent | 3692f937130e18cf396f5871d8a15bdd258bdd2b (diff) | |
<iman> update merchant
Diffstat (limited to 'src/lib/merchant/components/InformasiPerusahaan.jsx')
| -rw-r--r-- | src/lib/merchant/components/InformasiPerusahaan.jsx | 57 |
1 files changed, 47 insertions, 10 deletions
diff --git a/src/lib/merchant/components/InformasiPerusahaan.jsx b/src/lib/merchant/components/InformasiPerusahaan.jsx index 60e61e2e..a5456378 100644 --- a/src/lib/merchant/components/InformasiPerusahaan.jsx +++ b/src/lib/merchant/components/InformasiPerusahaan.jsx @@ -9,7 +9,8 @@ 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 createMerchantApi from '../api/createMerchantApi'; +import getMerchantApi from '../api/getMerchantApi'; import addressApi from '@/lib/address/api/addressApi'; import PageContent from '@/lib/content/components/PageContent'; import { useRouter } from 'next/router'; @@ -115,6 +116,44 @@ const CreateMerchant = ({ handleIsError }) => { ]; useEffect(() => { + const loadData = async () => { + try { + const data = await getMerchantApi(); + console.log('data', data); + reset({ + pejabatName: data.pejabatName ? data.pejabatName : '', + PICName: data.picMerchant || '', + PICPosition: data.picPosition || '', + address: data.address || '', + state: data.state || '', + city: data.city || '', + district: data.district || '', + subDistrict: data.subDistrict || '', + zip: parseInt(data.zip) || '', + email: data.emailCompany || '', + emailSales: data.emailSales || '', + emailFinance: data.emailFinance || '', + bank: data.bankName || '', + rekening: data.rekeningName || '', + accountNumber: data.accountNumber || '', + phone: data.phone || '', + mobile: data.mobile || '', + bisnisType: data.bisnisType ? parseInt(data.bisnisType) : null, + categoryPerusahaan: data.categoryPerusahaan + ? parseInt(data.categoryPerusahaan) + : null, + website: data.website || '', + }); + } catch (error) { + console.error('Error loading profile:', error); + handleIsError(true); // Jika ada error, panggil fungsi error handler + } + }; + + loadData(); + }, [reset, handleIsError]); + + useEffect(() => { const loadProfile = async () => { try { const dataProfile = await addressApi({ @@ -170,10 +209,10 @@ const CreateMerchant = ({ handleIsError }) => { }, [auth, watchState]); const watchCity = watch('city'); - + console.log('watchCity', watchCity); useEffect(() => { if (watchCity) { - setValue('district', ''); + // setValue('district', ''); const loadDistricts = async () => { let dataDistricts = await districtApi({ cityId: watchCity }); dataDistricts = dataDistricts.map((district) => ({ @@ -189,7 +228,7 @@ const CreateMerchant = ({ handleIsError }) => { const watchDistrict = watch('district'); useEffect(() => { if (watchDistrict) { - setValue('subDistrict', ''); + // setValue('subDistrict', ''); const loadSubDistricts = async () => { let dataSubDistricts = await subDistrictApi({ districtId: watchDistrict, @@ -211,7 +250,7 @@ const CreateMerchant = ({ handleIsError }) => { let kecamatan = ''; if (watchDistrict) { - setValue('zip', ''); + // setValue('zip', ''); for (const data in districts) { if (districts[data].value == watchDistrict) { kecamatan = districts[data].label.toLowerCase(); @@ -266,7 +305,6 @@ const CreateMerchant = ({ handleIsError }) => { pejabat_name: values.pejabatName, pic_merchant: values.PICName, pic_position: values.PICPosition, - partner_id: auth.partnerId, address: values.address, state: values.state, city: values.city, @@ -283,6 +321,7 @@ const CreateMerchant = ({ handleIsError }) => { mobile: values.mobile, bisnis_type: values.bisnisType, category_perusahaan: values.categoryPerusahaan, + website: values.website, description: 'Nama Perusahaan : ' + values.company + @@ -297,15 +336,13 @@ const CreateMerchant = ({ handleIsError }) => { ' \r\n No Hp : ' + values.mobile, }; - // isError(true); - // toast.dismiss(toastId); - // toast.success('Berhasil menambahkan data'); const create_leads = await createMerchantApi({ data }); if (create_leads) { toast.dismiss(toastId); toast.success('Berhasil menambahkan data'); + isError(false); reset(); - router.push('/'); + // router.push('/'); } else { toast.dismiss(toastId); toast.error('Gagal menambahkan data'); |
