1
- import React from 'react' ;
2
- import { useHistory } from 'react-router-dom' ;
1
+ import React , { useState } from 'react' ;
2
+ import { Link , useHistory } from 'react-router-dom' ;
3
3
import { register } from '../api/auth' ;
4
4
import useToken from '../hooks/token' ;
5
+ import Label from "./utils/Label" ;
5
6
6
7
const Register : React . FC = ( ) => {
7
8
const history = useHistory ( ) ;
8
9
const { token, setToken } = useToken ( ) ;
10
+ const [ status , setStatus ] = useState ( ) ;
11
+ const [ message , setMessage ] = useState ( ) ;
12
+
9
13
10
14
if ( token ) {
11
15
history . push ( '/dashboard' ) ;
12
16
}
13
17
const registerUser = async ( event : any ) => {
14
18
event . preventDefault ( ) ;
15
19
20
+ if ( event . target . password !== event . target . passwordConfirmed ) {
21
+ // @ts -ignore
22
+ setMessage ( "Passwords doesn't match" ) ;
23
+ // @ts -ignore
24
+ setStatus ( 'Error' ) ;
25
+ return
26
+ }
27
+
16
28
await register (
17
29
event . target . name . value ,
18
30
event . target . email . value ,
@@ -24,7 +36,7 @@ const Register: React.FC = () => {
24
36
} ;
25
37
26
38
return (
27
- < section className = "flex flex-col items-center h-screen md:flex-row" >
39
+ < section className = "flex min-h-screen flex-col items-center h-screen md:flex-row" >
28
40
< div className = "container mx-auto" >
29
41
< div className = "flex justify-center px-2 py-6 " >
30
42
< div className = "flex w-full rounded-lg xl:w-3/4 lg:w-11/12 lg:shadow-xl " >
@@ -41,6 +53,7 @@ const Register: React.FC = () => {
41
53
id = "name"
42
54
placeholder = "Your name "
43
55
className = "w-full px-4 py-2 mt-2 text-base transition duration-500 ease-in-out transform border-transparent rounded-lg bg-blueGray-100 focus:outline-none focus:shadow-outline focus:ring-2 ring-offset-current ring-offset-2 ext-black focus:border-blueGray-500"
56
+ required = { true }
44
57
/>
45
58
</ div >
46
59
< div >
@@ -53,6 +66,7 @@ const Register: React.FC = () => {
53
66
id = "username"
54
67
placeholder = "Your Username "
55
68
className = "w-full px-4 py-2 mt-2 text-base transition duration-500 ease-in-out transform border-transparent rounded-lg bg-blueGray-100 focus:outline-none focus:shadow-outline focus:ring-2 ring-offset-current ring-offset-2 ext-black focus:border-blueGray-500"
69
+ required = { true }
56
70
/>
57
71
</ div >
58
72
< div className = "mt-4" >
@@ -81,14 +95,29 @@ const Register: React.FC = () => {
81
95
< input
82
96
className = "block w-full px-4 py-2 mt-2 text-base text-black transition duration-500 ease-in-out transform border-transparent rounded-lg bg-blueGray-100 focus:outline-none focus:shadow-outline focus:ring-2 ring-offset-current ring-offset-2 ext-black focus:border-blueGray-500"
83
97
id = "password"
84
- type = "text "
98
+ type = "password "
85
99
placeholder = "Your Password"
100
+ required = { true }
101
+ />
102
+ </ div >
103
+ < div className = "w-full px-3 mb-6 md:w-1/2 md:mb-0" >
104
+ < label
105
+ className = "text-base font-medium leading-relaxed text-blueGray-700"
106
+ htmlFor = "password"
107
+ >
108
+ { ' ' }
109
+ Confirm password{ ' ' }
110
+ </ label >
111
+ < input
112
+ className = "block w-full px-4 py-2 mt-2 text-base text-black transition duration-500 ease-in-out transform border-transparent rounded-lg bg-blueGray-100 focus:outline-none focus:shadow-outline focus:ring-2 ring-offset-current ring-offset-2 ext-black focus:border-blueGray-500"
113
+ id = "passwordConfirmed"
114
+ type = "password"
115
+ placeholder = "Confirm Your Password"
116
+ required = { true }
86
117
/>
87
- { /* <p className="mt-1 text-xs italic text-black">
88
- Please fill out this field.
89
- </p> */ }
90
118
</ div >
91
119
</ div >
120
+ < Label status = { status } message = { message } />
92
121
< button
93
122
type = "submit"
94
123
className = "block w-full px-4 py-3 mt-6 font-semibold text-white transition duration-500 ease-in-out transform rounded-lg bg-gradient-to-r from-black hover:from-black to-black focus:outline-none focus:shadow-outline focus:ring-2 ring-offset-current ring-offset-2 hover:to-black"
@@ -98,15 +127,15 @@ const Register: React.FC = () => {
98
127
</ form >
99
128
< p className = "mt-8 text-center" >
100
129
Already have an account?{ ' ' }
101
- < a
102
- href = "#"
103
- className = "font-semibold text-black hover:text-black"
104
- >
105
- Sign In
106
- </ a >
130
+ < Link
131
+ className = "font-semibold text-black hover:text-black"
132
+ to = "/login"
133
+ > Sign In
134
+ </ Link >
107
135
</ p >
108
136
</ div >
109
137
</ div >
138
+ < img className = "rounded" src = "https://images2.imgbox.com/ab/88/aS4VAVYc_o.png" alt = "Codebench logo" />
110
139
</ div >
111
140
</ div >
112
141
</ div >
0 commit comments