From ad3038d8902245ba0ec4122dc9795cda3906ba0e Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 26 Aug 2024 10:52:10 +0700 Subject: update new register handling validation --- .../register/components/RegistrasiBisnis.tsx | 5 ++- src-migrate/validations/auth.ts | 41 +++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) (limited to 'src-migrate') diff --git a/src-migrate/modules/register/components/RegistrasiBisnis.tsx b/src-migrate/modules/register/components/RegistrasiBisnis.tsx index b8ea5fff..c158e2f4 100644 --- a/src-migrate/modules/register/components/RegistrasiBisnis.tsx +++ b/src-migrate/modules/register/components/RegistrasiBisnis.tsx @@ -58,19 +58,22 @@ const RegistrasiBisnis = () => { setIsIndividuRequired(true); setIsPKP(true); } else { + validate(); setIsPKP(false); setIsIndividuRequired(false); // Hide and make optional the Individu form setIsPKP(false); } }; - + const handleChangeBisnis = (value: string) => { setSelectedValueBisnis(value); console.log('value',value) if (value === "true") { + validate(); updateForm('is_terdaftar','true') setIsTerdaftar(true); } else { + validate(); updateForm('is_terdaftar','false') setIsTerdaftar(false); } diff --git a/src-migrate/validations/auth.ts b/src-migrate/validations/auth.ts index 69ea52e1..5cc3dc67 100644 --- a/src-migrate/validations/auth.ts +++ b/src-migrate/validations/auth.ts @@ -89,7 +89,46 @@ export const registerSchema = z } } }else{ - + if (data.is_pkp === 'false') { + // Validation for is_pkp === 'false' + if (!data.business_name) { + ctx.addIssue({ + code: 'custom', + path: ['business_name'], + message: 'Nama perusahaan harus diisi', + }); + } + } else { + // Validation for is_pkp === 'true' or other values + const requiredFields: { field: keyof typeof data; message: string }[] = [ + { field: 'business_name', message: 'Nama perusahaan harus diisi' }, + { field: 'company_type_id', message: 'Badan usaha wajib dipilih' }, + { field: 'industry_id', message: 'Jenis usaha harus dipilih' }, + { field: 'sppkp_document', message: 'Document harus diisi' }, + { field: 'npwp_document', message: 'Document harus diisi' }, + { field: 'npwp', message: 'Format NPWP tidak valid, NPWP harus terdiri dari 15 digit angka.' }, + { field: 'nama_wajib_pajak', message: 'Nama wajib pajak harus diisi' }, + ]; + + requiredFields.forEach(({ field, message }) => { + if (!data[field]) { + ctx.addIssue({ + code: 'custom', + path: [field], + message, + }); + } + }); + + // Email validation for `email_partner` + if (!data.email_partner || !z.string().email().safeParse(data.email_partner).success) { + ctx.addIssue({ + code: 'custom', + path: ['email_partner'], + message: 'Email partner harus diisi dengan format example@mail.com', + }); + } + } } // Remove this unconditional issue addition to prevent blocking form submission -- cgit v1.2.3