Showing
4 changed files
with
118 additions
and
2 deletions
... | @@ -2,6 +2,7 @@ import React from "react"; | ... | @@ -2,6 +2,7 @@ import React from "react"; |
2 | import { Switch, Route, Redirect } from "react-router-dom"; | 2 | import { Switch, Route, Redirect } from "react-router-dom"; |
3 | 3 | ||
4 | import { Login } from "auth/Login"; | 4 | import { Login } from "auth/Login"; |
5 | +import { Signup } from "auth/Signup"; | ||
5 | import { useAuth, TokenContext } from "auth/useAuth"; | 6 | import { useAuth, TokenContext } from "auth/useAuth"; |
6 | 7 | ||
7 | import { Page } from "layout/Page"; | 8 | import { Page } from "layout/Page"; |
... | @@ -16,6 +17,9 @@ export function App() { | ... | @@ -16,6 +17,9 @@ export function App() { |
16 | <Route path="/login"> | 17 | <Route path="/login"> |
17 | <Login login={token.login} /> | 18 | <Login login={token.login} /> |
18 | </Route> | 19 | </Route> |
20 | + <Route path="/signup"> | ||
21 | + <Signup /> | ||
22 | + </Route> | ||
19 | <Route> | 23 | <Route> |
20 | {token.token !== null ? ( | 24 | {token.token !== null ? ( |
21 | <TokenContext.Provider value={token}> | 25 | <TokenContext.Provider value={token}> | ... | ... |
1 | import React, { useCallback, useState } from "react"; | 1 | import React, { useCallback, useState } from "react"; |
2 | import { Form, Input, Button, Checkbox, Layout } from "antd"; | 2 | import { Form, Input, Button, Checkbox, Layout } from "antd"; |
3 | import { UserOutlined, LockOutlined } from "@ant-design/icons"; | 3 | import { UserOutlined, LockOutlined } from "@ant-design/icons"; |
4 | -import { useHistory } from "react-router-dom"; | 4 | +import { useHistory, Link } from "react-router-dom"; |
5 | 5 | ||
6 | import styles from "./Login.module.scss"; | 6 | import styles from "./Login.module.scss"; |
7 | 7 | ||
... | @@ -49,7 +49,7 @@ export function Login({ login }: LoginProps) { | ... | @@ -49,7 +49,7 @@ export function Login({ login }: LoginProps) { |
49 | </Form.Item> | 49 | </Form.Item> |
50 | <Form.Item | 50 | <Form.Item |
51 | name="password" | 51 | name="password" |
52 | - rules={[{ required: true, message: "Please input your Password!" }]} | 52 | + rules={[{ required: true, message: "비밀번호를 입력하세요" }]} |
53 | {...(error && { | 53 | {...(error && { |
54 | validateStatus: "error", | 54 | validateStatus: "error", |
55 | help: "로그인에 실패했습니다", | 55 | help: "로그인에 실패했습니다", |
... | @@ -71,6 +71,9 @@ export function Login({ login }: LoginProps) { | ... | @@ -71,6 +71,9 @@ export function Login({ login }: LoginProps) { |
71 | <Button type="primary" htmlType="submit"> | 71 | <Button type="primary" htmlType="submit"> |
72 | 로그인 | 72 | 로그인 |
73 | </Button> | 73 | </Button> |
74 | + <Link to="/signup" style={{ marginLeft: 24 }}> | ||
75 | + 회원가입 | ||
76 | + </Link> | ||
74 | </Form.Item> | 77 | </Form.Item> |
75 | </Form> | 78 | </Form> |
76 | </Layout.Content> | 79 | </Layout.Content> | ... | ... |
frontend/src/auth/Signup.tsx
0 → 100644
1 | +import React, { useCallback, useState } from "react"; | ||
2 | +import { Form, Input, Button, Layout, message } from "antd"; | ||
3 | +import { UserOutlined, LockOutlined, TagOutlined } from "@ant-design/icons"; | ||
4 | +import { useHistory } from "react-router-dom"; | ||
5 | + | ||
6 | +import styles from "./Login.module.scss"; | ||
7 | +import ky from "ky"; | ||
8 | + | ||
9 | +export function Signup() { | ||
10 | + const [error, setError] = useState<boolean>(false); | ||
11 | + const [check, setCheck] = useState<boolean>(false); | ||
12 | + const history = useHistory(); | ||
13 | + | ||
14 | + const handleSignup = useCallback( | ||
15 | + async ({ user_id, password, password_check, name }) => { | ||
16 | + if (password !== password_check) { | ||
17 | + return setCheck(true); | ||
18 | + } else { | ||
19 | + setCheck(false); | ||
20 | + } | ||
21 | + | ||
22 | + setError(false); | ||
23 | + try { | ||
24 | + const body = new URLSearchParams(); | ||
25 | + body.set("user_id", user_id); | ||
26 | + body.set("password", password); | ||
27 | + body.set("name", name); | ||
28 | + | ||
29 | + await ky.post("/users/signup/", { body }); | ||
30 | + | ||
31 | + message.success("회원가입이 완료되었습니다"); | ||
32 | + history.push("/login"); | ||
33 | + } catch { | ||
34 | + setError(true); | ||
35 | + } | ||
36 | + }, | ||
37 | + [history] | ||
38 | + ); | ||
39 | + | ||
40 | + return ( | ||
41 | + <Layout className={styles.layout}> | ||
42 | + <Layout.Content className={styles.content}> | ||
43 | + <Form name="signup" onFinish={handleSignup}> | ||
44 | + <Form.Item | ||
45 | + name="user_id" | ||
46 | + rules={[{ required: true, message: "아이디를 입력하세요" }]} | ||
47 | + {...(error && { | ||
48 | + validateStatus: "error", | ||
49 | + })} | ||
50 | + > | ||
51 | + <Input prefix={<UserOutlined />} placeholder="아이디" /> | ||
52 | + </Form.Item> | ||
53 | + <Form.Item | ||
54 | + name="password" | ||
55 | + rules={[{ required: true, message: "비밀번호를 입력하세요" }]} | ||
56 | + {...(error && { | ||
57 | + validateStatus: "error", | ||
58 | + help: "로그인에 실패했습니다", | ||
59 | + })} | ||
60 | + > | ||
61 | + <Input | ||
62 | + prefix={<LockOutlined />} | ||
63 | + type="password" | ||
64 | + placeholder="비밀번호" | ||
65 | + /> | ||
66 | + </Form.Item> | ||
67 | + <Form.Item | ||
68 | + name="password_check" | ||
69 | + rules={[ | ||
70 | + { required: true, message: "비밀번호를 한번 더 입력하세요" }, | ||
71 | + ]} | ||
72 | + {...(error && { | ||
73 | + validateStatus: "error", | ||
74 | + help: "로그인에 실패했습니다", | ||
75 | + })} | ||
76 | + {...(check && { | ||
77 | + validateStatus: "error", | ||
78 | + help: "비밀번호가 일치하지 않습니다", | ||
79 | + })} | ||
80 | + > | ||
81 | + <Input | ||
82 | + prefix={<LockOutlined />} | ||
83 | + type="password" | ||
84 | + placeholder="비밀번호 확인" | ||
85 | + /> | ||
86 | + </Form.Item> | ||
87 | + <Form.Item | ||
88 | + name="name" | ||
89 | + rules={[{ required: true, message: "이름을 입력하세요" }]} | ||
90 | + {...(error && { | ||
91 | + validateStatus: "error", | ||
92 | + })} | ||
93 | + > | ||
94 | + <Input prefix={<TagOutlined />} placeholder="이름" /> | ||
95 | + </Form.Item> | ||
96 | + | ||
97 | + <Form.Item> | ||
98 | + <Button type="primary" htmlType="submit"> | ||
99 | + 회원 가입 | ||
100 | + </Button> | ||
101 | + </Form.Item> | ||
102 | + </Form> | ||
103 | + </Layout.Content> | ||
104 | + </Layout> | ||
105 | + ); | ||
106 | +} |
... | @@ -178,6 +178,9 @@ export function FileList() { | ... | @@ -178,6 +178,9 @@ export function FileList() { |
178 | })} | 178 | })} |
179 | dataSource={list} | 179 | dataSource={list} |
180 | pagination={false} | 180 | pagination={false} |
181 | + locale={{ | ||
182 | + emptyText: "파일이 없습니다", | ||
183 | + }} | ||
181 | /> | 184 | /> |
182 | </div> | 185 | </div> |
183 | ); | 186 | ); | ... | ... |
-
Please register or login to post a comment