LoginPage.js
2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React, {useState} from "react";
import "../style/LoginPage.scss";
import { Icon, Input } from "semantic-ui-react"
import { useNavigate } from "react-router-dom";
import {useDispatch} from "react-redux";
import { loginUser } from '../../../_actions/user_action'
function LoginPage(props) {
const dispatch = useDispatch();
const navigate = useNavigate();
const [Id, setId] = useState("");
const [Password, setPassword] = useState("");
const onIdHandler = (event) => {
setId(event.currentTarget.value);
};
const onPasswordHandler = (event) => {
setPassword(event.currentTarget.value);
};
const onSubmitHandler = (event) => {
event.preventDefault();
console.log("ID", Id);
console.log("Password", Password);
let body = {
id: Id,
password: Password
}
dispatch(loginUser(body))
.then(response => {
if (response.payload.loginSuccess) {
props.history.push('/main')
}
else{
alert('Error')
}
})
};
const goToRegister = () => {
navigate('/register');
}
return (
<div id="body">
<div className="login-form">
<form onSubmit={onSubmitHandler}>
<h1>Tunnel</h1>
<div className="input-area">
<Input
icon={<Icon name='at'/>}
iconPosition='left'
placeholder="ID"
type="text"
value={Id}
autoComplete="off"
onChange={onIdHandler}/>
</div>
<div className="input-area">
<Input
icon={<Icon name='lock'/>}
iconPosition='left'
placeholder="Password"
type="password"
value={Password}
autoComplete="off"
onChange={onPasswordHandler}/>
</div>
<div className="btn-area">
<button className="login-btn" >Login</button>
<button className="register-btn" onClick={()=>goToRegister()} >Register</button>
</div>
</form>
</div>
</div>
);
}
export default LoginPage;