From 0b5f187f45e0bbf111e11a94415f20d5e34f7c5c Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 27 Aug 2024 14:51:14 +0700 Subject: update new field register --- .../modules/register/components/FormBisnis.tsx | 73 ++++++++++++++++++++- .../register/components/RegistrasiBisnis.tsx | 12 +++- .../modules/register/stores/useRegisterStore.ts | 8 ++- src-migrate/validations/auth.ts | 76 +++++++++++++++------- 4 files changed, 139 insertions(+), 30 deletions(-) (limited to 'src-migrate') diff --git a/src-migrate/modules/register/components/FormBisnis.tsx b/src-migrate/modules/register/components/FormBisnis.tsx index 1d0c930f..3b8fdbfc 100644 --- a/src-migrate/modules/register/components/FormBisnis.tsx +++ b/src-migrate/modules/register/components/FormBisnis.tsx @@ -4,7 +4,7 @@ import { useRegisterStore } from "../stores/useRegisterStore"; import { RegisterProps } from "~/types/auth"; import { registerUser } from "~/services/auth"; import { useRouter } from "next/router"; -import { UseToastOptions, color, useToast } from "@chakra-ui/react"; +import { Checkbox, UseToastOptions, color, useToast } from "@chakra-ui/react"; import Link from "next/link"; import getFileBase64 from '@/core/utils/getFileBase64' import { Controller, useForm } from 'react-hook-form' @@ -38,6 +38,7 @@ const form: React.FC = ({ type, required, isPKP }) => { } = useRegisterStore() const { control, watch, setValue } = useForm(); const [selectedCategory, setSelectedCategory] = useState(''); + const [isChekBox, setIsChekBox] = useState(false); const [industries, setIndustries] = useState([]); const [companyTypes, setCompanyTypes] = useState([]); @@ -86,6 +87,20 @@ const form: React.FC = ({ type, required, isPKP }) => { validate(); }; + const handleChange = (event: ChangeEvent) => { + setIsChekBox(!isChekBox) + }; + + useEffect(() => { + if (isChekBox) { + updateForm("isChekBox", 'true'); + validate(); + } else { + updateForm("isChekBox", 'false'); + validate(); + } + }, [isChekBox,]); + const handleFileChange = async (event: ChangeEvent) => { const toastProps: UseToastOptions = { @@ -224,6 +239,26 @@ const form: React.FC = ({ type, required, isPKP }) => { {!required && !!errors.industry_id && {errors.industry_id}} +
+ + + + + {!required && !!errors.alamat_bisnis && {errors.alamat_bisnis}} +
+
@@ -244,6 +279,42 @@ const form: React.FC = ({ type, required, isPKP }) => { {isPKP && !required && !!errors.nama_wajib_pajak && {errors.nama_wajib_pajak}}
+
+ + + + + {isPKP && !required && !!errors.alamat_wajib_pajak && {errors.alamat_wajib_pajak}} +
+
diff --git a/src-migrate/modules/register/components/RegistrasiBisnis.tsx b/src-migrate/modules/register/components/RegistrasiBisnis.tsx index 443ff0a0..1d8317f1 100644 --- a/src-migrate/modules/register/components/RegistrasiBisnis.tsx +++ b/src-migrate/modules/register/components/RegistrasiBisnis.tsx @@ -48,6 +48,16 @@ const RegistrasiBisnis = () => { validate(); } }, [selectedValue,]); + + useEffect(() => { + if (isTerdaftar) { + updateForm("is_terdaftar", 'true'); + validate(); + } else { + updateForm("is_terdaftar", 'false'); + validate(); + } + }, [isTerdaftar,]); const handleChange = (value: string) => { setSelectedValue(value); @@ -65,11 +75,9 @@ const RegistrasiBisnis = () => { setSelectedValueBisnis(value); if (value === "true") { validate(); - updateForm('is_terdaftar','true') setIsTerdaftar(true); } else { validate(); - updateForm('is_terdaftar','false') setIsTerdaftar(false); } }; diff --git a/src-migrate/modules/register/stores/useRegisterStore.ts b/src-migrate/modules/register/stores/useRegisterStore.ts index 7bed1833..14288b6e 100644 --- a/src-migrate/modules/register/stores/useRegisterStore.ts +++ b/src-migrate/modules/register/stores/useRegisterStore.ts @@ -39,7 +39,9 @@ export const useRegisterStore = create((set, get) => ({ npwp: '', is_pkp: '', type_acc:'', - is_terdaftar:'' + is_terdaftar:'', + alamat_bisnis:'', + alamat_wajib_pajak:'', }, updateForm: (name, value) => set((state) => ({ form: { ...state.form, [name]: value } })), @@ -87,7 +89,9 @@ export const useRegisterStore = create((set, get) => ({ npwp: '', is_pkp: '', type_acc:'', - is_terdaftar:'' + is_terdaftar:'', + alamat_bisnis:'', + alamat_wajib_pajak:'', }, }), })); diff --git a/src-migrate/validations/auth.ts b/src-migrate/validations/auth.ts index 443c0d80..81d464f2 100644 --- a/src-migrate/validations/auth.ts +++ b/src-migrate/validations/auth.ts @@ -16,6 +16,8 @@ export const registerSchema = z }), type_acc: z.string().optional(), nama_wajib_pajak: z.string().optional(), + alamat_bisnis: z.string().optional(), + alamat_wajib_pajak: z.string().optional(), is_pkp: z.string(), is_terdaftar: z.string(), sppkp_document: z.string().optional(), @@ -24,36 +26,19 @@ export const registerSchema = z email_partner: z.string().optional(), business_name: z.string().optional(), company_type_id: z.string().optional(), - npwp: z.string().optional(), + isChekBox: z.string().optional(), + npwp: z.string().optional().refine((val) => !val || /^\d{15,16}$/.test(val), { + message: 'Format NPWP tidak valid, NPWP harus terdiri dari 15-16 digit angka.', + }), }) .superRefine((data, ctx) => { if (data.type_acc === 'business') { if (data.is_terdaftar === 'false') { - if (data.is_pkp === 'false') { - if (!data.business_name) { - ctx.addIssue({ - code: 'custom', - path: ['business_name'], - message: 'Nama perusahaan harus diisi', - }); - } - if (!data.company_type_id) { - ctx.addIssue({ - code: 'custom', - path: ['company_type_id'], - message: 'Badan usaha wajib dipilih', - }); - } - if (!data.industry_id) { - ctx.addIssue({ - code: 'custom', - path: ['industry_id'], - message: 'Jenis usaha harus dipilih', - }); - } - } else { + if (data.is_pkp === 'true') { const requiredFields: { field: keyof typeof data; message: string }[] = [ { field: 'business_name', message: 'Nama perusahaan harus diisi' }, + { field: 'alamat_bisnis', message: 'Alamat perusahaan harus diisi' }, + // { field: 'alamat_wajib_pajak', message: 'Alamat wajib pajak 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' }, @@ -79,9 +64,50 @@ export const registerSchema = z message: 'Email partner harus diisi dengan format example@mail.com', }); } + if(data.isChekBox === 'false'){ + if (!data.alamat_wajib_pajak) { + ctx.addIssue({ + code: 'custom', + path: ['alamat_wajib_pajak'], + message: 'Alamat wajib pajak harus diisi', + }); + } + } + + } else { + if (!data.business_name) { + ctx.addIssue({ + code: 'custom', + path: ['business_name'], + message: 'Nama perusahaan harus diisi', + }); + } + if (!data.alamat_bisnis) { + ctx.addIssue({ + code: 'custom', + path: ['alamat_bisnis'], + message: 'Alamat perusahaan harus diisi', + }); + } + + if (!data.company_type_id) { + ctx.addIssue({ + code: 'custom', + path: ['company_type_id'], + message: 'Badan usaha wajib dipilih', + }); + } + if (!data.industry_id) { + ctx.addIssue({ + code: 'custom', + path: ['industry_id'], + message: 'Jenis usaha harus dipilih', + }); + } + } }else{ - if (data.is_pkp === 'false') { + if (data.is_pkp === 'true') { if (!data.business_name) { ctx.addIssue({ code: 'custom', -- cgit v1.2.3