summaryrefslogtreecommitdiff
path: root/src-migrate/modules/register
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-09-23 09:22:29 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-09-23 09:22:29 +0700
commitc13bb5c6f78032695b24cf8a6c23942eb465c6d5 (patch)
treee48c1ab39a61fd5702f578fbfdb7a7375cc1ce43 /src-migrate/modules/register
parent870bede9df9920b23f2e5cb771ff5ae6448e3ac7 (diff)
parent4bd29979c34c1ec3b31dd384829b008eb726769c (diff)
Merge branch 'Feature/new-register' into Feature/switch-account
Diffstat (limited to 'src-migrate/modules/register')
-rw-r--r--src-migrate/modules/register/components/Form.tsx57
-rw-r--r--src-migrate/modules/register/components/FormBisnis.tsx73
-rw-r--r--src-migrate/modules/register/index.tsx7
3 files changed, 24 insertions, 113 deletions
diff --git a/src-migrate/modules/register/components/Form.tsx b/src-migrate/modules/register/components/Form.tsx
index cd0b4343..38e9c810 100644
--- a/src-migrate/modules/register/components/Form.tsx
+++ b/src-migrate/modules/register/components/Form.tsx
@@ -41,15 +41,9 @@ const Form: React.FC<FormProps> = ({
updateForm(name, value);
validate();
};
-
- const mutation = useMutation({
- mutationFn: (data: RegisterProps) => registerUser(data),
- });
-
useEffect(() => {
const loadIndustries = async () => {
- const response = await mutation.mutateAsync(form);
- if (!response?.register) {
+ if (!isFormValid) {
const options: ScrollIntoViewOptions = {
behavior: 'smooth',
block: 'center',
@@ -78,55 +72,8 @@ const Form: React.FC<FormProps> = ({
loadIndustries();
}, [buttonSubmitClick, chekValid]);
- const handleSubmit = async (e: ChangeEvent<HTMLFormElement>) => {
- e.preventDefault();
-
- const response = await mutation.mutateAsync(form);
-
- 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,
- position: 'top',
- };
-
- 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 (
- <form className='mt-6 grid grid-cols-1 gap-y-4' onSubmit={handleSubmit}>
+ <form className='mt-6 grid grid-cols-1 gap-y-4'>
<div>
<label htmlFor='name' className='text-black font-bold'>
Nama Lengkap
diff --git a/src-migrate/modules/register/components/FormBisnis.tsx b/src-migrate/modules/register/components/FormBisnis.tsx
index b81ca601..88a2f0b0 100644
--- a/src-migrate/modules/register/components/FormBisnis.tsx
+++ b/src-migrate/modules/register/components/FormBisnis.tsx
@@ -128,9 +128,23 @@ const form: React.FC<FormProps> = ({
const handleInputChange = (event: ChangeEvent<HTMLInputElement>) => {
const { name, value } = event.target;
- updateForm('type_acc', `business`);
+
+ updateForm('type_acc', 'business');
updateForm('is_pkp', `${isPKP}`);
+
+ // Update form dengan nilai terbaru dari input yang berubah
updateForm(name, value);
+
+ // Jika checkbox aktif, sinkronisasi alamat_wajib_pajak dengan alamat_bisnis
+ if (isChekBox) {
+ if (name === 'alamat_wajib_pajak') {
+ updateForm('alamat_bisnis', value);
+ } else if (name === 'alamat_bisnis') {
+ updateForm('alamat_wajib_pajak', value);
+ }
+ }
+
+ // Validasi setelah perubahan dilakukan
validate();
};
@@ -188,6 +202,7 @@ const form: React.FC<FormProps> = ({
useEffect(() => {
if (isChekBox) {
updateForm('isChekBox', 'true');
+ updateForm('alamat_wajib_pajak', `${form.alamat_bisnis}`);
validate();
} else {
updateForm('isChekBox', 'false');
@@ -241,15 +256,11 @@ const form: React.FC<FormProps> = ({
validate(); // Perform form validation
}
};
-
- const mutation = useMutation({
- mutationFn: (data: RegisterProps) => registerUser(data),
- });
+ const isFormValid = useMemo(() => Object.keys(errors).length === 0, [errors]);
useEffect(() => {
const loadIndustries = async () => {
- const response = await mutation.mutateAsync(form);
- if (!response?.register) {
+ if (!isFormValid) {
const options: ScrollIntoViewOptions = {
behavior: 'smooth',
block: 'center',
@@ -299,53 +310,6 @@ const form: React.FC<FormProps> = ({
};
loadIndustries();
}, [buttonSubmitClick, chekValid]);
-
- const handleSubmit = async (e: ChangeEvent<HTMLFormElement>) => {
- e.preventDefault();
-
- const response = await mutation.mutateAsync(form);
-
- 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,
- position: 'top',
- };
-
- 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 (
<>
<BottomPopup
@@ -371,7 +335,6 @@ const form: React.FC<FormProps> = ({
? 'mt-6 grid grid-cols-1 gap-y-4'
: 'mt-6 grid grid-cols-2 gap-x-4 gap-y-6 auto-rows-min'
}`}
- onSubmit={handleSubmit}
>
<div>
<label htmlFor='email' className='font-bold'>
diff --git a/src-migrate/modules/register/index.tsx b/src-migrate/modules/register/index.tsx
index 08d7f893..da41fd8b 100644
--- a/src-migrate/modules/register/index.tsx
+++ b/src-migrate/modules/register/index.tsx
@@ -161,7 +161,7 @@ const Register = () => {
)}
</div>
<section className='mt-2'>
- {/* <FormCaptcha /> */}
+ <FormCaptcha />
<TermCondition />
<Button
type='submit'
@@ -169,8 +169,9 @@ const Register = () => {
className='w-full mt-2'
size='lg'
onClick={handleSubmit}
- // isDisabled = {!isFormValid || !isCheckedTNC || mutation.isLoading || !isValidCaptcha}
- isDisabled={!isCheckedTNC || mutation.isLoading}
+ isDisabled={
+ !isCheckedTNC || mutation.isLoading || !isValidCaptcha
+ }
>
{mutation.isLoading ? 'Loading...' : 'Daftar'}
</Button>