From 3f23b60c9d6c8bbf98576f41f72de66d322b5de4 Mon Sep 17 00:00:00 2001 From: ngc2207 Date: Fri, 31 Jan 2025 16:42:12 +0800 Subject: [PATCH] feat(ui): implement sign-in/sign-up form with validation --- src/features/auth/components/sign-in-card.tsx | 23 +++++++------- src/features/auth/components/sign-up-card.tsx | 30 +++++++++++-------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/features/auth/components/sign-in-card.tsx b/src/features/auth/components/sign-in-card.tsx index 3680e4a..6817021 100644 --- a/src/features/auth/components/sign-in-card.tsx +++ b/src/features/auth/components/sign-in-card.tsx @@ -7,31 +7,32 @@ import { FormItem, FormMessage, } from "@/components/ui/form"; +import { loginSchema } from "../schema"; import { FcGoogle } from "react-icons/fc"; import { FaGithub } from "react-icons/fa"; import { useForm } from "react-hook-form"; +import { useLogin } from "../api/use-login"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import { zodResolver } from "@hookform/resolvers/zod"; import { Separator } from "@/components/ui/separator"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; -const formSchema = z.object({ - email: z.string().email(), - password: z.string().min(1, "Required"), -}); - export const SignInCard = () => { - const form = useForm>({ - resolver: zodResolver(formSchema), + const { mutate } = useLogin(); + + const form = useForm>({ + resolver: zodResolver(loginSchema), defaultValues: { email: "", password: "", }, }); - const onSubmit = (values: z.infer) => { - console.log({ values }); + const onSubmit = (values: z.infer) => { + mutate({ + json: values, + }); }; return ( @@ -113,7 +114,9 @@ export const SignInCard = () => {

Don't have an account?{" "} - Sign Up + + Sign Up +

diff --git a/src/features/auth/components/sign-up-card.tsx b/src/features/auth/components/sign-up-card.tsx index 9ec130f..7f23060 100644 --- a/src/features/auth/components/sign-up-card.tsx +++ b/src/features/auth/components/sign-up-card.tsx @@ -17,20 +17,18 @@ import { import { FcGoogle } from "react-icons/fc"; import { FaGithub } from "react-icons/fa"; import { useForm } from "react-hook-form"; +import { registerSchema } from "../schema"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; +import { useRegister } from "../api/use-register"; import { Separator } from "@/components/ui/separator"; import { zodResolver } from "@hookform/resolvers/zod"; -const formSchema = z.object({ - name: z.string().trim().min(1, "Required"), - email: z.string().email(), - password: z.string().min(8, "Minimum of 8 characters required"), -}); - export const SignUpCard = () => { - const form = useForm>({ - resolver: zodResolver(formSchema), + const { mutate } = useRegister(); + + const form = useForm>({ + resolver: zodResolver(registerSchema), defaultValues: { name: "", email: "", @@ -38,8 +36,8 @@ export const SignUpCard = () => { }, }); - const onSubmit = (values: z.infer) => { - console.log({ values }); + const onSubmit = (values: z.infer) => { + mutate({ json: values }); }; return ( @@ -49,11 +47,15 @@ export const SignUpCard = () => { By signing up, you're giving a nod to our{" "} - Privacy Policy + + Privacy Policy + {" "} and{" "} - Terms of service + + Terms of service + @@ -147,7 +149,9 @@ export const SignUpCard = () => {

Already have an account?{" "} - Sign In + + Sign In +