@@ -7,15 +7,28 @@ import {
77 TextInput ,
88 Title ,
99} from "@mantine/core" ;
10- import { useForm } from "@mantine/form" ;
10+ import { useForm , zodResolver } from "@mantine/form" ;
11+ import { z } from "zod" ;
1112
12- export type SignupFields = {
13- name : string ;
14- committee : string ;
15- email : string ;
16- password : string ;
17- confirmPassword : string ;
18- } ;
13+ const schema = z
14+ . object ( {
15+ name : z . string ( ) . nonempty ( { message : "Required" } ) ,
16+ committee : z . string ( ) . nonempty ( { message : "Required" } ) ,
17+ email : z . string ( ) . email ( ) . nonempty ( { message : "Required" } ) ,
18+ password : z . string ( ) . min ( 6 ) ,
19+ confirmPassword : z . string ( ) . nonempty ( { message : "Required" } ) ,
20+ } )
21+ . superRefine ( ( { confirmPassword, password } , ctx ) => {
22+ if ( confirmPassword !== password ) {
23+ ctx . addIssue ( {
24+ code : "custom" ,
25+ message : "Password did not match" ,
26+ path : [ "confirmPassword" ] ,
27+ } ) ;
28+ }
29+ } ) ;
30+
31+ export type SignupFields = z . infer < typeof schema > ;
1932
2033type Props = {
2134 onSubmit : ( f : SignupFields ) => void ;
@@ -32,12 +45,14 @@ const Signup = (props: Props) => {
3245 password : "" ,
3346 confirmPassword : "" ,
3447 } ,
48+
49+ validate : zodResolver ( schema ) ,
3550 } ) ;
3651
3752 return (
3853 < Stack m = "md" w = "50%" >
3954 < Title order = { 1 } > Welcome,</ Title >
40- < form onSubmit = { ( ) => onSubmit ( form . values ) } >
55+ < form onSubmit = { form . onSubmit ( ( values ) => onSubmit ( values ) ) } >
4156 < TextInput
4257 withAsterisk
4358 label = "Name"
0 commit comments