1
1
'use client' ;
2
2
import { ChangeEvent , useState } from 'react' ;
3
+ import { getMailValidation } from '@/helpers/validators' ;
3
4
import Input from '@/components/Inputs/TextInput' ;
4
5
5
6
type RegistrationFormData = {
@@ -25,75 +26,86 @@ export default function Registration() {
25
26
const { name, value } = e . target ;
26
27
setFormData ( ( prevFormData ) => ( { ...prevFormData , [ name ] : value } ) ) ;
27
28
} ;
29
+
30
+ const handlePwValidation = ( ) : string | undefined => {
31
+ if ( formData . passwordConfirm !== formData . password ) return 'Passwords should match' ;
32
+ return undefined ;
33
+ } ;
34
+
28
35
return (
29
- < div className = "grid grid-cols-1 xl:grid-cols-2 xl:gap-8" >
30
- < form className = "flex flex-col items-stretch gap-4" >
31
- < Input
32
- type = "text"
33
- label = "Username"
34
- name = "username"
35
- id = "username"
36
- value = { formData . username }
37
- onChange = { handleInputChange }
38
- required
39
- />
40
- < div className = "grid grid-cols-1 xl:grid-cols-2 xl:gap-3" >
36
+ < div >
37
+ < h1 className = "h3" > My Account</ h1 >
38
+ < div className = "grid grid-cols-1 xl:grid-cols-2 xl:gap-8" >
39
+ < form className = "flex flex-col items-stretch gap-4" >
41
40
< Input
42
41
type = "text"
43
- label = "First Name "
44
- name = "firstname "
45
- id = "firstname "
46
- value = { formData . firstname }
42
+ label = "Username "
43
+ name = "username "
44
+ id = "username "
45
+ value = { formData . username }
47
46
onChange = { handleInputChange }
48
47
required
49
48
/>
49
+ < div className = "grid grid-cols-1 xl:grid-cols-2 xl:gap-3" >
50
+ < Input
51
+ type = "text"
52
+ label = "First Name"
53
+ name = "firstname"
54
+ id = "firstname"
55
+ value = { formData . firstname }
56
+ onChange = { handleInputChange }
57
+ required
58
+ />
59
+ < Input
60
+ type = "text"
61
+ label = "Last Name"
62
+ name = "lastname"
63
+ id = "lastname"
64
+ value = { formData . lastname }
65
+ onChange = { handleInputChange }
66
+ required
67
+ />
68
+ </ div >
50
69
< Input
51
70
type = "text"
52
- label = "Last Name "
53
- name = "lastname "
54
- id = "lastname "
55
- value = { formData . lastname }
71
+ label = "Email Address "
72
+ name = "email "
73
+ id = "email "
74
+ value = { formData . email }
56
75
onChange = { handleInputChange }
57
76
required
77
+ validate = { ( value ) => getMailValidation ( value ) }
58
78
/>
59
- </ div >
60
- < Input
61
- type = "text"
62
- label = "Email Address"
63
- name = "email"
64
- id = "email"
65
- value = { formData . email }
66
- onChange = { handleInputChange }
67
- required
68
- />
69
- < Input
70
- type = "password"
71
- label = "Password"
72
- name = "password"
73
- id = "password"
74
- value = { formData . password }
75
- onChange = { handleInputChange }
76
- required
77
- />
78
- < Input
79
- type = "password"
80
- label = "Confirm Password"
81
- name = "passwordConfirm"
82
- id = "passwordConfirm"
83
- value = { formData . passwordConfirm }
84
- onChange = { handleInputChange }
85
- required
86
- />
87
- < input className = "btn ml-auto hover:cursor-pointer" type = "submit" value = "Register" />
88
- </ form >
89
- < div >
90
- < h2 className = "text-secondary" > Please note</ h2 >
79
+ < Input
80
+ type = "password"
81
+ label = "Password"
82
+ name = "password"
83
+ id = "password"
84
+ value = { formData . password }
85
+ onChange = { handleInputChange }
86
+ required
87
+ />
88
+ < Input
89
+ type = "password"
90
+ label = "Confirm Password"
91
+ name = "passwordConfirm"
92
+ id = "passwordConfirm"
93
+ value = { formData . passwordConfirm }
94
+ onChange = { handleInputChange }
95
+ required
96
+ validate = { handlePwValidation }
97
+ />
98
+ < input className = "btn ml-auto hover:cursor-pointer" type = "submit" value = "Register" />
99
+ </ form >
100
+ < div >
101
+ < h2 className = "text-secondary" > Please note</ h2 >
91
102
92
- < p >
93
- Lorem ipsum dolor sit amet consectetur adipisicing elit. Vel est adipisci quas, aperiam voluptas,
94
- omnis tempora blanditiis quae fuga eum ullam commodi a perspiciatis provident pariatur sunt
95
- excepturi doloremque! Commodi!
96
- </ p >
103
+ < p >
104
+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Vel est adipisci quas, aperiam
105
+ voluptas, omnis tempora blanditiis quae fuga eum ullam commodi a perspiciatis provident pariatur
106
+ sunt excepturi doloremque! Commodi!
107
+ </ p >
108
+ </ div >
97
109
</ div >
98
110
</ div >
99
111
) ;
0 commit comments