Last change
on this file since 58ceab3 was 2e507a8, checked in by Vzdra <vladko.zdravkovski@…>, 4 years ago |
front end additions
|
-
Property mode
set to
100644
|
File size:
2.4 KB
|
Rev | Line | |
---|
[3f5bf9e] | 1 | import React from 'react';
|
---|
[6f9b7b0] | 2 | import { Button, Checkbox, Container, Form } from "semantic-ui-react";
|
---|
| 3 | import { Redirect } from 'react-router-dom';
|
---|
[3f5bf9e] | 4 |
|
---|
| 5 | const Login = (props) => {
|
---|
| 6 | const [formData, updateFormData] = React.useState({
|
---|
[17abe5e] | 7 | email: "",
|
---|
[3f5bf9e] | 8 | password: "",
|
---|
[17abe5e] | 9 | type: "0"
|
---|
[3f5bf9e] | 10 | })
|
---|
| 11 |
|
---|
| 12 | const handleCheck = (e, {value}) => {
|
---|
| 13 | updateFormData({
|
---|
| 14 | ...formData,
|
---|
| 15 | [e.target.name]: value
|
---|
| 16 | })
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | const onFormSubmit = (e) =>{
|
---|
| 20 | e.preventDefault();
|
---|
[17abe5e] | 21 | const email = formData.email;
|
---|
[3f5bf9e] | 22 | const password = formData.password;
|
---|
| 23 | const type = formData.type;
|
---|
| 24 |
|
---|
[17abe5e] | 25 | props.onCompleteForm(email,password,type);
|
---|
[6f9b7b0] | 26 | }
|
---|
| 27 |
|
---|
| 28 | if(!props.loggedIn){
|
---|
| 29 | return(
|
---|
| 30 | <Container>
|
---|
| 31 | <h1 style={{color: "red"}}>{props.error}</h1>
|
---|
| 32 | <Form onSubmit={onFormSubmit}>
|
---|
[2e507a8] | 33 | <Form.Input id="email" name="email" type='email' required fluid label='E-mail' placeholder='Enter e-mail.' onChange={handleCheck} />
|
---|
[6f9b7b0] | 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 | );
|
---|
[3f5bf9e] | 69 | }
|
---|
| 70 |
|
---|
| 71 | return(
|
---|
[6f9b7b0] | 72 | <Redirect to={"/profile"}/>
|
---|
[3f5bf9e] | 73 | );
|
---|
[6f9b7b0] | 74 |
|
---|
[3f5bf9e] | 75 | }
|
---|
| 76 |
|
---|
| 77 | export default Login; |
---|
Note:
See
TracBrowser
for help on using the repository browser.