From 6ff5efdb4b7eec25f991f5bfcc02b4a3f883981b Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 11 Sep 2024 10:04:31 +0700 Subject: update error handling hanya muncul saat button daftar di click --- .../register/components/RegistrasiBisnis.tsx | 190 ++++++++++++--------- 1 file changed, 108 insertions(+), 82 deletions(-) (limited to 'src-migrate/modules/register/components/RegistrasiBisnis.tsx') diff --git a/src-migrate/modules/register/components/RegistrasiBisnis.tsx b/src-migrate/modules/register/components/RegistrasiBisnis.tsx index 1d8317f1..36476ab9 100644 --- a/src-migrate/modules/register/components/RegistrasiBisnis.tsx +++ b/src-migrate/modules/register/components/RegistrasiBisnis.tsx @@ -1,67 +1,60 @@ -import { ChangeEvent, useEffect, useMemo, useState } from "react"; -import FormBisnis from "./FormBisnis"; -import Form from "./Form"; -import TermCondition from "./TermCondition"; -import FormCaptcha from "./FormCaptcha"; -import { Radio, RadioGroup, Stack, Divider, Button } from '@chakra-ui/react' -import React from "react"; -import { - ChevronDownIcon, - ChevronRightIcon -} from '@heroicons/react/24/outline'; -import { useRegisterStore } from "../stores/useRegisterStore"; -import { useMutation } from "react-query"; -import { RegisterProps } from "~/types/auth"; -import { registerUser } from "~/services/auth"; -import router from "next/router"; -import { useRouter } from "next/router"; -import { UseToastOptions, useToast } from "@chakra-ui/react"; -import Link from "next/link"; - -const RegistrasiBisnis = () => { +import { ChangeEvent, useEffect, useMemo, useState } from 'react'; +import FormBisnis from './FormBisnis'; +import Form from './Form'; +import TermCondition from './TermCondition'; +import FormCaptcha from './FormCaptcha'; +import { Radio, RadioGroup, Stack, Divider, Button } from '@chakra-ui/react'; +import React from 'react'; +import { ChevronDownIcon, ChevronRightIcon } from '@heroicons/react/24/outline'; +import { useRegisterStore } from '../stores/useRegisterStore'; +import { useMutation } from 'react-query'; +import { RegisterProps } from '~/types/auth'; +import { registerUser } from '~/services/auth'; +import router from 'next/router'; +import { useRouter } from 'next/router'; +import { UseToastOptions, useToast } from '@chakra-ui/react'; +import Link from 'next/link'; +interface FormProps { + chekValid: boolean; +} +const RegistrasiBisnis: React.FC = ({ chekValid }) => { const [isPKP, setIsPKP] = useState(true); const [isTerdaftar, setIsTerdaftar] = useState(false); const [isDropIndividu, setIsDropIndividu] = useState(true); const [isBisnisClicked, setisBisnisClicked] = useState(true); const [selectedValue, setSelectedValue] = useState('PKP'); const [selectedValueBisnis, setSelectedValueBisnis] = useState('false'); - const { - form, - isCheckedTNC, - isValidCaptcha, - errors, - validate, - updateForm - } = useRegisterStore() - const isFormValid = useMemo(() => Object.keys(errors).length === 0, [errors]) - const toast = useToast() + const { form, isCheckedTNC, isValidCaptcha, errors, validate, updateForm } = + useRegisterStore(); + const isFormValid = useMemo(() => Object.keys(errors).length === 0, [errors]); + const toast = useToast(); const mutation = useMutation({ - mutationFn: (data: RegisterProps) => registerUser(data) - }) + mutationFn: (data: RegisterProps) => registerUser(data), + }); useEffect(() => { - if (selectedValue === "PKP") { - updateForm("is_pkp", 'true'); + if (selectedValue === 'PKP') { + updateForm('is_pkp', 'true'); validate(); } else { - updateForm("is_pkp", 'false'); + updateForm('is_pkp', 'false'); validate(); } - }, [selectedValue,]); - + }, [selectedValue]); + useEffect(() => { if (isTerdaftar) { - updateForm("is_terdaftar", 'true'); + updateForm('is_terdaftar', 'true'); validate(); } else { - updateForm("is_terdaftar", 'false'); + updateForm('is_terdaftar', 'false'); validate(); } - }, [isTerdaftar,]); + }, [isTerdaftar]); - const handleChange = (value: string) => { + const handleChange = (value: string) => { setSelectedValue(value); - if (value === "PKP") { + if (value === 'PKP') { validate(); setIsPKP(true); } else { @@ -70,10 +63,10 @@ const RegistrasiBisnis = () => { setIsPKP(false); } }; - + const handleChangeBisnis = (value: string) => { setSelectedValueBisnis(value); - if (value === "true") { + if (value === 'true') { validate(); setIsTerdaftar(true); } else { @@ -83,81 +76,114 @@ const RegistrasiBisnis = () => { }; const handleClick = () => { - setIsDropIndividu(!isDropIndividu) + setIsDropIndividu(!isDropIndividu); }; const handleClickBisnis = () => { - setisBisnisClicked(!isBisnisClicked) + setisBisnisClicked(!isBisnisClicked); }; return ( <> - -
-
-
-

+

+
+
+

Data Akun

{isDropIndividu ? ( -
- +
+
) : ( - + )}
{isDropIndividu && (
- -
+ +
)}
-
-
-
-

+

+
+
+

Data Bisnis

{isBisnisClicked ? ( -
- +
+
) : ( - + )}
{isBisnisClicked && (
- +
-

Bisnis Terdaftar di Indoteknik?

- +

+ Bisnis Terdaftar di Indoteknik? +

+ - Sudah Terdaftar - Belum Terdaftar + + Sudah Terdaftar + + + Belum Terdaftar +
-
-

Tipe Bisnis

- - - PKP - Non-PKP - - -
- +
+

Tipe Bisnis

+ + + + PKP + + + Non-PKP + + + +
+
)}
- -

- + +

); }; -- cgit v1.2.3