RegisterPage.js
4.39 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import React, {useState, useCallback} from "react";
import { useNavigate } from "react-router-dom";
import "../style/RegisterPage.scss";
import { Button, Dropdown, Icon, Input} from "semantic-ui-react";
import Axios from 'axios'
function RegisterPage(props) {
const navigate = useNavigate();
const [Id, setId] = useState("");
const [Password, setPassword] = useState("");
const [PasswordCheck,setPasswordCheck] = useState("");
const [Personality, setPersonality] = useState("");
const onIdHandler = (event) => {
setId(event.currentTarget.value);
};
const onPasswordHandler = (event) => {
setPassword(event.currentTarget.value);
};
const onPersonalityHandler = (event) => {
setPersonality(event.currentTarget.value.toUpperCase());
};
const onPasswordChkHandler = (event) => {
//비밀번호를 입력할때마다 password 를 검증하는 함수
setPasswordCheck(event.currentTarget.value);
};
const onSubmitHandler = (event) => {
event.preventDefault();
console.log("ID", Id);
console.log("Password", Password);
console.log("MBTI", Personality);
if (Password !== PasswordCheck) {
return alert('비밀번호가 일치하지 않습니다.')
}
else if((Personality[0] !== 'I' && Personality[0] !== 'E') || (Personality[1] !== 'S' && Personality[1] !== 'N')
|| (Personality[2] !== 'F' && Personality[2] !== 'T') || (Personality[3] !== 'J' && Personality[3] !== 'P'))
{
return alert('올바르지 않은 MBTI입니다.')
}
else{
Axios.post('/api/register',{
Id,
Password,
Personality
})
.then((res)=>{
if(res.status === 200){
alert("회원가입에 성공하였습니다.")
navigate('/login')
}
}).catch((error) => {
console.log(error.response)
alert("중복된 아이디입니다.")
})
}
}
return (
<div id="Register">
<div className="register-form">
<form onSubmit={onSubmitHandler}>
<h1>Tunnel</h1>
<div className="input-area">
<Input
icon={<Icon name="id badge"/>}
iconPosition='left'
placeholder="ID"
type="text"
value={Id}
autoComplete="off"
required onChange={onIdHandler}/>
</div>
<div className="input-area">
<Input
icon={<Icon name='heart'/>}
iconPosition='left'
placeholder="Your MBTI"
maxlength='4'
type="text"
value={Personality}
autoComplete="off"
onChange={onPersonalityHandler}/>
</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="input-area">
<Input
icon={<Icon name='check'/>}
iconPosition='left'
placeholder="Check your Password"
type="password"
value={PasswordCheck}
autoComplete="off"
onChange={onPasswordChkHandler}/>
</div>
<div className="btn-area" >
<Button className='register-btn'
content='Sign up'
icon='signup'/>
</div>
</form>
</div>
</div>
);
}
export default RegisterPage;