-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateTeam.js
232 lines (214 loc) · 7.59 KB
/
createTeam.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
import React from 'react';
import Icon from 'react-native-vector-icons/Ionicons';
import {
StyleSheet,
Text,
View,
Image,
TextInput,
ScrollView,
Button,
Picker,
Alert,
TouchableHighlight,
FlatList,
TouchableOpacity,
AsyncStorage
} from 'react-native';
export default class createTeam extends React.Component {
state={
teamName:"",
teamDes:"",
teamLoc:"",
teamId:0,
userId:"",
}
componentDidMount() {
this._loadInitialState().done();
}
// AsyncStorage for login data processing
_loadInitialState=async()=>{
var phone = await AsyncStorage.getItem('phone');
this.setState({userId:phone})
}
// AsyncStorage for login data processing
createTeam=()=>{
const {teamName} = this.state
const {teamLoc} = this.state
const {teamDes} = this.state
fetch('http://localhost:8080/piedpiper/createTeam.php', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
teamName:teamName,
teamLoc: teamLoc,
teamDes:teamDes,
})
})
.then((response) => response.json())
.then((responseData) => {
console.log("inside responsejson"+responseData);
console.log('response object:'+JSON.stringify(responseData))
if (responseData.msg=="insertion_team_ok"){
this.setState({
teamId:responseData.id
})
console.log(" Inserting to Team is success",this.state.teamId);
this.insertToTeamMembers(this.state.teamId);
}
else if(responseData=="insertion_team_fail"){
alert("Inserting to tracks is failed")
}
else {
alert("Idk What happend")
}
}).catch((error)=> {
console.error("Error Message 1"+error)
});
}
insertToTeamMembers=(teamId)=>{
const {userId} = this.state
fetch('http://localhost:8080/piedpiper/insertToTeamMembers.php', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
userId:userId,
teamId:teamId,
})
})
.then((response) => response.json())
.then((responseData) => {
console.log("inside responsejson"+responseData);
console.log('response object:'+JSON.stringify(responseData))
if (responseData.msg=="insertion_teamDetails_ok"){
console.log(" Inserting to TeamDetails is success",this.state.teamId);
}
else if(responseData=="insertion_teamDetails_fail"){
alert("Inserting to TeamDetails is failed")
}
else {
alert("Idk What happend")
}
}).catch((error)=> {
console.error("Error Message 1"+error)
});
}
render(){
return (
<View style={styles.container}>
<View style={styles.SectionStyle}>
<View style={styles.gridChild1}>
<View>
<TouchableOpacity onPress={() => this.props.navigation.navigate('ProfileScreen')} >
<Icon name={'ios-arrow-back'} size={22} color='coral' style={{marginLeft: '3%'}}/>
</TouchableOpacity>
</View>
<View>
<TouchableOpacity style={styles.k} onPress={() => this.props.navigation.navigate('ProfileScreen')}>
<Text style={{color:"coral",fontWeight:"bold", margin:5}}>Done</Text>
</TouchableOpacity>
</View>
</View>
</View>
<Text style={styles.TeamViewHeaderFont1}>Create Team </Text>
<View style={styles.gridChild}>
<Icon name={'ios-cloud-upload'} size={32} color='black' style={{marginLeft: '3%',paddingRight:5}}/>
<View style={styles.inputView}>
<TextInput style={styles.inputText}
placeholder="Type Team Name..."
placeholderTextColor="black"
onChangeText={teamName => this.setState({teamName})}/>
</View>
</View>
<View>
<Text>Description</Text>
<View style={styles.inputView}>
<TextInput style={styles.inputText}
placeholder="About your Team..."
placeholderTextColor="black"
onChangeText={teamDes => this.setState({teamDes})}/>
</View>
</View>
<View>
<Text>Location</Text>
<View style={styles.inputView}>
<TextInput style={styles.inputText}
placeholder="Location..."
placeholderTextColor="black"
onChangeText={teamLoc => this.setState({teamLoc})}/>
</View>
</View>
<TouchableOpacity style={styles.loginBtn} onPress={this.createTeam}>
<Text style={styles.loginText}>Create</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
padding: 10,
flex: 1,
backgroundColor:'white',
},
loginBtn:{
width:"50%",
backgroundColor:"coral",
borderRadius:5,
height:50,
alignItems:"center",
justifyContent:"center",
marginTop:40,
marginBottom:10
},
loginText:{
color:"black"
},
SectionStyle: {
//flexDirection: 'row',
marginTop:30,
height: 40,
},
TeamViewHeaderFont1:{
fontSize:25,
color:"tomato",
fontWeight:'500',
padding:5,
margin:5,
},
gridChild1:{
justifyContent:'space-between',
flexDirection:'row',
flexWrap:'wrap',
},
gridChild:{
marginLeft:20,
marginRight:20,
marginTop:10,
justifyContent:'flex-start' ,
flexDirection:'row',
flexWrap:'wrap',
},
inputText:{
height:50,
alignItems: 'flex-start',
fontSize:15,
color:'black'
},
inputView:{
width:"80%",
borderRadius:5,
height:30,
marginBottom:20,
justifyContent:"center",
borderBottomColor: 'gray',
borderBottomWidth: 1,
marginLeft:10
},
});