Skip to content

Commit e5f2e6e

Browse files
committed
feat: password matching and logo
1 parent 92a45b3 commit e5f2e6e

File tree

1 file changed

+42
-13
lines changed

1 file changed

+42
-13
lines changed

src/components/Register.tsx

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
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';
33
import { register } from '../api/auth';
44
import useToken from '../hooks/token';
5+
import Label from "./utils/Label";
56

67
const Register: React.FC = () => {
78
const history = useHistory();
89
const { token, setToken } = useToken();
10+
const [status, setStatus] = useState();
11+
const [message, setMessage] = useState();
12+
913

1014
if (token) {
1115
history.push('/dashboard');
1216
}
1317
const registerUser = async (event: any) => {
1418
event.preventDefault();
1519

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+
1628
await register(
1729
event.target.name.value,
1830
event.target.email.value,
@@ -24,7 +36,7 @@ const Register: React.FC = () => {
2436
};
2537

2638
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">
2840
<div className="container mx-auto">
2941
<div className="flex justify-center px-2 py-6 ">
3042
<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 = () => {
4153
id="name"
4254
placeholder="Your name "
4355
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}
4457
/>
4558
</div>
4659
<div>
@@ -53,6 +66,7 @@ const Register: React.FC = () => {
5366
id="username"
5467
placeholder="Your Username "
5568
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}
5670
/>
5771
</div>
5872
<div className="mt-4">
@@ -81,14 +95,29 @@ const Register: React.FC = () => {
8195
<input
8296
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"
8397
id="password"
84-
type="text"
98+
type="password"
8599
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}
86117
/>
87-
{/* <p className="mt-1 text-xs italic text-black">
88-
Please fill out this field.
89-
</p> */}
90118
</div>
91119
</div>
120+
<Label status={status} message={message}/>
92121
<button
93122
type="submit"
94123
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 = () => {
98127
</form>
99128
<p className="mt-8 text-center">
100129
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>
107135
</p>
108136
</div>
109137
</div>
138+
<img className="rounded" src="https://images2.imgbox.com/ab/88/aS4VAVYc_o.png" alt="Codebench logo"/>
110139
</div>
111140
</div>
112141
</div>

0 commit comments

Comments
 (0)