@@ -4,17 +4,23 @@ import Label from "@/components/form/Label";
44import { ChevronLeftIcon , EyeCloseIcon , EyeIcon } from "@/icons" ;
55import Link from "next/link" ;
66import React , { useState } from "react" ;
7- import { namePattern , passwordRules } from "@/utils" ;
7+ import { namePattern , emailPattern , passwordRules } from "@/utils" ;
88import { useForm } from "react-hook-form" ;
9+ import { useSignup } from "@/hooks/useSignup" ;
10+ import SpinnerButton from "../ui/button/SpinnerButton" ;
11+
912
1013type FormData = {
1114 firstName : string ;
1215 lastName : string ;
1316 password : string ;
17+ email : string ;
1418} ;
1519
1620export default function SignUpForm ( ) {
1721 const [ showPassword , setShowPassword ] = useState ( false ) ;
22+ const signupMutation = useSignup ( ) ;
23+
1824 const {
1925 register,
2026 handleSubmit,
@@ -24,6 +30,23 @@ export default function SignUpForm() {
2430 } ) ;
2531 const onSubmit = ( data : FormData ) => {
2632 console . log ( "Form data:" , data ) ;
33+ signupMutation . mutate (
34+ {
35+ requestBody : {
36+ full_name : data . firstName + " " + data . lastName ,
37+ password : data . password ,
38+ email : data . email ,
39+ } ,
40+ } ,
41+ {
42+ onSuccess : ( res ) => {
43+ console . log ( "Signup success:" , res ) ;
44+ } ,
45+ onError : ( err ) => {
46+ console . error ( "Signup failed:" , err ) ;
47+ } ,
48+ }
49+ ) ;
2750 } ;
2851
2952 return (
@@ -34,7 +57,7 @@ export default function SignUpForm() {
3457 className = "inline-flex items-center text-sm text-gray-500 transition-colors hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300"
3558 >
3659 < ChevronLeftIcon />
37- Back to dashboard
60+ Back to home
3861 </ Link >
3962 </ div >
4063
@@ -81,7 +104,22 @@ export default function SignUpForm() {
81104 hint = { errors . lastName ?. message }
82105 />
83106 </ div >
84-
107+ { /* Email */ }
108+ < div className = "sm:col-span-2" >
109+ < Label >
110+ Email< span className = "text-error-500" > *</ span >
111+ </ Label >
112+ < Input
113+ placeholder = "Enter your email"
114+ type = "email"
115+ { ...register ( "email" , {
116+ required : "Email is required" ,
117+ pattern : emailPattern
118+ } ) }
119+ error = { ! ! errors . email }
120+ hint = { errors . email ?. message }
121+ />
122+ </ div >
85123 { /* Password */ }
86124 < div className = "sm:col-span-2" >
87125 < Label >
@@ -107,19 +145,18 @@ export default function SignUpForm() {
107145 </ span >
108146 </ div >
109147 </ div >
110-
111148 { /* Submit Button */ }
112149 < div className = "sm:col-span-2" >
113- < button
114- type = "submit"
150+ < SpinnerButton
115151 className = "flex items-center justify-center w-full px-4 py-3 text-sm font-medium text-white transition rounded-lg bg-brand-500 shadow-theme-xs hover:bg-brand-600"
152+ disabled = { signupMutation . isPending }
153+ loading = { signupMutation . isPending }
116154 >
117155 Sign Up
118- </ button >
156+ </ SpinnerButton >
119157 </ div >
120158 </ div >
121159 </ form >
122-
123160 < div className = "mt-5" >
124161 < p className = "text-sm font-normal text-center text-gray-700 dark:text-gray-400 sm:text-start" >
125162 Already have an account?{ " " }
0 commit comments