Changeset 16237c4 for frontend/src/screens
- Timestamp:
- 09/08/22 12:38:24 (2 years ago)
- Branches:
- master
- Children:
- ee05663
- Parents:
- 717ceae
- Location:
- frontend/src/screens
- Files:
-
- 7 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
frontend/src/screens/SigninScreen.js
r717ceae r16237c4 1 import Axios from "axios"; 1 2 import Container from "react-bootstrap/Container"; 2 3 import Form from "react-bootstrap/Form"; … … 4 5 import Button from "react-bootstrap/Button"; 5 6 import "../styles/SigninScreen.css"; 6 import React from "react"; 7 import { Link, useLocation } from "react-router-dom"; 7 import React, { useContext, useEffect, useState } from "react"; 8 import { Link, useLocation, useNavigate } from "react-router-dom"; 9 import { Store } from "../Store"; 10 import { toast } from "react-toastify"; 11 import { getError } from "../components/utils"; 8 12 9 13 function SigninScreen() { 14 const navigate = useNavigate(); 10 15 const { search } = useLocation(); 11 16 const redirectInUrl = new URLSearchParams(search).get("redirect"); 12 17 const redirect = redirectInUrl ? redirectInUrl : "/"; 18 19 const [email, setEmail] = useState(""); 20 const [password, setPassword] = useState(""); 21 22 const { state, dispatch: ctxDispatch } = useContext(Store); 23 const { userInfo } = state; 24 25 const submitHandler = async (e) => { 26 e.preventDefault(); 27 try { 28 const { data } = await Axios.post("/api/users/signin", { 29 email, 30 password, 31 }); 32 ctxDispatch({ type: "USER_SIGNIN", payload: data }); 33 localStorage.setItem("userInfo", JSON.stringify(data)); 34 navigate(redirect || "/"); 35 } catch (err) { 36 toast.error(getError(err)); 37 } 38 }; 39 40 useEffect(() => { 41 if (userInfo) { 42 navigate(redirect); 43 } 44 }, [navigate, redirect, userInfo]); 45 13 46 return ( 14 47 <div className="pageContainer"> … … 18 51 </Helmet> 19 52 <h1>Најави се</h1> 20 <Form className="formCointainer" >53 <Form className="formCointainer" onSubmit={submitHandler}> 21 54 <Form.Group controlId="email"> 22 55 <Form.Label>Email</Form.Label> 23 <Form.Control type="email" required /> 56 <Form.Control 57 type="email" 58 required 59 onChange={(e) => setEmail(e.target.value)} 60 /> 24 61 </Form.Group> 25 62 <Form.Group controlId="password"> 26 63 <Form.Label>Лозинка</Form.Label> 27 <Form.Control type="email" required /> 64 <Form.Control 65 type="password" 66 required 67 onChange={(e) => setPassword(e.target.value)} 68 /> 28 69 </Form.Group> 29 70 <div className="submitBtnContainer">
Note:
See TracChangeset
for help on using the changeset viewer.