diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-08-24 08:46:44 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-08-24 08:46:44 +0700 |
| commit | 0bca1bfb2bc7e52a31dde39602dd599d7c640e73 (patch) | |
| tree | 2859fefbcde9243d394f03929814d7951b41014a /src-migrate | |
| parent | bf33cdda7fb249cdd2473e0d1039704fd2171589 (diff) | |
<iman> update new register
Diffstat (limited to 'src-migrate')
| -rw-r--r-- | src-migrate/modules/register/components/Form.tsx | 7 | ||||
| -rw-r--r-- | src-migrate/modules/register/components/FormBisnis.tsx | 39 | ||||
| -rw-r--r-- | src-migrate/modules/register/components/RegistrasiBisnis.tsx | 36 | ||||
| -rw-r--r-- | src-migrate/modules/register/stores/useRegisterStore.ts | 10 | ||||
| -rw-r--r-- | src-migrate/validations/auth.ts | 4 |
5 files changed, 76 insertions, 20 deletions
diff --git a/src-migrate/modules/register/components/Form.tsx b/src-migrate/modules/register/components/Form.tsx index 76601866..c4789e9a 100644 --- a/src-migrate/modules/register/components/Form.tsx +++ b/src-migrate/modules/register/components/Form.tsx @@ -36,10 +36,13 @@ const Form: React.FC<FormProps> = ({ type, required, isBisnisRegist=false }) => const { name, value } = event.target; updateForm(name, value) // if(!isBisnisRegist){ + + updateForm('type_acc',`individu`) + updateForm('is_pkp','false') updateForm('business_name','Iman') - updateForm('companyType','iman') + updateForm('company_type_id','0') updateForm('email_partner','it@fixcomart.co.id') - updateForm('industry','1') + updateForm('industry_id','0') updateForm('nama_wajib_pajak','Iman') updateForm('npwp','958666666688888') updateForm('npwp_document','adsdad.pdf') diff --git a/src-migrate/modules/register/components/FormBisnis.tsx b/src-migrate/modules/register/components/FormBisnis.tsx index b58f2fec..f969efdf 100644 --- a/src-migrate/modules/register/components/FormBisnis.tsx +++ b/src-migrate/modules/register/components/FormBisnis.tsx @@ -23,13 +23,14 @@ interface industry_id { category: string; } -interface company_type_id { +interface companyType { value: string; label: string; } const FormBisnis: React.FC<FormProps> = ({ type, required, isPKP }) => { const { + form, formBisnis, isCheckedTNC, isValidCaptcha, @@ -43,7 +44,7 @@ const FormBisnis: React.FC<FormProps> = ({ type, required, isPKP }) => { const [selectedCompanyId, setSelectedCompanyId] = useState<string>(''); const [industries, setIndustries] = useState<industry_id[]>([]); - const [companyTypes, setCompanyTypes] = useState<company_type_id[]>([]); + const [companyTypes, setCompanyTypes] = useState<companyType[]>([]); const isFormValid = useMemo(() => Object.keys(errors).length === 0, [errors]); const router = useRouter(); @@ -58,19 +59,19 @@ const FormBisnis: React.FC<FormProps> = ({ type, required, isPKP }) => { }, []); useEffect(() => { - const selectedCompanyType = companyTypes.find(company => company.value === watch('company_type_id')); + const selectedCompanyType = companyTypes.find(company => company.value === watch('companyType')); if (selectedCompanyType) { - updateFormBisnis("company_type_id", selectedCompanyType?.value); + updateFormBisnis("company_type_id", `${selectedCompanyType?.value}`); setSelectedCompanyId(selectedCompanyType?.label) validateFormBisnis(); } - }, [watch('company_type_id'), companyTypes]); + }, [watch('companyType'), companyTypes]); useEffect(() => { const selectedIndustryType = industries.find(industry => industry.value === watch('industry_id')); if (selectedIndustryType) { - updateFormBisnis("industry_id", selectedIndustryType?.value); - setSelectedCategory(selectedIndustryType.label); + updateFormBisnis("industry_id", `${selectedIndustryType?.value}`); + setSelectedCategory(selectedIndustryType.category); validateFormBisnis(); } }, [watch('industry_id'), industries]); @@ -85,15 +86,29 @@ const FormBisnis: React.FC<FormProps> = ({ type, required, isPKP }) => { const handleInputChange = (event: ChangeEvent<HTMLInputElement>) => { const { name, value } = event.target; + updateFormBisnis('type_acc',`business`) + updateFormBisnis('is_pkp',`${isPKP}`) updateFormBisnis(name, value); - updateFormBisnis('name','iman'); - updateFormBisnis('email','it@fixcomart.co.id'); - updateFormBisnis('password','Fixcomart378'); - updateFormBisnis('phone','082339129611'); + updateFormBisnis('name',form.name); + updateFormBisnis('email',form.email); + updateFormBisnis('password',form.password); + updateFormBisnis('phone',form.phone); validateFormBisnis(); }; const handleFileChange = async (event: ChangeEvent<HTMLInputElement>) => { + // const file = poFile.current.files[0]; + // const name = poNumber.current.value; + // if (typeof file === 'undefined' || !name) { + // toast.error('Nomor dan Dokumen PO harus diisi'); + // return; + // } + // if (file.size > 5000000) { + // toast.error('Maksimal ukuran file adalah 5MB'); + // return; + // } + // const data = { name, file: await getFileBase64(file) }; + let fileBase64 = ''; const { name} = event.target; const file = event.target.files?.[0]; @@ -183,7 +198,7 @@ const FormBisnis: React.FC<FormProps> = ({ type, required, isPKP }) => { <div className="flex justify-between items-start gap-2 h-12"> <div className='w-4/5 pr-1'> <Controller - name='company_type_id' + name='companyType' control={control} render={(props) => <HookFormSelect {...props} options={companyTypes} disabled={required} placeholder="Badan Usaha"/>} /> diff --git a/src-migrate/modules/register/components/RegistrasiBisnis.tsx b/src-migrate/modules/register/components/RegistrasiBisnis.tsx index 12ec7ba2..6ace27f9 100644 --- a/src-migrate/modules/register/components/RegistrasiBisnis.tsx +++ b/src-migrate/modules/register/components/RegistrasiBisnis.tsx @@ -86,6 +86,42 @@ const RegistrasiBisnis = () => { const handleSubmit = async () => { console.log("form",form) console.log("form Bisnis",formBisnis) + const response = await mutation.mutateAsync(formBisnis) + + console.log("response",response) + + if (response?.register === true) { + const urlParams = new URLSearchParams({ + activation: 'otp', + email: form.email, + redirect: (router.query?.next || '/') as string + }) + router.push(`${router.route}?${urlParams}`) + } + + const toastProps: UseToastOptions = { + duration: 5000, + isClosable: true + } + + switch (response?.reason) { + case 'EMAIL_USED': + toast({ + ...toastProps, + title: 'Email sudah digunakan', + status: 'warning' + }) + break; + case 'NOT_ACTIVE': + const activationUrl = `${router.route}?activation=email` + toast({ + ...toastProps, + title: 'Akun belum aktif', + description: <>Akun sudah terdaftar namun belum aktif. <Link href={activationUrl} className="underline">Klik untuk aktivasi akun</Link></>, + status: 'warning' + }) + break + } }; return ( <> diff --git a/src-migrate/modules/register/stores/useRegisterStore.ts b/src-migrate/modules/register/stores/useRegisterStore.ts index 2db0b602..75d2ab34 100644 --- a/src-migrate/modules/register/stores/useRegisterStore.ts +++ b/src-migrate/modules/register/stores/useRegisterStore.ts @@ -28,7 +28,7 @@ type Action = { export const useRegisterStore = create<State & Action>((set, get) => ({ form: { business_name: '', - company_type_id: 0, + company_type_id: '', name: '', email: '', email_partner: '', @@ -37,15 +37,16 @@ export const useRegisterStore = create<State & Action>((set, get) => ({ sppkp_document: '', npwp_document: '', nameWajibPajak: '', - industry_id: 0, + industry_id: '', badanUsaha: '', jenisUsaha: '', npwp: '', nama_wajib_pajak : '', is_pkp: '', + type_acc:'' }, formBisnis: { - company_type_id: 0, + company_type_id: '', business_name: '', name: '', nama_wajib_pajak : '', @@ -56,11 +57,12 @@ export const useRegisterStore = create<State & Action>((set, get) => ({ sppkp_document: '', npwp_document: '', nameWajibPajak: '', - industry_id: 0, + industry_id: '', badanUsaha: '', jenisUsaha: '', npwp: '', is_pkp:'', + type_acc:'' }, updateForm: (name, value) => set((state) => ({ form: { ...state.form, [name]: value } })), diff --git a/src-migrate/validations/auth.ts b/src-migrate/validations/auth.ts index fd645ef3..dc5b0411 100644 --- a/src-migrate/validations/auth.ts +++ b/src-migrate/validations/auth.ts @@ -16,13 +16,13 @@ export const registerSchema = z.object({ nama_wajib_pajak: z.string().min(1, { message: 'Nama wajib pajak harus diisi' }), sppkp_document: z.string().min(1, { message: 'document harus diisi' }), npwp_document: z.string().min(1, { message: 'document harus diisi' }), - industry_id: z.number().min(1, { message: 'Jenis usaha harus dipilih' }), + industry_id: z.string().min(1, { message: 'Jenis usaha harus dipilih' }), email_partner: z .string() .min(1, { message: 'Email harus diisi' }) .email({ message: 'Email harus menggunakan format example@mail.com' }), business_name: z.string().min(1, { message: 'Nama perusahaan harus diisi' }), - company_type_id: z.number().min(1, { message: 'Badan usaha wajib dipilih' }), + company_type_id: z.string().min(1, { message: 'Badan usaha wajib dipilih' }), npwp: z .string() .min(15, { message: 'Format NPWP tidak valid, NPWP harus terdiri dari 15 digit angka.' }) |
