From 2ffc49bb65a16f07cf5a3b7e4926c34ea07b9460 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 21 Aug 2024 17:10:13 +0700 Subject: update new register --- .../modules/register/components/FormBisnis.tsx | 118 ++++++++++++++------- .../register/components/RegistrasiBisnis.tsx | 37 ++++--- .../modules/register/stores/useRegisterStore.ts | 22 ++-- src-migrate/types/auth.ts | 1 + src-migrate/validations/auth.ts | 17 ++- 5 files changed, 132 insertions(+), 63 deletions(-) (limited to 'src-migrate') diff --git a/src-migrate/modules/register/components/FormBisnis.tsx b/src-migrate/modules/register/components/FormBisnis.tsx index 7b301dc5..d014f4e7 100644 --- a/src-migrate/modules/register/components/FormBisnis.tsx +++ b/src-migrate/modules/register/components/FormBisnis.tsx @@ -22,6 +22,11 @@ interface Industry { category: string; } +interface CompanyType { + value: string; + label: string; +} + const FormBisnis: React.FC = ({ type, required }) => { const { formBisnis, @@ -34,9 +39,10 @@ const FormBisnis: React.FC = ({ type, required }) => { const { control, watch, setValue } = useForm(); const [selectedCategory, setSelectedCategory] = useState(''); + const [selectedCompanyId, setSelectedCompanyId] = useState(); const [industries, setIndustries] = useState([]); - const [companyTypes, setCompanyTypes] = useState([]); + const [companyTypes, setCompanyTypes] = useState([]); const isFormValid = useMemo(() => Object.keys(errors).length === 0, [errors]); const router = useRouter(); @@ -50,6 +56,23 @@ const FormBisnis: React.FC = ({ type, required }) => { loadCompanyTypes(); }, []); + useEffect(() => { + const selectedCompanyType = companyTypes.find(company => company.value === watch('companyType')); + if (selectedCompanyType) { + updateFormBisnis("company_type_id", selectedCompanyType?.value); + validateFormBisnis(); + } + }, [watch('companyType'), companyTypes]); + + useEffect(() => { + const selectedIndustryType = industries.find(industry => industry.value === watch('industry')); + if (selectedIndustryType) { + updateFormBisnis("industry_id", selectedIndustryType?.value); + validateFormBisnis(); + console.log("selectedIndustryType",selectedIndustryType) + } + }, [watch('industry'), industries]); + useEffect(() => { const loadIndustries = async () => { const dataIndustries = await odooApi('GET', '/api/v1/partner/industry'); @@ -76,6 +99,7 @@ const FormBisnis: React.FC = ({ type, required }) => { const handleFileChange = async (event: ChangeEvent) => { let fileBase64 = ''; + const { name} = event.target; const file = event.target.files?.[0]; if (file) { if (typeof file !== 'undefined') { @@ -85,7 +109,7 @@ const FormBisnis: React.FC = ({ type, required }) => { } fileBase64 = await getFileBase64(file); } - updateFormBisnis("document", fileBase64); // Menyimpan file ke dalam formBisnis state + updateFormBisnis(name, fileBase64); validateFormBisnis(); } }; @@ -140,17 +164,21 @@ const FormBisnis: React.FC = ({ type, required }) => { - {!!errors.email && {errors.email}} + {!required && !!errors.email_partner && {errors.email_partner}}
@@ -162,96 +190,108 @@ const FormBisnis: React.FC = ({ type, required }) => { } + render={(props) => } />
-
- + - {!!errors.name && {errors.name}} + {!required && !!errors.nama_wajib_pajak && {errors.nama_wajib_pajak}}
- + - {!!errors.phone && {errors.phone}} + {!required && !!errors.npwp && {errors.npwp}}
- + - {/* {!!errors.document && {errors.document}} */} + {!required && !!errors.npwp_document && {errors.npwp_document}}
- + - {/* {!!errors.document && {errors.document}} */} + {!required && !!errors.sppkp_document && {errors.sppkp_document}}
{/*