source: client_app/src/components/login/login.js@ ed3f5c4

Last change on this file since ed3f5c4 was 7944fab, checked in by Vzdra <vladko.zdravkovski@…>, 3 years ago

finished user registration

  • Property mode set to 100644
File size: 2.5 KB
Line 
1import React from 'react';
2import { Button, Checkbox, Container, Form } from "semantic-ui-react";
3import { Redirect } from 'react-router-dom';
4
5const Login = (props) => {
6 const [formData, updateFormData] = React.useState({
7 email: "",
8 password: "",
9 type: "0"
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();
21 const email = formData.email;
22 const password = formData.password;
23 const type = formData.type;
24
25 props.onCompleteForm(email,password,type);
26 }
27
28 if(!props.loggedIn){
29 return(
30 <Container>
31 <h1 style={{color: "green"}}>{props.success}</h1>
32 <h1 style={{color: "red"}}>{props.error}</h1>
33 <Form onSubmit={onFormSubmit}>
34 <Form.Input id="email" name="email" type='email' required fluid label='E-mail' placeholder='Enter e-mail.' onChange={handleCheck} />
35 <Form.Input id="password" name="password" type='password' required fluid label='Password' placeholder='Enter password.' onChange={handleCheck} />
36 <Form.Field
37 control={Checkbox}
38 radio
39 label='User'
40 id="0"
41 name="type"
42 value="0"
43 checked={formData.type === "0"}
44 onChange={handleCheck}
45 />
46 <Form.Field
47 control={Checkbox}
48 radio
49 label='Team'
50 id="1"
51 name="type"
52 value="1"
53 checked={formData.type === "1"}
54 onChange={handleCheck}
55 />
56 <Form.Field
57 control={Checkbox}
58 radio
59 label='Company'
60 id="2"
61 name="type"
62 value="2"
63 checked={formData.type === "2"}
64 onChange={handleCheck}
65 />
66 <Form.Field control={Button}>LogIn</Form.Field>
67 </Form>
68 </Container>
69 );
70 }
71
72 return(
73 <Redirect to={"/profile"}/>
74 );
75
76}
77
78export default Login;
Note: See TracBrowser for help on using the repository browser.