From b9b4eb3ed751a69c023a45e7cdca8da01ae6b1cd Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Wed, 15 Jan 2025 13:21:48 +0700
Subject: <iman> update merchant

---
 .../merchant/components/InformasiPerusahaan.jsx    | 57 ++++++++++++++++++----
 1 file changed, 47 insertions(+), 10 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 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';
@@ -114,6 +115,44 @@ const CreateMerchant = ({ handleIsError }) => {
     { value: 5, label: 'Wholesaler (Pedagang Besar)' },
   ];
 
+  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 {
@@ -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');
-- 
cgit v1.2.3

