Signup.tsx
3.13 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
import React, { useCallback, useState } from "react";
import { Form, Input, Button, Layout, message } from "antd";
import { UserOutlined, LockOutlined, TagOutlined } from "@ant-design/icons";
import { useHistory } from "react-router-dom";
import styles from "./Login.module.scss";
import ky from "ky";
export function Signup() {
const [error, setError] = useState<boolean>(false);
const [check, setCheck] = useState<boolean>(false);
const history = useHistory();
const handleSignup = useCallback(
async ({ user_id, password, password_check, name }) => {
if (password !== password_check) {
return setCheck(true);
} else {
setCheck(false);
}
setError(false);
try {
const body = new URLSearchParams();
body.set("user_id", user_id);
body.set("password", password);
body.set("name", name);
await ky.post("/users/signup/", { body });
message.success("회원가입이 완료되었습니다");
history.push("/login");
} catch {
setError(true);
}
},
[history]
);
return (
<Layout className={styles.layout}>
<Layout.Content className={styles.content}>
<Form name="signup" onFinish={handleSignup}>
<Form.Item
name="user_id"
rules={[{ required: true, message: "아이디를 입력하세요" }]}
{...(error && {
validateStatus: "error",
})}
>
<Input prefix={<UserOutlined />} placeholder="아이디" />
</Form.Item>
<Form.Item
name="password"
rules={[{ required: true, message: "비밀번호를 입력하세요" }]}
{...(error && {
validateStatus: "error",
help: "로그인에 실패했습니다",
})}
>
<Input
prefix={<LockOutlined />}
type="password"
placeholder="비밀번호"
/>
</Form.Item>
<Form.Item
name="password_check"
rules={[
{ required: true, message: "비밀번호를 한번 더 입력하세요" },
]}
{...(error && {
validateStatus: "error",
help: "로그인에 실패했습니다",
})}
{...(check && {
validateStatus: "error",
help: "비밀번호가 일치하지 않습니다",
})}
>
<Input
prefix={<LockOutlined />}
type="password"
placeholder="비밀번호 확인"
/>
</Form.Item>
<Form.Item
name="name"
rules={[{ required: true, message: "이름을 입력하세요" }]}
{...(error && {
validateStatus: "error",
})}
>
<Input prefix={<TagOutlined />} placeholder="이름" />
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit">
회원 가입
</Button>
</Form.Item>
</Form>
</Layout.Content>
</Layout>
);
}