Ignore:
Timestamp:
01/10/21 21:16:40 (3 years ago)
Author:
i-ina <76742075+i-ina@…>
Branches:
master
Children:
fc8421e
Parents:
17abe5e
Message:

user login

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client_app/src/components/login/login.js

    r17abe5e r6f9b7b0  
    11import React from 'react';
    2 import {useHistory} from 'react-router-dom';
    3 import {Button, Checkbox, Container, Form} from "semantic-ui-react";
     2import { Button, Checkbox, Container, Form } from "semantic-ui-react";
     3import { Redirect } from 'react-router-dom';
    44
    55const Login = (props) => {
    6     const history = useHistory();
    76    const [formData, updateFormData] = React.useState({
    87        email: "",
     
    2524
    2625        props.onCompleteForm(email,password,type);
    27         history.push("/");
     26    }
     27
     28    if(!props.loggedIn){
     29        return(
     30            <Container>
     31                <h1 style={{color: "red"}}>{props.error}</h1>
     32                <Form onSubmit={onFormSubmit}>
     33                    <Form.Input id="email" name="email" type='text' required fluid label='E-mail' placeholder='Enter e-mail.' onChange={handleCheck} />
     34                    <Form.Input id="password" name="password" type='password' required fluid label='Password' placeholder='Enter password.' onChange={handleCheck} />
     35                    <Form.Field
     36                        control={Checkbox}
     37                        radio
     38                        label='User'
     39                        id="0"
     40                        name="type"
     41                        value="0"
     42                        checked={formData.type === "0"}
     43                        onChange={handleCheck}
     44                    />
     45                    <Form.Field
     46                        control={Checkbox}
     47                        radio
     48                        label='Team'
     49                        id="1"
     50                        name="type"
     51                        value="1"
     52                        checked={formData.type === "1"}
     53                        onChange={handleCheck}
     54                    />
     55                    <Form.Field
     56                        control={Checkbox}
     57                        radio
     58                        label='Company'
     59                        id="2"
     60                        name="type"
     61                        value="2"
     62                        checked={formData.type === "2"}
     63                        onChange={handleCheck}
     64                    />
     65                    <Form.Field control={Button}>LogIn</Form.Field>
     66                </Form>
     67            </Container>
     68        );
    2869    }
    2970
    3071    return(
    31         <Container>
    32             <Form onSubmit={onFormSubmit}>
    33                 <Form.Input id="email" name="email" type='text' required fluid label='E-mail' placeholder='Enter e-mail.' onChange={handleCheck} />
    34                 <Form.Input id="password" name="password" type='password' required fluid label='Password' placeholder='Enter password.' onChange={handleCheck} />
    35                 <Form.Field
    36                     control={Checkbox}
    37                     radio
    38                     label='User'
    39                     id="0"
    40                     name="type"
    41                     value="0"
    42                     checked={formData.type === "0"}
    43                     onChange={handleCheck}
    44                 />
    45                 <Form.Field
    46                     control={Checkbox}
    47                     radio
    48                     label='Team'
    49                     id="1"
    50                     name="type"
    51                     value="1"
    52                     checked={formData.type === "1"}
    53                     onChange={handleCheck}
    54                 />
    55                 <Form.Field
    56                     control={Checkbox}
    57                     radio
    58                     label='Company'
    59                     id="2"
    60                     name="type"
    61                     value="2"
    62                     checked={formData.type === "2"}
    63                     onChange={handleCheck}
    64                 />
    65                 <Form.Field control={Button}>LogIn</Form.Field>
    66             </Form>
    67         </Container>
     72        <Redirect to={"/profile"}/>
    6873    );
     74
    6975}
    7076
Note: See TracChangeset for help on using the changeset viewer.