|
1 |
| -import React from 'react' |
| 1 | +import React, { useState } from 'react' |
| 2 | +import { useAuth } from '../../Context/AuthContext' |
| 3 | +import { useNavigate } from "react-router-dom" |
| 4 | +import { auth } from '../../firebase' |
| 5 | +import Button from 'react-bootstrap/Button'; |
| 6 | +import Form from 'react-bootstrap/Form'; |
| 7 | +import "./Form.css" |
| 8 | +import 'bootstrap/dist/css/bootstrap.min.css'; |
2 | 9 |
|
3 | 10 | export const Login = () => {
|
| 11 | + const [user, setUser] = useState({ |
| 12 | + email:"", |
| 13 | + password:"" |
| 14 | + }) |
| 15 | + const navigate = useNavigate() |
| 16 | + const { login, loginWithGoogle } = useAuth() |
| 17 | + |
| 18 | + const handelChange = (e)=>{ |
| 19 | + setUser({ |
| 20 | + ...user, |
| 21 | + [e.target.name] : e.target.value |
| 22 | + }) |
| 23 | + } |
| 24 | + |
| 25 | + const handelSubmit = async (e)=>{ |
| 26 | + e.preventDefault() |
| 27 | + try { |
| 28 | + await login(user.email, user.password) |
| 29 | + navigate("/") |
| 30 | + } catch (error) { |
| 31 | + console.log(error) |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + const createAccount = (e)=>{ |
| 36 | + e.preventDefault() |
| 37 | + navigate("/register") |
| 38 | + } |
| 39 | + |
| 40 | + const handelLoguinGoogle = async (e)=>{ |
| 41 | + e.preventDefault() |
| 42 | + try { |
| 43 | + await loginWithGoogle() |
| 44 | + navigate("/") |
| 45 | + } catch (error) { |
| 46 | + console.log(error) |
| 47 | + } |
| 48 | + |
| 49 | + } |
| 50 | + |
4 | 51 | return (
|
5 |
| - <div>Login</div> |
| 52 | + <div className='container-form d-flex flex-column justify-content-center align-content-center'> |
| 53 | + <Form className="formu border p-4" onSubmit={handelSubmit}> |
| 54 | + <h3>Enter for make your searches</h3> |
| 55 | + <Form.Group className="mb-3" controlId="formBasicEmail"> |
| 56 | + <Form.Label>Email address</Form.Label> |
| 57 | + <Form.Control type="email" name='email' placeholder="Enter email" onChange={handelChange}/> |
| 58 | + <Form.Text className="text-muted"> |
| 59 | + We'll never share your email with anyone else. |
| 60 | + </Form.Text> |
| 61 | + </Form.Group> |
| 62 | + |
| 63 | + <Form.Group className="mb-3" controlId="formBasicPassword"> |
| 64 | + <Form.Label>Password</Form.Label> |
| 65 | + <Form.Control type="password" name='password' placeholder="Password" onChange={handelChange}/> |
| 66 | + </Form.Group> |
| 67 | + {/* <Form.Group className="mb-3" controlId="formBasicCheckbox"> |
| 68 | + <Form.Check type="checkbox" label="Check me out" /> |
| 69 | + </Form.Group> */} |
| 70 | + <div className='d-flex justify-content-between'> |
| 71 | + <Button variant="primary" type="submit"> |
| 72 | + Login |
| 73 | + </Button> |
| 74 | + <Button variant="" onClick={createAccount}> |
| 75 | + Create Account |
| 76 | + </Button> |
| 77 | + </div> |
| 78 | + <div className='d-flex justify-content-center mt-4'> |
| 79 | + <Button variant="primary" type="submit" onClick={handelLoguinGoogle}> |
| 80 | + Loguin with Google |
| 81 | + </Button> |
| 82 | + </div> |
| 83 | + </Form> |
| 84 | + </div> |
6 | 85 | )
|
7 | 86 | }
|
0 commit comments