Fix updating profile on app
This commit is contained in:
@@ -13,19 +13,20 @@ import * as ImagePicker from 'expo-image-picker';
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
let ProfileSettings = ()=>{
|
let ProfileSettings = () => {
|
||||||
const gState = useSnapshot(GlobalState);
|
const gState = useSnapshot(GlobalState);
|
||||||
const viewer = gState.me;
|
const viewer = gState.me;
|
||||||
const [photo, setPhoto] = React.useState(null);
|
const [photo, setPhoto] = React.useState(null);
|
||||||
const [name, setName] = React.useState(viewer.profile.firstName);
|
const [name, setName] = React.useState(viewer.profile.firstName);
|
||||||
const [lastName, setLastName] = React.useState(viewer.profile.lastName);
|
const [lastName, setLastName] = React.useState(viewer.profile.lastName);
|
||||||
const [photoUrl, setphotoUrl] = React.useState(viewer.profile.photo);
|
const [photoUrl, setphotoUrl] = React.useState(viewer.profile.photo);
|
||||||
|
const [language, setLanguage] = React.useState(viewer.profile.language);
|
||||||
const [updateKey, setUpdateKey] = React.useState(0);
|
const [updateKey, setUpdateKey] = React.useState(0);
|
||||||
const [description, setDescription] = React.useState(viewer.profile.description);
|
const [description, setDescription] = React.useState(viewer.profile.description);
|
||||||
const [uploading, setUploading] = React.useState(false);
|
const [uploading, setUploading] = React.useState(false);
|
||||||
|
|
||||||
const pickImage = async () => {
|
const pickImage = async () => {
|
||||||
if(uploading) return;
|
if (uploading) return;
|
||||||
// No permissions request is necessary for launching the image library
|
// No permissions request is necessary for launching the image library
|
||||||
let result = await ImagePicker.launchImageLibraryAsync({
|
let result = await ImagePicker.launchImageLibraryAsync({
|
||||||
mediaTypes: ImagePicker.MediaTypeOptions.Images,
|
mediaTypes: ImagePicker.MediaTypeOptions.Images,
|
||||||
@@ -38,7 +39,7 @@ let ProfileSettings = ()=>{
|
|||||||
setUploading(true);
|
setUploading(true);
|
||||||
setPhoto(result);
|
setPhoto(result);
|
||||||
let newPhotoURL = await handleUploadPhoto(result.assets[0]);
|
let newPhotoURL = await handleUploadPhoto(result.assets[0]);
|
||||||
if(newPhotoURL !== ""){
|
if (newPhotoURL !== "") {
|
||||||
setphotoUrl(newPhotoURL);
|
setphotoUrl(newPhotoURL);
|
||||||
GlobalState.me.profile.photo = newPhotoURL;
|
GlobalState.me.profile.photo = newPhotoURL;
|
||||||
updateProfile()
|
updateProfile()
|
||||||
@@ -88,12 +89,27 @@ let ProfileSettings = ()=>{
|
|||||||
return uploadedFile;
|
return uploadedFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
let updateProfile = () => {
|
let updateProfile = async () => {
|
||||||
GlobalState.me.profile.firstName = name;
|
let currentProfile = await API.getUserProfile(viewer._id)
|
||||||
GlobalState.me.profile.lastName = lastName;
|
currentData = currentProfile.data;
|
||||||
GlobalState.me.profile.description = description;
|
currentProfile = currentProfile.profile;
|
||||||
API.updateMyProfile(GlobalState.me.profile, viewer.data);
|
try {
|
||||||
setUpdateKey(updateKey+1);
|
//let currentProfile = JSON.parse(JSON.stringify(viewer.profile));
|
||||||
|
currentProfile.firstName = name;
|
||||||
|
currentProfile.lastName = lastName;
|
||||||
|
currentProfile.description = description;
|
||||||
|
currentProfile.language = language;
|
||||||
|
currentProfile.photo = photoUrl;
|
||||||
|
console.log("updating", currentProfile);
|
||||||
|
} catch (error) {
|
||||||
|
alert("Error updating profile, contact administrator.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let r = await API.updateMyProfile(currentProfile, currentData).catch((e) => {
|
||||||
|
alert("Error updating profile, contact administrator.");
|
||||||
|
});
|
||||||
|
console.log(r);
|
||||||
|
setUpdateKey(updateKey + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -101,82 +117,84 @@ let ProfileSettings = ()=>{
|
|||||||
padding: 10,
|
padding: 10,
|
||||||
}}>
|
}}>
|
||||||
<ImageBackground source={require("../assets/settings.png")}
|
<ImageBackground source={require("../assets/settings.png")}
|
||||||
imageStyle={{resizeMode:"contain", opacity: 0.05}}
|
imageStyle={{ resizeMode: "contain", opacity: 0.05 }}
|
||||||
style={{paddingBottom: 50}}
|
style={{ paddingBottom: 50 }}
|
||||||
>
|
>
|
||||||
<Text style={{marginBottom:10, fontSize:20}}>Profile Settings</Text>
|
<Text style={{ marginBottom: 10, fontSize: 20 }}>Profile Settings</Text>
|
||||||
<View style={{flexDirection:"row", justifyContent:"space-between"}}>
|
<View style={{ flexDirection: "row", justifyContent: "space-between" }}>
|
||||||
<TextInput
|
<TextInput
|
||||||
label={i18n.t("message.name")}
|
label={i18n.t("message.name")}
|
||||||
style={{width:"48%", backgroundColor:"rgba(0,0,0,0)"}}
|
style={{ width: "48%", backgroundColor: "rgba(0,0,0,0)" }}
|
||||||
value={name}
|
value={name}
|
||||||
onChangeText={text => setName(text)}
|
onChangeText={text => setName(text)}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
label={i18n.t("message.lastName")}
|
label={i18n.t("message.lastName")}
|
||||||
style={{width:"48%", backgroundColor:"rgba(0,0,0,0)"}}
|
style={{ width: "48%", backgroundColor: "rgba(0,0,0,0)" }}
|
||||||
value={lastName}
|
value={lastName}
|
||||||
onChangeText={text => setLastName(text)}
|
onChangeText={text => setLastName(text)}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<TextInput
|
<TextInput
|
||||||
label={i18n.t("message.description")}
|
label={i18n.t("message.description")}
|
||||||
style={{backgroundColor:"rgba(0,0,0,0)", marginBottom:5}}
|
style={{ backgroundColor: "rgba(0,0,0,0)", marginBottom: 5 }}
|
||||||
multiline={true}
|
multiline={true}
|
||||||
numberOfLines={3}
|
numberOfLines={3}
|
||||||
value={description}
|
value={description}
|
||||||
onChangeText={text => setDescription(text)}
|
onChangeText={text => setDescription(text)}
|
||||||
/>
|
/>
|
||||||
<Text>Language:</Text>
|
<Text>Language:</Text>
|
||||||
<View style={{flexDirection:"row"}}>
|
<View style={{ flexDirection: "row" }}>
|
||||||
<RadioButton.Group value='en' style={{flexDirection:"row"}}>
|
<RadioButton.Group value={language} onValueChange={setLanguage} style={{ flexDirection: "row" }}>
|
||||||
<RadioButton.Item value="es" label="Español"/>
|
<RadioButton.Item value="es" label="Español" />
|
||||||
<RadioButton.Item value="en" label="English"/>
|
<RadioButton.Item value="en" label="English" />
|
||||||
|
<RadioButton.Item value="da" label="Danish" />
|
||||||
|
<RadioButton.Item value="fr" label="French" />
|
||||||
</RadioButton.Group>
|
</RadioButton.Group>
|
||||||
</View>
|
</View>
|
||||||
<Button icon="photo" mode="outlined" onPress={pickImage}>{!uploading ? i18n.t("message.updatePhoto"): "uploading"}</Button>
|
<Button icon="photo" mode="outlined" onPress={pickImage}>{!uploading ? i18n.t("message.updatePhoto") : "uploading"}</Button>
|
||||||
<Divider />
|
<Divider />
|
||||||
<View style={{paddingTop: 10}}>
|
<View style={{ paddingTop: 10 }}>
|
||||||
<Text style={{fontSize:20, padding: 5, color:"#666"}}>Preview:</Text>
|
<Text style={{ fontSize: 20, padding: 5, color: "#666" }}>Preview:</Text>
|
||||||
<ProfileCardHorizontal profileObj={GlobalState.me} skipFollow={true} skiptOnPress={true} key={updateKey} />
|
<ProfileCardHorizontal profileObj={GlobalState.me} skipFollow={true} skiptOnPress={true} key={updateKey} />
|
||||||
</View>
|
</View>
|
||||||
<Button mode="outlined" onPress={updateProfile}>{i18n.t("message.update")}</Button>
|
<Button mode="outlined" onPress={updateProfile}>{i18n.t("message.update")}</Button>
|
||||||
<Divider />
|
<Divider />
|
||||||
<Text style={{fontSize:20, padding: 5, color:"#666"}}>{i18n.t("message.optional")}:</Text>
|
<Text style={{ fontSize: 20, padding: 5, color: "#666" }}>{i18n.t("message.optional")}:</Text>
|
||||||
<View style={{flexDirection:"row", justifyContent:"space-evenly"}}>
|
<View style={{ flexDirection: "row", justifyContent: "space-evenly" }}>
|
||||||
<Checkbox.Item status={'unchecked'} label="Married" />
|
<Checkbox.Item status={'unchecked'} label="Married" />
|
||||||
<Checkbox.Item status={'unchecked'} label="With Kids" />
|
<Checkbox.Item status={'unchecked'} label="With Kids" />
|
||||||
</View>
|
</View>
|
||||||
<Text>{i18n.t("message.birthday")}</Text>
|
<Text>{i18n.t("message.birthday")}</Text>
|
||||||
<View style={{flexDirection:"row", justifyContent:"space-between"}}>
|
<View style={{ flexDirection: "row", justifyContent: "space-between" }}>
|
||||||
<TextInput
|
<TextInput
|
||||||
label={"Day:"}
|
label={"Day:"}
|
||||||
style={{width:"48%", backgroundColor:"rgba(0,0,0,0)"}}
|
style={{ width: "48%", backgroundColor: "rgba(0,0,0,0)" }}
|
||||||
//value={name}
|
//value={name}
|
||||||
//onChangeText={text => setName(text)}
|
//onChangeText={text => setName(text)}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
label={"Month:"}
|
label={"Month:"}
|
||||||
style={{width:"48%", backgroundColor:"rgba(0,0,0,0)"}}
|
style={{ width: "48%", backgroundColor: "rgba(0,0,0,0)" }}
|
||||||
//value={lastName}
|
//value={lastName}
|
||||||
//onChangeText={text => setLastName(text)}
|
//onChangeText={text => setLastName(text)}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<TextInput
|
<TextInput
|
||||||
label={i18n.t("message.localMinistry")}
|
label={i18n.t("message.localMinistry")}
|
||||||
style={{backgroundColor:"rgba(0,0,0,0)"}}
|
style={{ backgroundColor: "rgba(0,0,0,0)" }}
|
||||||
//value={lastName}
|
//value={lastName}
|
||||||
//onChangeText={text => setLastName(text)}
|
//onChangeText={text => setLastName(text)}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
label={i18n.t("message.country")}
|
label={i18n.t("message.country")}
|
||||||
style={{backgroundColor:"rgba(0,0,0,0)"}}
|
style={{ backgroundColor: "rgba(0,0,0,0)" }}
|
||||||
//value={lastName}
|
//value={lastName}
|
||||||
//onChangeText={text => setLastName(text)}
|
//onChangeText={text => setLastName(text)}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
label={i18n.t("message.ocupation")}
|
label={i18n.t("message.ocupation")}
|
||||||
style={{backgroundColor:"rgba(0,0,0,0)"}}
|
style={{ backgroundColor: "rgba(0,0,0,0)" }}
|
||||||
//value={lastName}
|
//value={lastName}
|
||||||
//onChangeText={text => setLastName(text)}
|
//onChangeText={text => setLastName(text)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user