-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSingup.js
508 lines (487 loc) · 13.3 KB
/
Singup.js
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
import React, { useState } from "react";
import {
View,
Text,
TextInput,
StyleSheet,
TouchableOpacity,
Switch,
FlatList,
} from "react-native";
import { useNavigation } from "@react-navigation/native";
const SignupScreen = () => {
const [email, setEmail] = useState("");
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const [passwordConfirm, setPasswordConfirm] = useState("");
const [getCode, setGetCode] = useState("");
const [checkCode, setCheckCode] = useState("");
const [codeEqual, setCodeEqual] = useState(null);
const [pwEqual, setPwEqual] = useState(null);
const sendEmail = () => {
fetch("http://35.216.92.188:8080/api/auth/confirm", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: email.trim(),
}),
})
.then((response) => response.json())
.then((response) => setGetCode(response.AuthenticationCode))
.then((json) => console.log(json))
.catch((error) => console.error(error));
};
console.log(getCode);
const verifyCode = (inputCode) => {
if (inputCode === getCode.trim()) {
setCodeEqual(true);
} else {
setCodeEqual(false);
}
};
const verifyPw = (inputPw) => {
console.log(password, passwordConfirm);
if (inputPw === password.trim()) {
setPwEqual(true);
} else {
setPwEqual(false);
}
};
const [selectedLearningLevel, setSelectedLearningLevel] = useState(null);
const [selectedInterests, setSelectedInterests] = useState([]);
const learningLevels = ["Beginner", "Intermediate", "Advanced"];
const interests1 = ["POLITICS", "ECONOMY", "SOCIETY"];
const interests2 = ["GLOBAL", "IT/SCIENCE", "CULTURE"];
const handleSelectLearningLevel = (level) => {
setSelectedLearningLevel(level);
};
const handleSelectInterest = (interest) => {
setSelectedInterests((prevInterests) => {
if (prevInterests.includes(interest)) {
return prevInterests.filter((i) => i !== interest);
} else {
return [...prevInterests, interest];
}
});
};
// console.log(selectedLearningLevel)
// console.log(selectedInterests)
const interestsJson = {
1: "POLITICS",
2: "ECONOMY",
3: "SOCIETY",
4: "GLOBAL",
5: "IT/SCIENCE",
6: "CULTURE",
};
const navigation = useNavigation();
const handleSignup = () => {
// E-mail, Nickname, P/W, 약관 동의 여부 등의 유효성을 검사합니다.
if (!email || !username || !password) {
alert("Enter all the fields.");
return;
} else {
if (!codeEqual || !pwEqual) {
alert("The input isn't valid");
} else {
// interestsJson 객체의 값들을 배열로 가져옴
const filteredDictionary = {};
Object.entries(interestsJson).forEach(([key, value]) => {
if (selectedInterests.includes(value)) {
filteredDictionary[key] = value;
}
});
fetch("http://35.216.92.188:8080/api/auth/signup", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
id: email.trim(),
password: password.trim(),
nickname: username.trim(),
grade: selectedLearningLevel.trim(),
interests: filteredDictionary,
}),
})
.then((response) => {
if (!response.ok) {
throw new Error("Login failed"); // 로그인 실패 처리
}
return response.json();
})
.then((json) => {
console.log(json);
navigation.navigate("Login"); // 이 부분을 성공 로직에 맞게 조정
})
.catch((error) => {
console.error(error);
// 에러 처리 로직
});
}
}
};
// Render function for the interests FlatList
const renderInterestItem = ({ item }) => (
<View style={styles.interestButtonBox}>
<TouchableOpacity
style={[
styles.interestButton,
selectedInterests.includes(item) && styles.selectedInterestButton,
]}
onPress={() => handleSelectInterest(item)}
>
<Text
style={[
styles.interestButtonText,
selectedInterests.includes(item) &&
styles.selectedInterestButtonText,
]}
>
{item}
</Text>
</TouchableOpacity>
</View>
);
return (
<View style={styles.container}>
<View style={styles.wrapContainer}>
<View style={styles.leftContainer}>
<View style={styles.label}>
<Text style={[styles.labelText, { marginTop: "10%" }]}>
Nickname
</Text>
</View>
<View style={styles.label}>
<Text style={[styles.labelText]}>E-mail</Text>
</View>
<View style={[styles.label]}>
<Text style={[styles.labelText]}>Verify</Text>
</View>
<View style={[styles.label, (style = { marginTop: "50%" })]}>
<Text style={[styles.labelText]}>P/W</Text>
</View>
<View style={styles.label}>
<Text style={[styles.labelText]}>Confirm P/W</Text>
</View>
</View>
<View style={styles.rightContainer}>
<TextInput
placeholder="Nickname"
value={username}
onChangeText={setUsername}
style={styles.input}
/>
<View style={styles.rowContainer}>
<TextInput
placeholder="E-mail"
value={email}
onChangeText={setEmail}
style={styles.emailInput}
/>
<TouchableOpacity
activeOpacity={0.5}
style={styles.authButton}
onPress={sendEmail}
>
<View>
<Text style={styles.authText}>Get code</Text>
</View>
</TouchableOpacity>
</View>
<TextInput
placeholder="Enter the verification code"
value={checkCode}
onChangeText={(text) => {
setCheckCode(text);
verifyCode(text);
}}
style={styles.input}
/>
{codeEqual == null ? (
<Text></Text>
) : codeEqual ? (
<Text style={{ fontSize: 14, left: "3%", color: "blue" }}>
Valid
</Text>
) : (
<Text style={{ fontSize: 14, left: "3%", color: "red" }}>
Invalid
</Text>
)}
<TextInput
placeholder="P/W"
value={password}
onChangeText={setPassword}
secureTextEntry
style={styles.input}
/>
<TextInput
placeholder="P/W 확인"
value={passwordConfirm}
onChangeText={(text) => {
setPasswordConfirm(text);
verifyPw(text);
}}
secureTextEntry
style={styles.input}
/>
{pwEqual == null ? (
""
) : pwEqual ? (
<Text style={{ fontSize: 14, left: "3%", color: "blue" }}>
Valid
</Text>
) : (
<Text style={{ fontSize: 14, left: "3%", color: "red" }}>
Invalid
</Text>
)}
</View>
</View>
<Text style={styles.textGoal}>Weekly Goals</Text>
<View style={styles.radioGroup}>
{learningLevels.map((level) => (
<TouchableOpacity
key={level}
style={styles.radioButton}
onPress={() => handleSelectLearningLevel(level)}
>
<Text style={styles.radioText}>{level}</Text>
<View style={styles.outerCircle}>
{selectedLearningLevel === level && (
<View style={styles.innerCircle} />
)}
</View>
</TouchableOpacity>
))}
</View>
<Text style={styles.textInterest}>Interests</Text>
<View style={styles.interestContainer}>
<FlatList
data={interests1}
style={styles.interestBox}
renderItem={renderInterestItem}
keyExtractor={(item) => item}
horizontal={true}
/>
<FlatList
data={interests2}
style={styles.interestBox}
renderItem={renderInterestItem}
keyExtractor={(item) => item}
horizontal={true}
/>
</View>
{/* 회원가입 버튼 */}
<TouchableOpacity style={styles.button} onPress={handleSignup}>
<Text style={styles.buttonText}>Sign Up</Text>
</TouchableOpacity>
{/* 스위치 */}
{/* <View style={styles.switchContainer}>
<Text style={styles.switchLabel}>약관에 동의합니다</Text>
<Switch
trackColor={{ false: "#767577", true: "#81b0ff" }}
thumbColor={isAgree ? "#f5dd4b" : "#f4f3f4"}
ios_backgroundColor="#3e3e3e"
onValueChange={toggleSwitch}
value={isAgree}
/>
</View> */}
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "white",
flexDirection: "column",
},
wrapContainer: {
flexDirection: "row",
minWidth: "100%",
height: 300,
},
leftContainer: {
flexDirection: "column",
left: 0,
minWidth: "20%",
},
rightContainer: {
flexDirection: "column",
minWidth: "72%",
left: "5%",
},
label: {
width: "110%",
justifyContent: "center",
alignItems: "left",
height: 40,
marginTop: "17%",
marginBottom: "20%",
textAlign: "left",
left: "15%",
},
labelText: {
fontSize: 12,
},
input: {
width: "90%",
justifyContent: "center",
alignItems: "center",
height: 40,
borderBottomWidth: 1,
borderColor: "#55433B",
marginVertical: "5%",
left: "3%",
},
rowContainer: {
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
width: "100%",
paddingHorizontal: "3%",
position: "relative",
},
emailInput: {
width: "70%", // 이메일 입력란의 너비
height: 40,
borderBottomWidth: 1,
borderColor: "#55433B",
marginRight: 10, // 버튼과의 간격
marginVertical: "5%",
},
authInput: {
width: "70%", // 이메일 입력란의 너비
height: 40,
borderBottomWidth: 1,
borderColor: "#55433B",
marginRight: 10, // 버튼과의 간격
},
authButton: {
justifyContent: "center",
alignItems: "center",
backgroundColor: "#55433B",
maxWidth: "100%",
position: "absolute",
right: "5%",
bottom: "10%",
padding: 10,
borderRadius: 20,
marginBottom: 15,
// 여기에 추가 버튼 스타일을 정의할 수 있어
},
authText: {
color: "white",
backgroundColor: "rgba(0, 0, 0, 0)",
},
textGoal: {
color: "#55433B",
fontSize: 20,
fontWeight: "500",
textAlign: "center",
marginTop: 110,
},
textInterest: {
color: "#55433B",
fontSize: 20,
fontWeight: "500",
textAlign: "center",
marginTop: 5,
marginBottom: 3,
},
radioGroup: {
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
marginVertical: 20,
},
radioButton: {
flexDirection: "row",
justifyContent: "center",
alignItems: "center",
minWidth: "33%",
},
radioText: {
marginRight: 8,
color: "#55433B",
},
// 스위치와 관련된 스타일을 추가합니다.
switchContainer: {
flexDirection: "row",
alignItems: "center",
marginBottom: 20,
},
switchLabel: {
marginRight: 10,
},
outerCircle: {
// ... Styles for the outer circle of the radio button
height: 20,
width: 20,
borderRadius: 10,
borderWidth: 1,
borderColor: "#55433B",
alignItems: "center",
justifyContent: "center",
marginRight: 10,
},
innerCircle: {
// ... Styles for the inner circle of the radio button
height: 10,
width: 10,
borderRadius: 5,
backgroundColor: "#55433B",
},
interestContainer: {
flex: 1,
justifyContent: "center",
alignItems: "center",
maxHeight: 110,
},
interestBox: {
flexGrow: 0,
flexDirection: "row",
},
interestButtonBox: {
marginHorizontal: 10, // Space between items
justifyContent: "center",
alignItems: "center",
},
interestButton: {
paddingHorizontal: 10,
paddingVertical: 5,
borderWidth: 1,
borderColor: "#55433B",
borderRadius: 15,
backgroundColor: "transparent",
marginVertical: 5,
},
selectedInterestButton: {
backgroundColor: "#55433B",
},
interestButtonText: {
color: "#55433B",
},
selectedInterestButtonText: {
color: "white",
},
button: {
backgroundColor: "#55433B", // 버튼의 배경색
padding: 10, // 버튼 안쪽의 여백
borderRadius: 5, // 버튼의 모서리 둥글기
alignItems: "center", // 텍스트를 중앙에 정렬
justifyContent: "center",
maxWidth: "50%",
marginHorizontal: "25%",
marginVertical: "10%",
marginTop: "5%",
marginBottom: "5%",
},
buttonText: {
color: "white",
},
});
export default SignupScreen;