|
1 | | -import React from 'react'; |
| 1 | +import React, { useState } from 'react'; |
| 2 | +import { Formik, Form, Field } from 'formik'; |
| 3 | +import * as yup from 'yup'; |
| 4 | +import { Link } from 'react-router-dom'; |
2 | 5 |
|
3 | | -function Signup() { |
| 6 | +import './signup.scss'; |
| 7 | +import { useDispatch, useSelector } from 'react-redux'; |
| 8 | +import { signUpUser } from '../../redux/actions/userActions'; |
| 9 | + |
| 10 | +const SignUp = () => { |
| 11 | + const initialValues = { |
| 12 | + firstName: '', |
| 13 | + lastName: '', |
| 14 | + email: '', |
| 15 | + phoneNumber: '', |
| 16 | + password: '', |
| 17 | + confirmPassword: '' |
| 18 | + }; |
| 19 | + |
| 20 | + const dispatch = useDispatch(); |
| 21 | + |
| 22 | + let loginSchema = yup.object().shape({ |
| 23 | + firstName: yup.string().required(), |
| 24 | + lastName: yup.string().required(), |
| 25 | + phoneNumber: yup.string().required(), |
| 26 | + email: yup.string().email().required(), |
| 27 | + password: yup.string().required(), |
| 28 | + confirmPassword: yup.string().required(), |
| 29 | + termsAndCondition: yup.string().required() |
| 30 | + }); |
| 31 | + |
| 32 | + const handleSubmit = (data) => { |
| 33 | + dispatch(signUpUser(data)); |
| 34 | + }; |
4 | 35 | return ( |
5 | | - <div> |
6 | | - <h3>Hellow Signup</h3> |
7 | | - </div> |
| 36 | + <> |
| 37 | + <div className="signup-form-wrapper"> |
| 38 | + <h2 className="welcome-text">Welcome to FarmReach</h2> |
| 39 | + <div className="form-container"> |
| 40 | + <p> |
| 41 | + <strong>Let's Get Started</strong> |
| 42 | + </p> |
| 43 | + <div className="signup-form"> |
| 44 | + <Formik |
| 45 | + initialValues={initialValues} |
| 46 | + validationSchema={loginSchema} |
| 47 | + validateOnChange={true} |
| 48 | + validateOnBlur={true} |
| 49 | + onSubmit={(data) => { |
| 50 | + handleSubmit(data); |
| 51 | + }} |
| 52 | + > |
| 53 | + {({ errors, touched }) => ( |
| 54 | + <Form> |
| 55 | + <div className="form-div"> |
| 56 | + <Field type="text" className="form-control" name="firstName" placeholder="First Name" /> |
| 57 | + {errors.firstName && touched.firstName ? ( |
| 58 | + <div className="text-danger">{errors.firstName}</div> |
| 59 | + ) : null} |
| 60 | + </div> |
| 61 | + <div className="form-div"> |
| 62 | + <Field type="text" className="form-control" name="lastName" placeholder="Last Name" /> |
| 63 | + {errors.lastName && touched.lastName ? <div className="text-danger">{errors.lastName}</div> : null} |
| 64 | + </div> |
| 65 | + <div className="form-div"> |
| 66 | + <Field type="email" className="form-control" name="email" placeholder="Email" /> |
| 67 | + {errors.email && touched.email ? <div className="text-danger">{errors.email}</div> : null} |
| 68 | + </div> |
| 69 | + <div className="form-div"> |
| 70 | + <Field type="tel" className="form-control" name="phoneNumber" placeholder="Phone Number" /> |
| 71 | + {errors.phoneNumber && touched.phoneNumber ? ( |
| 72 | + <div className="text-danger">{errors.phoneNumber}</div> |
| 73 | + ) : null} |
| 74 | + </div> |
| 75 | + |
| 76 | + <div className="form-div"> |
| 77 | + <Field |
| 78 | + type="password" |
| 79 | + className="form-control" |
| 80 | + id="password" |
| 81 | + name="password" |
| 82 | + placeholder="Password" |
| 83 | + /> |
| 84 | + {errors.password && touched.password ? <div className="text-danger">{errors.password}</div> : null} |
| 85 | + </div> |
| 86 | + |
| 87 | + <div className="form-div"> |
| 88 | + <Field |
| 89 | + type="password" |
| 90 | + className="form-control" |
| 91 | + name="confirmPassword" |
| 92 | + placeholder="Confirm Password" |
| 93 | + /> |
| 94 | + </div> |
| 95 | + |
| 96 | + <button type="submit" className="signup-btn"> |
| 97 | + SIGN UP |
| 98 | + </button> |
| 99 | + <p className="login-text"> |
| 100 | + {' '} |
| 101 | + I already have an account |
| 102 | + <Link to="/login">Login</Link> |
| 103 | + </p> |
| 104 | + |
| 105 | + <div className="form-div-checkbox"> |
| 106 | + <Field |
| 107 | + type="checkbox" |
| 108 | + className="form-control-check" |
| 109 | + id="terms" |
| 110 | + name="termsAndCondition" |
| 111 | + placeholder="Confirm Password" |
| 112 | + /> |
| 113 | + <label htmlFor="terms">I agree to the terms and conditions</label> |
| 114 | + </div> |
| 115 | + </Form> |
| 116 | + )} |
| 117 | + </Formik> |
| 118 | + </div> |
| 119 | + </div> |
| 120 | + </div> |
| 121 | + </> |
8 | 122 | ); |
9 | | -} |
| 123 | +}; |
10 | 124 |
|
11 | | -export default Signup; |
| 125 | +export default SignUp; |
0 commit comments