diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-09-27 09:28:14 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-09-27 09:28:14 +0700 |
| commit | 11f415a8c9438362078d0eceee37701edbdeaafc (patch) | |
| tree | b953b5107742f1aab4f6baf953b6eb800b9ba311 /src-migrate/modules/register | |
| parent | 935066853ab4847fbff605eed21f98ddbb445864 (diff) | |
<iman> update fetch data
Diffstat (limited to 'src-migrate/modules/register')
| -rw-r--r-- | src-migrate/modules/register/components/FormBisnis.tsx | 72 |
1 files changed, 41 insertions, 31 deletions
diff --git a/src-migrate/modules/register/components/FormBisnis.tsx b/src-migrate/modules/register/components/FormBisnis.tsx index c88ec735..d4fdbbbd 100644 --- a/src-migrate/modules/register/components/FormBisnis.tsx +++ b/src-migrate/modules/register/components/FormBisnis.tsx @@ -1,4 +1,11 @@ -import { ChangeEvent, useEffect, useMemo, useRef, useState } from 'react'; +import { + ChangeEvent, + useEffect, + useMemo, + useRef, + useState, + MouseEvent, +} from 'react'; import { useMutation } from 'react-query'; import { useRegisterStore } from '../stores/useRegisterStore'; import { RegisterProps } from '~/types/auth'; @@ -62,7 +69,6 @@ const form: React.FC<FormProps> = ({ const router = useRouter(); const toast = useToast(); - const emailRef = useRef<HTMLInputElement>(null); const businessNameRef = useRef<HTMLInputElement>(null); const companyTypeRef = useRef<HTMLInputElement>(null); @@ -94,38 +100,14 @@ const form: React.FC<FormProps> = ({ useEffect(() => { if (form.company_type_id) { - console.log('form.company_type_id', form.company_type_id); - setValue('companyType', form.company_type_id); + setValue('companyType', parseInt(form.company_type_id)); } - }, [form.company_type_id]); - - useEffect(() => { - const selectedCompanyType = companyTypes.find( - (company) => company.value === watch('companyType') - ); - if (selectedCompanyType) { - console.log('selectedCompanyType', selectedCompanyType); - updateForm('company_type_id', `${selectedCompanyType?.value}`); - // setCompanyTypes([ - // { - // value: '2', - // label: 'Distributor', - // }, - // ]); - validate(); - } - }, [watch('companyType'), companyTypes]); - + }, []); useEffect(() => { - const selectedIndustryType = industries.find( - (industry) => industry.value === watch('industry_id') - ); - if (selectedIndustryType) { - updateForm('industry_id', `${selectedIndustryType?.value}`); - setSelectedCategory(selectedIndustryType.category); - validate(); + if (form.industry_id) { + setValue('industry_id', parseInt(form.industry_id)); } - }, [watch('industry_id'), industries]); + }, []); useEffect(() => { const loadIndustries = async () => { @@ -326,6 +308,32 @@ const form: React.FC<FormProps> = ({ }; loadIndustries(); }, [buttonSubmitClick, chekValid]); + + const handleCompanyTypeChange = (event: MouseEvent<HTMLDivElement>) => { + const selectedCompanyTypeValue = watch('companyType'); + const selectedCompanyType = companyTypes.find( + (company) => company.value === selectedCompanyTypeValue + ); + + if (selectedCompanyType !== undefined) { + updateForm('company_type_id', `${selectedCompanyType.value}`); + validate(); + } + }; + useEffect(() => {}, [watch('industry_id'), industries]); + + const handleIndustriIdChange = (event: MouseEvent<HTMLDivElement>) => { + const selectedIndustriIdValue = watch('industry_id'); + const selectedIndustryType = industries.find( + (industry) => industry.value === selectedIndustriIdValue + ); + if (selectedIndustryType) { + updateForm('industry_id', `${selectedIndustryType?.value}`); + setSelectedCategory(selectedIndustryType.category); + validate(); + } + }; + return ( <> <BottomPopup @@ -393,6 +401,7 @@ const form: React.FC<FormProps> = ({ <div className='w-4/5 pr-1 max-h-11 transition-all duration-500' ref={companyTypeRef} + onClick={handleCompanyTypeChange} > <Controller name='companyType' @@ -440,6 +449,7 @@ const form: React.FC<FormProps> = ({ <div className='max-h-10 transition-all duration-500' ref={industryRef} + onClick={handleIndustriIdChange} > <Controller name='industry_id' |
