diff options
| -rw-r--r-- | src-migrate/modules/register/components/FormBisnis.tsx | 73 | ||||
| -rw-r--r-- | src-migrate/modules/register/components/RegistrasiBisnis.tsx | 12 | ||||
| -rw-r--r-- | src-migrate/modules/register/stores/useRegisterStore.ts | 8 | ||||
| -rw-r--r-- | src-migrate/validations/auth.ts | 76 |
4 files changed, 139 insertions, 30 deletions
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<FormProps> = ({ type, required, isPKP }) => { } = useRegisterStore() const { control, watch, setValue } = useForm(); const [selectedCategory, setSelectedCategory] = useState<string>(''); + const [isChekBox, setIsChekBox] = useState<boolean>(false); const [industries, setIndustries] = useState<industry_id[]>([]); const [companyTypes, setCompanyTypes] = useState<companyType[]>([]); @@ -86,6 +87,20 @@ const form: React.FC<FormProps> = ({ type, required, isPKP }) => { validate(); }; + const handleChange = (event: ChangeEvent<HTMLInputElement>) => { + setIsChekBox(!isChekBox) + }; + + useEffect(() => { + if (isChekBox) { + updateForm("isChekBox", 'true'); + validate(); + } else { + updateForm("isChekBox", 'false'); + validate(); + } + }, [isChekBox,]); + const handleFileChange = async (event: ChangeEvent<HTMLInputElement>) => { const toastProps: UseToastOptions = { @@ -225,6 +240,26 @@ const form: React.FC<FormProps> = ({ type, required, isPKP }) => { </div> <div> + <label htmlFor='alamat_bisnis' className="font-bold">Alamat Bisnis</label> + + <input + type='text' + id='alamat_bisnis' + name='alamat_bisnis' + placeholder='Masukan alamat bisnis anda' + value={!required? form.alamat_bisnis : ''} + className={`form-input mt-3 ${required ? 'cursor-no-drop' : ''}`} + disabled={required} + contentEditable={required} + readOnly={required} + onChange={handleInputChange} + aria-invalid={!required && !!errors.alamat_bisnis} + /> + + {!required && !!errors.alamat_bisnis && <span className="form-msg-danger">{errors.alamat_bisnis}</span>} + </div> + + <div> <label htmlFor='nama_wajib_pajak' className="font-bold">Nama Wajib Pajak {!isPKP && !required && <span className='font-normal text-gray_r-11'>(opsional)</span>}</label> <input @@ -245,6 +280,42 @@ const form: React.FC<FormProps> = ({ type, required, isPKP }) => { </div> <div> + <label htmlFor='alamat_wajib_pajak' className="font-bold flex items-center"> + <p> + Alamat Wajib Pajak {!isPKP && !required && <span className='font-normal text-gray_r-11'>(opsional)</span>} + </p> + <div className="flex items-center ml-2 mt-1"> + <Checkbox + borderColor='gray.600' + colorScheme='red' + size='md' + isChecked={isChekBox} + onChange={handleChange} + /> + <span className='text-caption-2 ml-2 font-normal italic'> + sama dengan alamat bisnis? + </span> + </div> + </label> + + <input + type='text' + id='alamat_wajib_pajak' + name='alamat_wajib_pajak' + placeholder='Masukan alamat wajib pajak anda' + value={!required? (isChekBox?form.alamat_bisnis : form.alamat_wajib_pajak) : ''} + className={`form-input mt-3 ${required ? 'cursor-no-drop' : ''}`} + disabled={isChekBox || required} + contentEditable={required} + readOnly={required} + onChange={handleInputChange} + aria-invalid={isPKP && !required && !!errors.alamat_wajib_pajak} + /> + + {isPKP && !required && !!errors.alamat_wajib_pajak && <span className="form-msg-danger">{errors.alamat_wajib_pajak}</span>} + </div> + + <div> <label htmlFor='npwp' className="font-bold">Nomor NPWP {!isPKP && !required && <span className='font-normal text-gray_r-11'>(opsional)</span>}</label> <input 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<State & Action>((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<State & Action>((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', |
