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

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

Did more refactoring

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