source: jobvista-frontend/src/views/auth/SignUpJobSeekerForm.js@ 4d97b63

main
Last change on this file since 4d97b63 was 19398ad, checked in by 223021 <daniel.ilievski.2@…>, 6 months ago

Implemented backend and frontend CRUD operations for job advertisements

  • Property mode set to 100644
File size: 5.0 KB
Line 
1
2import * as yup from 'yup';
3import {useDispatch} from "react-redux";
4import {yupResolver} from "@hookform/resolvers/yup";
5import {useForm} from "react-hook-form";
6import {useNavigate} from 'react-router';
7import "./auth.css"
8import {AuthActions} from "../../redux/actions/authActions";
9
10export const SignUpJobSeekerForm = () => {
11
12 const dispatch = useDispatch();
13 const navigate = useNavigate()
14
15 const schema = yup.object().shape({
16 firstNameReg: yup.string().required("First name is required."),
17 lastNameReg: yup.string().required("Last name is required."),
18 phoneNumberReg: yup.string().required("Phone number is required"),
19 emailReg: yup.string().required("Email is required.").email("Email is not valid."),
20 passwordReg: yup.string().min(6, "Password must be at least 6 characters.").required("Password is required."),
21 confirmPasswordReg: yup.string().oneOf([yup.ref("passwordReg")], "Passwords are not same").required("Confirm your password."),
22 });
23
24 const {register, handleSubmit, formState: {errors}} = useForm({
25 resolver: yupResolver(schema),
26 });
27
28 const signUp = async (values) => {
29 try {
30 dispatch(AuthActions.signUpJobSeeker(values.firstNameReg, values.lastNameReg, values.phoneNumberReg, values.emailReg,
31 values.passwordReg, success => {
32 // createSnackbar({
33 // message: success ? 'Successfully signed up.' : 'Error while signing up. Try again!',
34 // timeout: 2500,
35 // theme: success ? 'success' : 'error'
36 // });
37 success && navigate("/");
38 }));
39 } catch (err) {
40 console.error(err);
41 }
42 }
43
44
45 return (
46 <div className="d-flex align-items-center">
47 <div className="container">
48 <div className="row">
49 <div className="col-md-8 mx-auto form-container">
50 <h3 className="login-heading mb-4">Register as a Job Seeker</h3>
51 <form onSubmit={handleSubmit(signUp)}>
52 <div className="form-floating mb-1">
53 <input type="text" className="form-control" {...register("firstNameReg")} placeholder="Dwayne" />
54 <label htmlFor="firstName">First Name</label>
55 <p className="error-message" >{errors.firstNameReg?.message}</p>
56 </div>
57 <div className="form-floating mb-1">
58 <input type="text" className="form-control" {...register("lastNameReg")} placeholder="Johnson"/>
59 <label htmlFor="lastName">Last Name</label>
60 <p className="error-message" >{errors.lastNameReg?.message}</p>
61 </div>
62 <div className="form-floating mb-1">
63 <input type="text" className="form-control" placeholder="070479397" {...register("phoneNumberReg")} />
64 <label htmlFor="phoneNumber">Phone Number</label>
65 <p className="error-message" >{errors.phoneNumberReg?.message}</p>
66 </div>
67 <div className="form-floating mb-1">
68 <input type="email" className="form-control" placeholder="name@example.com" {...register("emailReg")}/>
69 <label htmlFor="email">Email Address</label>
70 <p className="error-message" >{errors.emailReg?.message}</p>
71 </div>
72 <div className="form-floating mb-3">
73 <input type="password" className="form-control" placeholder="Password" {...register("passwordReg")}/>
74 <label htmlFor="floatingPassword">Password</label>
75 <p className="error-message" >{errors.passwordReg?.message}</p>
76 </div>
77 <div className="form-floating mb-3">
78 <input type="password" className="form-control" placeholder="Confirm Password" {...register("confirmPasswordReg")}/>
79 <label htmlFor="floatingConfirmPassword">Confirm Password</label>
80 <p className="error-message" >{errors.confirmPasswordReg?.message}</p>
81 </div>
82
83 <div className="d-grid mb-3">
84 <button
85 className="btn btn-lg auth-primary-btn text-uppercase fw-bold mb-2"
86 type="submit">Submit
87 </button>
88 </div>
89 </form>
90
91 </div>
92 </div>
93 </div>
94 </div>
95 )
96}
Note: See TracBrowser for help on using the repository browser.