summaryrefslogtreecommitdiff
path: root/src-migrate/modules/register/components/FormBisnis.tsx
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-08-26 10:28:15 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-08-26 10:28:15 +0700
commitf0cde08a3fda95b1738a765358022241aea404bf (patch)
treec2cf2cb3e07154d04672f3b9d0667753f8487764 /src-migrate/modules/register/components/FormBisnis.tsx
parent0bca1bfb2bc7e52a31dde39602dd599d7c640e73 (diff)
<iman> update logic new register validation
Diffstat (limited to 'src-migrate/modules/register/components/FormBisnis.tsx')
-rw-r--r--src-migrate/modules/register/components/FormBisnis.tsx50
1 files changed, 24 insertions, 26 deletions
diff --git a/src-migrate/modules/register/components/FormBisnis.tsx b/src-migrate/modules/register/components/FormBisnis.tsx
index f969efdf..5d15ab6c 100644
--- a/src-migrate/modules/register/components/FormBisnis.tsx
+++ b/src-migrate/modules/register/components/FormBisnis.tsx
@@ -28,17 +28,15 @@ interface companyType {
label: string;
}
-const FormBisnis: React.FC<FormProps> = ({ type, required, isPKP }) => {
+const form: React.FC<FormProps> = ({ type, required, isPKP }) => {
const {
form,
- formBisnis,
isCheckedTNC,
isValidCaptcha,
errors,
- updateFormBisnis,
- validateFormBisnis,
+ updateForm,
+ validate
} = useRegisterStore()
- console.log("errors bisnis",errors)
const { control, watch, setValue } = useForm();
const [selectedCategory, setSelectedCategory] = useState<string>('');
const [selectedCompanyId, setSelectedCompanyId] = useState<string>('');
@@ -61,18 +59,18 @@ const FormBisnis: React.FC<FormProps> = ({ type, required, isPKP }) => {
useEffect(() => {
const selectedCompanyType = companyTypes.find(company => company.value === watch('companyType'));
if (selectedCompanyType) {
- updateFormBisnis("company_type_id", `${selectedCompanyType?.value}`);
+ updateForm("company_type_id", `${selectedCompanyType?.value}`);
setSelectedCompanyId(selectedCompanyType?.label)
- validateFormBisnis();
+ validate();
}
}, [watch('companyType'), companyTypes]);
useEffect(() => {
const selectedIndustryType = industries.find(industry => industry.value === watch('industry_id'));
if (selectedIndustryType) {
- updateFormBisnis("industry_id", `${selectedIndustryType?.value}`);
+ updateForm("industry_id", `${selectedIndustryType?.value}`);
setSelectedCategory(selectedIndustryType.category);
- validateFormBisnis();
+ validate();
}
}, [watch('industry_id'), industries]);
@@ -86,14 +84,14 @@ 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',form.name);
- updateFormBisnis('email',form.email);
- updateFormBisnis('password',form.password);
- updateFormBisnis('phone',form.phone);
- validateFormBisnis();
+ updateForm('type_acc',`business`)
+ updateForm('is_pkp',`${isPKP}`)
+ updateForm(name, value);
+ updateForm('name',form.name);
+ updateForm('email',form.email);
+ updateForm('password',form.password);
+ updateForm('phone',form.phone);
+ validate();
};
const handleFileChange = async (event: ChangeEvent<HTMLInputElement>) => {
@@ -120,8 +118,8 @@ const FormBisnis: React.FC<FormProps> = ({ type, required, isPKP }) => {
}
fileBase64 = await getFileBase64(file);
}
- updateFormBisnis(name, fileBase64);
- validateFormBisnis();
+ updateForm(name, fileBase64);
+ validate();
}
};
@@ -132,12 +130,12 @@ const FormBisnis: React.FC<FormProps> = ({ type, required, isPKP }) => {
const handleSubmit = async (e: ChangeEvent<HTMLFormElement>) => {
e.preventDefault();
- const response = await mutation.mutateAsync(formBisnis);
+ const response = await mutation.mutateAsync(form);
if (response?.register === true) {
const urlParams = new URLSearchParams({
activation: 'otp',
- email: formBisnis.email,
+ email: form.email,
redirect: (router.query?.next || '/') as string
});
router.push(`${router.route}?${urlParams}`);
@@ -177,7 +175,7 @@ const FormBisnis: React.FC<FormProps> = ({ type, required, isPKP }) => {
id='email_partner'
name='email_partner'
placeholder='example@email.com'
- value={!required ? formBisnis.email_partner : ''}
+ value={!required ? form.email_partner : ''}
className={`form-input mt-3 ${required ? 'cursor-no-drop' : ''}`}
disabled={required}
contentEditable={required}
@@ -212,7 +210,7 @@ const FormBisnis: React.FC<FormProps> = ({ type, required, isPKP }) => {
className="form-input h-full "
placeholder="Nama Perusahaan"
autoCapitalize="true"
- value={formBisnis.business_name}
+ value={form.business_name}
aria-invalid={!!errors.business_name}
onChange={handleInputChange}
/>
@@ -245,7 +243,7 @@ const FormBisnis: React.FC<FormProps> = ({ type, required, isPKP }) => {
id='nama_wajib_pajak'
name='nama_wajib_pajak'
placeholder='Masukan nama lengkap anda'
- value={!required? formBisnis.nama_wajib_pajak : ''}
+ value={!required? form.nama_wajib_pajak : ''}
className={`form-input mt-3 ${required ? 'cursor-no-drop' : ''}`}
disabled={required}
contentEditable={required}
@@ -269,7 +267,7 @@ const FormBisnis: React.FC<FormProps> = ({ type, required, isPKP }) => {
contentEditable={required}
readOnly={required}
placeholder='000.000.000.0-000.000'
- value={!required ? formBisnis.npwp : ''}
+ value={!required ? form.npwp : ''}
onChange={handleInputChange}
aria-invalid={isPKP && !required && !!errors.npwp}
/>
@@ -324,4 +322,4 @@ const FormBisnis: React.FC<FormProps> = ({ type, required, isPKP }) => {
)
}
-export default FormBisnis;
+export default form;