Login.js 6.72 KB
import React, { useState } from 'react';
import { Formik } from "formik";
import Image from "next/image";
import Link from "next/link";
import { Fragment } from "react";
import { Button, Form } from "react-bootstrap";
import * as Yup from "yup";
import { renderImage } from "../../services/imageHandling";

const Login = (props) => {
    console.log(props.type)
    const loginValidationSchema = Yup.object().shape({
        email: Yup.string()
            .required("Email Id is Required")
            .email("Please Enter An Valid Email Id"),
        password: Yup.string()
            .required("Password is Required")
    });
    return (
        <Fragment>
            <div className="contaier-fluid login-banner-image">
                <div className="row">
                    <div className="col-12 col-lg-4 login-div">
                        <div className="">
                            <h2>{props.type=="vendor" ? "Vendor Login" : "Login to Experience"}</h2>
                            <div className="form-container">
                                <Formik
                                    initialValues={{
                                        email: "",
                                        password: ""
                                    }}
                                    validationSchema={loginValidationSchema}
                                    // enableReinitialize={true}
                                    onSubmit={values => {
                                        console.log("login values",values)
                                    }}
                                >
                                    {({ values, errors, touched, handleChange, handleBlur, handleSubmit }) => (
                                        <Form
                                            onSubmit={e => {
                                                e.preventDefault();
                                                handleSubmit();
                                            }}
                                        >
                                            <div className="input-group">
                                                <label>Email Id</label>
                                                <input
                                                    type="text"
                                                    name="email"
                                                    onChange={handleChange}
                                                    onBlur={handleBlur}
                                                    value={values.email}
                                                    placeholder="yourname@example.com"
                                                />
                                                {errors.email && touched.email && (<span className="form-error">{errors.email}</span>)}
                                            </div>
                                            <div className="input-group">
                                                <label>Password</label>
                                                <input
                                                    type="text"
                                                    name="password"
                                                    onChange={handleChange}
                                                    onBlur={handleBlur}
                                                    value={values.password}
                                                    placeholder="#@$!%@#"
                                                />
                                                {errors.password && touched.password && (<span className="form-error">{errors.password}</span>)}
                                            </div>
                                            <div className="input-group">
                                                <Button type="submit" className="btn btn-primary btn-submit">
                                                    Login
                                                </Button>
                                            </div>
                                        </Form>
                                    )}
                                </Formik>
                                <div className="input-group justify-content-center">
                                    <p className="text-center mb-0">or <Link href={`../signup/${props.type}`}>Create a new account</Link></p>
                                </div>
                                {props && props.type == "user" && (
                                    <>
                                        <div className="input-group mb-0">
                                            <div className="btn-continue">
                                                <span className="col-1 image-container">
                                                    <Image src={renderImage("/images/login/icon-google.png")} layout="fill" className="image" />
                                                </span>
                                                <span className="col-10 text-center">Continue with Google</span>
                                            </div>
                                        </div>
                                        <div className="input-group mb-0">
                                            <div className="btn-continue">
                                                <span className="col-1 image-container">
                                                    <Image src={renderImage("/images/login/icon-fb1.png")} layout="fill" className="image" />
                                                </span>
                                                <span className="col-10 text-center">Continue with Facebook</span>
                                            </div>
                                        </div>
                                        <div className="input-group mb-0">
                                            <div className="btn-continue mb-0">
                                                <span className="col-1 image-container">
                                                    <Image src={renderImage("/images/login/icon-apple.png")} layout="fill" className="image" />
                                                </span>
                                                <span className="col-10 text-center">Continue with Apple</span>
                                            </div>
                                        </div>
                                    </>
                                )}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </Fragment>
    )
}

export default Login;