diff --git a/client/src/Pages/v2/Auth/Register.tsx b/client/src/Pages/v2/Auth/Register.tsx new file mode 100644 index 000000000..a9043a2c9 --- /dev/null +++ b/client/src/Pages/v2/Auth/Register.tsx @@ -0,0 +1,169 @@ +import { zodResolver } from "@hookform/resolvers/zod"; +import { z } from "zod"; +import { useTranslation } from "react-i18next"; +import { useForm, Controller } from "react-hook-form"; +import { useTheme } from "@mui/material/styles"; +import Typography from "@mui/material/Typography"; + +import { TextInput } from "@/Components/Inputs/TextInput/indexV2.tsx"; +import Button from "@mui/material/Button"; +import Stack from "@mui/material/Stack"; +import { usePost } from "@/Hooks/v2/UseApi"; + +const schema = z + .object({ + email: z.email({ message: "Invalid email address" }), + firstName: z.string().min(1, { message: "First Name is required" }), + lastName: z.string().min(1, { message: "Last Name is required" }), + password: z.string().min(6, { message: "Password must be at least 6 characters" }), + confirmPassword: z + .string() + .min(6, { message: "Confirm Password must be at least 6 characters" }), + }) + .refine((data) => data.password === data.confirmPassword, { + path: ["confirmPassword"], + message: "Passwords must match", + }); + +type FormData = z.infer; + +const Register = () => { + const { t } = useTranslation(); + const theme = useTheme(); + const { post, loading, error } = usePost("/auth/register"); + + const { + handleSubmit, + control, + formState: { errors }, + } = useForm({ + resolver: zodResolver(schema), // ⬅️ connect Zod + defaultValues: { + email: "", + password: "", + }, + }); + + const onSubmit = async (data: FormData) => { + const result = await post(data); + if (result) { + console.log(result); + } else { + console.error("Login failed:", error); + } + }; + + return ( + + + ( + + )} + /> + ( + + )} + /> + ( + + )} + /> + ( + + )} + /> + ( + + )} + /> + + {error && {error}} + + + ); +}; + +export default Register; diff --git a/client/src/Routes/index.jsx b/client/src/Routes/index.jsx index 06a4b1920..39959bc1c 100644 --- a/client/src/Routes/index.jsx +++ b/client/src/Routes/index.jsx @@ -8,6 +8,7 @@ import NotFound from "../Pages/v1/NotFound"; import AuthLogin from "../Pages/v1/Auth/Login"; import AuthLoginV2 from "@/Pages/v2/Auth/Login"; import AuthRegister from "../Pages/v1/Auth/Register/"; +import AuthRegisterV2 from "@/Pages/v2/Auth/Register"; import AuthForgotPassword from "../Pages/v1/Auth/ForgotPassword"; import AuthCheckEmail from "../Pages/v1/Auth/CheckEmail"; import AuthSetNewPassword from "../Pages/v1/Auth/SetNewPassword"; @@ -232,6 +233,14 @@ const Routes = () => { path="/register" element={} /> + + + + } + />