-
Notifications
You must be signed in to change notification settings - Fork 2
/
Signup.tsx
177 lines (161 loc) · 4.17 KB
/
Signup.tsx
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import React, { useEffect, useState } from "react";
import Link from "next/link";
import styled from "styled-components";
import axios from "axios";
import { z } from "zod";
const instance = axios.create({
baseURL: "https://onaka-api.herokuapp.com/",
});
function Signup() {
const [username, setUsername] = useState("");
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
// const SignupSend = (e) => {
// e.preventDefault();
// console.log(email, password);
/* バックエンドに送る処理に変える */
// };
const postDataChecker = z.object({
Name: z.string().min(1, { message: "ユーザー名を入力してください" }),
Email: z
.string()
.min(1, { message: "Emailを入力してください" })
.email({ message: "Emailの型にになっていません" }),
Password: z.string().min(1, { message: "パスワードを入力してください" }),
});
const postFunc = () => {
const postData = {
Name: username,
Email: email,
Password: password,
};
try {
postDataChecker.parse(postData);
} catch (err) {
alert(err.issues[0].message);
return;
}
instance.post(`/api/v1/users/signup`, postData).then(() => {
instance
.post("/api/v1/users/signin", {
Email: email,
Password: password,
})
.then((res) => {
console.log(res);
localStorage.setItem("token", res.data.jwt);
location.href = "/";
});
});
};
useEffect(() => {
if (localStorage.getItem("token") !== null) {
location.href = "/";
}
}, []);
return (
<BG>
<ContentDiv>
<Card>
<Title>新規登録画面</Title>
<div>
<div>
<label>
<div>ユーザー名</div>
<InputForm
name="username"
type="text"
onChange={(e) => setUsername(e.target.value)}
/>
</label>
</div>
<div>
<label>
<div>メールアドレス</div>
<InputForm
name="email"
type="email"
onChange={(e) => setEmail(e.target.value)}
/>
</label>
</div>
<div>
<label>
<div>パスワード</div>
<InputForm
name="password"
type="password"
onChange={(e) => setPassword(e.target.value)}
/>
</label>
</div>
<Enrole>
<InputButton onClick={postFunc}>
<a>新規登録</a>
</InputButton>
<InputButton type="submit">
<Link href="/Login">
<a>
<div>ログイン画面へ</div>
</a>
</Link>
</InputButton>
</Enrole>
</div>
</Card>
</ContentDiv>
</BG>
);
}
export default Signup;
const Enrole = styled.div`
text-align: center;
display: flex;
flex-direction: column;
justify-content: center;
padding: 0 20px;
`;
const BG = styled.div`
background-color: #ffee4a;
background-size: cover;
display: flex;
justify-content: center;
min-height: 100vh;
height: 100%;
`;
const ContentDiv = styled.div`
position: relative;
`;
const Card = styled.div`
text-align: center;
padding-top: 2em;
max-width: 800px;
background-color: white;
padding: 1em 30px;
margin: 30px 0;
border-radius: 20px;
`;
const Title = styled.h1`
margin: 10px 0;
color: #fe9600;
`;
const InputForm = styled.input`
padding: 4px 23px;
margin: 5px 30px;
border-radius: 5px;
border: 2px solid #fe9600;
`;
const InputButton = styled.button`
border-color: #00000000;
background-color: #fe9600;
color: white;
padding: 7px;
margin-top: 8px;
border-radius: 6px;
display: inline-block;
`;
// .color-0 { color: #fe9600; }
// .color-1 { color: #ffc501; }
// .color-2 { color: #ffee4a; }
// .color-3 { color: #77477e; }
// .color-4 { color: #03001c; }