summaryrefslogtreecommitdiff
path: root/src-migrate/modules/register/components/Form.tsx
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-11-10 14:47:52 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-11-10 14:47:52 +0700
commit4bed066c03dc55a8f811ff2e23e019d8adc64495 (patch)
tree7c8d9335015ec7cad07c7e2385de3bf19cf3ce42 /src-migrate/modules/register/components/Form.tsx
parent94c1fba12e054165e7447e9cf778dd7de8922304 (diff)
Refactor register form
Diffstat (limited to 'src-migrate/modules/register/components/Form.tsx')
-rw-r--r--src-migrate/modules/register/components/Form.tsx10
1 files changed, 7 insertions, 3 deletions
diff --git a/src-migrate/modules/register/components/Form.tsx b/src-migrate/modules/register/components/Form.tsx
index 5b51d6f4..ddc3397f 100644
--- a/src-migrate/modules/register/components/Form.tsx
+++ b/src-migrate/modules/register/components/Form.tsx
@@ -1,4 +1,4 @@
-import { ChangeEvent, useEffect } from "react";
+import { ChangeEvent, useEffect, useMemo } from "react";
import { useMutation } from "react-query";
import { useRegisterStore } from "~/common/stores/useRegisterStore";
import { RegisterProps } from "~/common/types/auth";
@@ -13,13 +13,17 @@ import { registerSchema } from "~/common/validations/auth";
const Form = () => {
const {
form,
- isValid,
isCheckedTNC,
isValidCaptcha,
errors,
updateForm,
validate,
} = useRegisterStore()
+
+ const isFormValid = useMemo(() => {
+ return Object.keys(errors).length === 0
+ }, [errors])
+
const router = useRouter()
const toast = useToast()
@@ -167,7 +171,7 @@ const Form = () => {
<button
type="submit"
className="btn-yellow w-full mt-2"
- disabled={!isValid || !isCheckedTNC || mutation.isLoading || !isValidCaptcha}
+ disabled={!isFormValid || !isCheckedTNC || mutation.isLoading || !isValidCaptcha}
>
{mutation.isLoading ? 'Loading...' : 'Daftar'}
</button>