-
Notifications
You must be signed in to change notification settings - Fork 0
/
JoinScreen.js
136 lines (112 loc) · 3.39 KB
/
JoinScreen.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
import React, { Component, useState } from "react";
import { View, Text, Button, StyleSheet, TextInput , ScrollView } from 'react-native';
import firestore , { doc } from '@react-native-firebase/firestore';
const style = StyleSheet.create({
container: {
backgroundColor: '#B9BFFF',
flex: 1
},
text: {
fontSize: 30,
color: '#21610B',
textAlign: 'center'
},
Button: {
color: 'black',
fontSize: 40,
backgroundColor: 'blue'
},
input: {
height: 40,
margin: 50,
borderWidth: 5,
padding: 10,
color: 'black'
},
})
export default class JoinScreen extends Component {
state ={
id:'',
id_list:[],
pw:'',
pw_list:[],
find_list:[]
}
onChageID = (event) => {
this.setState({
id: event
})
}
onChangePW = (event)=>{
this.setState({
pw : event
})
}
onAddMember = ()=>{
this.setState(prevState=>{
const ref = firestore().collection('Members').doc(prevState.id);
ref.set({
ID : prevState.id,
PW : prevState.pw
})
return{
id:'',
pw:'',
id_list:[...prevState.id],
pw_list:[...prevState.pw]
}
})
}
onFindMember =()=>{
this.setState(prevState=>{
const db = firestore().collection('Members');
db.doc(prevState.id).get().then((doc)=>{
console.log(doc.exists);
})
})
}
onJoin = ()=>{
this.setState(prevState=>{
const db = firestore().collection('Members');
db.doc(prevState.id).get().then((doc)=>{
if(!doc.exists){
db.doc(prevState.id).set({
ID : prevState.id,
PW : prevState.pw
})
alert("회원가입 성공. 이제 로그인이 가능합니다.")
this.props.navigation.navigate('Start')
}else{
alert("이미 사용중인 ID 입니다");
}
})
})
}
render() {
return (
<View style={style.container}>
<Text style={{ fontSize: 30 }}>Join Screen</Text>
<TextInput
style={style.input}
onChangeText={this.onChageID}
placeholder="ID"
value={this.state.id}
/>
<TextInput
style={style.input}
onChangeText={this.onChangePW}
placeholder="PW"
value={this.state.pw}
/>
<Button title="회원가입" onPress={this.onJoin} />
<Text>
{this.state.id_list}
</Text>
<Button onPress={() => this.gotoStartScreen()} title='back to Start' />
</View>
)
}
gotoStartScreen() {
this.props.navigation.navigate('Start')
}
}