-
Notifications
You must be signed in to change notification settings - Fork 0
/
Profile.tsx
298 lines (278 loc) · 9.83 KB
/
Profile.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
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
import React, { useEffect, useState } from "react";
import { SafeAreaView, StyleSheet, Text, View, Image, TextInput, TouchableOpacity, Alert } from "react-native";
import SelectDropdown from 'react-native-select-dropdown';
import Icon from 'react-native-vector-icons/dist/Ionicons';
import { launchCamera, launchImageLibrary } from 'react-native-image-picker';
import AsyncStorage from '@react-native-async-storage/async-storage';
export function Profile({ route, navigation }) {
const [firstName, setFirstName] = useState("");
const [lastName, setLastName] = useState("");
const [location, setLocation] = useState("Select Location"); // For upload selected country name
const [locations, setLocations] = useState(["Select Location"]); // For load all countries
const [selectLocation, setSelectLocation] = useState("Select Location"); // For load default country
const [profileImage, setProfileImage] = useState(null);
const [imgUri, setImgUri] = useState(route.params.profile_image_status == 1 ? "http://10.0.2.2/manthra/resources/images/profile_images/" + route.params.mobile + ".png" : "http://10.0.2.2/manthra/resources/images/user.png");
const ui = (
<SafeAreaView style={styles2.main}>
<View style={styles2.headerView}>
<TouchableOpacity style={styles2.backBtn} onPress={goToHome}>
<Icon name="chevron-back-outline" size={28} color="black" />
</TouchableOpacity>
<Text style={styles2.headerText}>Edit Profile</Text>
</View>
<Image source={{ uri: imgUri }} style={styles2.mianLogo} />
<TouchableOpacity onPress={selectProfilePicture} style={styles2.cameraBtn}>
<Icon name="camera-outline" size={38} color="black" />
</TouchableOpacity>
<Text style={styles2.mainLogoText}>{[route.params.first_name, " ", route.params.last_name]}</Text>
<View style={styles2.view1}>
<View style={styles2.view2}>
<TextInput autoCorrect={false} style={styles2.input2} maxLength={20} placeholder={route.params.first_name} onChangeText={setFirstName} />
<TextInput autoCorrect={false} style={styles2.input2} maxLength={20} placeholder={route.params.last_name} onChangeText={setLastName} />
</View>
<TextInput keyboardType="numeric" style={styles2.input} maxLength={10} placeholder={route.params.mobile} editable={false} />
<SelectDropdown
data={locations}
search={true}
searchInputTxtColor="black"
searchPlaceHolder="Search location"
defaultValue={selectLocation}
searchPlaceHolderColor="black"
renderSearchInputLeftIcon={searchIcon}
buttonStyle={styles2.input}
dropdownStyle={styles2.dropdown}
onSelect={assignLocation}
/>
<TouchableOpacity style={[styles2.btn, styles2.btnDark]} onPress={updateUser}>
<Text style={[styles2.btnText, styles2.btnTextWhite]}>Update Profile</Text>
</TouchableOpacity>
<TouchableOpacity style={[styles2.btn, styles2.btnDanger]} onPress={logOut}>
<Text style={[styles2.btnText, styles2.btnTextWhite]}>Log Out</Text>
</TouchableOpacity>
</View>
</SafeAreaView>
);
async function selectProfilePicture() {
const options = {
"mediaType": "photo",
};
const result = await launchImageLibrary(options);
if (result.didCancel) {
} else {
const imageObject = {
uri: result.assets[0].uri,
name: "profile.png",
type: "image/png",
}
setProfileImage(imageObject);
setImgUri(result.assets[0].uri);
}
}
function goToHome() {
navigation.navigate("Home");
}
function searchIcon() {
const icon = (
<Icon name="search-outline" size={18} color="black" />
);
return icon;
}
function assignLocation(selectedItem) {
setLocation(selectedItem);
}
function loadCountries() {
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
if (request.readyState == 4 && request.status == 200) {
var locationResponseArray = request.responseText;
setLocations(JSON.parse(locationResponseArray));
}
};
request.open("GET", "http://10.0.2.2/manthra/loadCountries.php", true);
request.send();
}
function loadSelectedCountry() {
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
if (request.readyState == 4 && request.status == 200) {
var text = request.responseText;
setSelectLocation(text);
}
};
request.open("GET", "http://10.0.2.2/manthra/loadCountries.php?id=" + route.params.id, true);
request.send();
}
useEffect(loadCountries, []);
useEffect(loadSelectedCountry, []);
function updateUser() {
var form = new FormData();
form.append("firstName", firstName);
form.append("lastName", lastName);
form.append("mobile", route.params.mobile);
form.append("location", location);
form.append("profileImage", profileImage);
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
if (request.readyState == 4 && request.status == 200) {
var userUpdateRespons = request.responseText;
if (userUpdateRespons != "success") {
Alert.alert("Message", userUpdateRespons);
} else {
Alert.alert("Message", "Profile update successful");
}
}
};
request.open("POST", "http://10.0.2.2/manthra/updateUser.php", true);
request.send(form);
}
async function logOut() {
// await AsyncStorage.removeItem("user");
Alert.alert("Message", "Log out successful");
goToApp();
}
function goToApp() {
navigation.navigate("Sign In");
}
return ui;
}
const styles2 = StyleSheet.create(
{
main: {
display: "flex",
flexDirection: "column",
flex: 1,
justifyContent: "flex-start",
alignItems: "center",
backgroundColor:"rgb(251, 255, 201)",
},
mianLogo: {
width: 130,
height: 130,
borderRadius: 65,
marginTop: 30,
},
mainLogoText: {
color: "#080808",
fontSize: 25,
fontWeight: "bold",
fontFamily: "Poppins",
marginTop: 10,
},
inputView: {
width: "100%",
paddingTop: 15,
},
inputText1: {
fontSize: 20,
color: "#080808",
marginBottom: 8
},
input: {
width: "100%",
borderStyle: "solid",
borderWidth: 2,
borderColor: "#0101003a",
borderRadius: 25,
paddingStart: 20,
paddingEnd: 20,
fontSize: 20,
height:50,
backgroundColor:"white",
},
input2: {
width: "48.5%",
borderStyle: "solid",
borderWidth: 2,
borderColor: "#0101003a",
borderRadius: 25,
paddingStart: 20,
paddingEnd: 20,
fontSize: 20,
height:50,
backgroundColor:"white",
},
view1: {
width: "100%",
paddingTop: 12,
gap: 10,
paddingHorizontal: 30,
},
view2: {
flexDirection: "row",
width: "100%",
paddingTop: 12,
gap: 8,
},
btn: {
width: "100%",
paddingVertical: 10,
borderStyle: "solid",
borderWidth: 2,
borderColor: "#0101003a",
borderRadius: 25,
flexDirection: "row",
justifyContent: "center",
height:50,
},
btnWarning: {
backgroundColor: "yellow",
},
btnDark: {
backgroundColor: "#080808",
}, btnDanger: {
backgroundColor: "#ff1306",
},
btnText: {
color: "#080808",
fontSize: 20,
fontWeight: "bold",
},
btnTextWhite: {
color: "#fff",
},
dropdown: {
backgroundColor: "yellow",
borderRadius: 15,
color: "black",
},
dropdownBtn: {
backgroundColor: "red",
},
searchInput: {
padding: 15,
color: "black",
fontSize: 22,
},
searchPlaceHolder: {
fontSize: 22,
color: "black",
opacity: 0.6,
},
headerView: {
width: "100%",
backgroundColor: "yellow",
flexDirection: "row",
alignItems: "center",
borderBottomEndRadius: 35,
borderBottomStartRadius: 35,
},
headerText: {
color: "#080808",
fontSize: 25,
fontWeight: "bold",
fontFamily: "Poppins",
marginVertical: 15,
paddingLeft: 15,
},
cameraBtn: {
backgroundColor: "rgba(255, 255, 0, 0.603)",
borderRadius: 50,
top: 170,
padding: 5,
position: "absolute",
},
backBtn: {
paddingLeft: 5,
}
}
);