Advertisement
Kool_Cool

RegistrationForm

Jun 14th, 2024
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //resources\js\Component\UserRegistration\RegistrationForm.jsx
  2.  
  3. import { Formik, Form, Field } from "formik";
  4. import * as Yup from "yup";
  5. import { Card, CardBody, Row, Col, Label, Button } from "reactstrap";
  6. import { useState } from "react";
  7.  
  8.  
  9. const RegistrationForm = () => {
  10.   const [submitErrors, setSubmitError] = useState(false);
  11.  
  12.  
  13.   const submitHandler = (values, { resetForm }) => {
  14.     resetForm();
  15.     setSubmitError(false);
  16.    
  17.   };
  18.  
  19.   const REGISTRATION_INITIAL_VALUES = {
  20.     email: "",
  21.     password: ""
  22.   };
  23.  
  24.   const REGISTRATION_VALIDATION_SCHEMA = Yup.object().shape({
  25.     email: Yup.string().email('Invalid email').required('Email is required'),
  26.     password: Yup.string().min(8, 'Password must be at least 8 characters').required('Password is required')
  27.   });
  28.  
  29.   return (
  30.     <>
  31.       <Card>
  32.         <CardBody class="p-0">
  33.           <Formik
  34.             initialValues={REGISTRATION_INITIAL_VALUES}
  35.             onSubmit={submitHandler}
  36.             validationSchema={REGISTRATION_VALIDATION_SCHEMA}
  37.           >
  38.             {({ errors }) => (
  39.               <Form>
  40.                 <Row className="g-3 custom-input">
  41.                   <Col md="6" className="position-relative">
  42.                     <Label>Email</Label>
  43.                     <Field
  44.                       name="email"
  45.                       type="email"
  46.                       className={`form-control ${submitErrors && `${errors.email ? "is-invalid" : "is-valid"}`}`}
  47.                       placeholder="[email protected]"
  48.                     />
  49.                     <div className="invalid-tooltip">{errors.email}</div>
  50.                   </Col>
  51.                   <Col md="6" className="position-relative">
  52.                     <Label>Password</Label>
  53.                     <Field
  54.                       name="password"
  55.                       type="password"
  56.                       className={`form-control ${submitErrors && `${errors.password ? "is-invalid" : "is-valid"}`}`}
  57.                       placeholder="Enter your password"
  58.                     />
  59.                     <div className="invalid-tooltip">{errors.password}</div>
  60.                   </Col>
  61.                   <Col sm="12">
  62.                     <Button color="primary" type="submit" onClick={() => setSubmitError(true)}>Register</Button>
  63.                   </Col>
  64.                 </Row>
  65.               </Form>
  66.             )}
  67.           </Formik>
  68.         </CardBody>
  69.       </Card>
  70.     </>
  71.   );
  72. };
  73.  
  74. export default RegistrationForm;
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement