From 6b221cccd58710682c99db7afbc29322da042880 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Tue, 31 Oct 2023 10:44:25 +0700 Subject: - Add redirect after activation - Add register form validation --- src-migrate/modules/register/components/Form.tsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src-migrate/modules/register/components/Form.tsx') diff --git a/src-migrate/modules/register/components/Form.tsx b/src-migrate/modules/register/components/Form.tsx index 3227a549..5b51d6f4 100644 --- a/src-migrate/modules/register/components/Form.tsx +++ b/src-migrate/modules/register/components/Form.tsx @@ -8,6 +8,7 @@ import FormCaptcha from "./FormCaptcha"; import { useRouter } from "next/router"; import { UseToastOptions, useToast } from "@chakra-ui/react"; import Link from "next/link"; +import { registerSchema } from "~/common/validations/auth"; const Form = () => { const { @@ -15,7 +16,9 @@ const Form = () => { isValid, isCheckedTNC, isValidCaptcha, + errors, updateForm, + validate, } = useRegisterStore() const router = useRouter() const toast = useToast() @@ -23,6 +26,7 @@ const Form = () => { const handleInputChange = (event: ChangeEvent) => { const { name, value } = event.target; updateForm(name, value) + validate() } const mutation = useMutation({ @@ -37,7 +41,8 @@ const Form = () => { if (response?.register === true) { const urlParams = new URLSearchParams({ activation: 'otp', - email: form.email + email: form.email, + redirect: (router.query?.next || '/') as string }) router.push(`${router.route}?${urlParams}`) } @@ -97,7 +102,10 @@ const Form = () => { placeholder='Masukan nama lengkap anda' value={form.name} onChange={handleInputChange} + aria-invalid={!!errors.name} /> + + {!!errors.name && {errors.name}}
@@ -111,7 +119,10 @@ const Form = () => { placeholder='08xxxxxxxx' value={form.phone} onChange={handleInputChange} + aria-invalid={!!errors.phone} /> + + {!!errors.phone && {errors.phone}}
@@ -126,7 +137,10 @@ const Form = () => { value={form.email} onChange={handleInputChange} autoComplete="username" + aria-invalid={!!errors.email} /> + + {!!errors.email && {errors.email}}
@@ -140,7 +154,10 @@ const Form = () => { value={form.password} onChange={handleInputChange} autoComplete="current-password" + aria-invalid={!!errors.password} /> + + {!!errors.password && {errors.password}}
-- cgit v1.2.3