Newer
Older

Cross, Liam (UG - Comp Sci & Elec Eng)
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { useForm } from 'react-hook-form';
import { useState } from 'react';
import './Register.scss';
interface IRegister {
name: string;
email: string;
password: string;
confirmPassword: string;
}
export function Register() {
const [error, setError] = useState('');
const { register, handleSubmit } = useForm<IRegister>({mode: 'onChange'});
const onSubmit = (formValue: IRegister) => {
if (formValue.password.length < 7) {
setError('password length must be greater than 6 characters');
return;
}
if (formValue.password !== formValue.confirmPassword) {
setError('password and confirm password must match');
return;
}
setError('');
console.log('ready to make register api call');
};
return (
<>
<div className='register'>
<form onSubmit={handleSubmit(onSubmit)}>
<div className='card register-card'>
<div className='form-group'>
<label>Full Name</label>
<input type='text' placeholder='Full name' {...register('name', { required: true })} />
</div>
<div className='form-group'>
<label>Email Address</label>
<input type='email' placeholder='Enter email' {...register('email', { required: true })} />
</div>
<div className='form-group'>
<label>Password</label>
<input type='password' placeholder='Enter password' {...register('password', { required: true })} />
</div>
<div className='form-group'>
<label>Confirm Password</label>
<input type='password' placeholder='Confirm password' {...register('confirmPassword', { required: true })} />
</div>
<div className='form-group'>
<button type='submit'>Submit</button>
</div>
<div className='form-group'>
{error && <span>{error}</span>}
</div>
</div>
</form>
</div>
</>
);
}
export default Register;