From fce958fbfca5a7f19863ff7222bb9bd0d7fa6668 Mon Sep 17 00:00:00 2001 From: Adolfo Reyna Date: Mon, 10 Feb 2025 21:44:37 -0500 Subject: [PATCH] Fix updating profile on app --- Views/ProfileSettings.js | 114 ++++++++++++++++++++++----------------- 1 file changed, 66 insertions(+), 48 deletions(-) diff --git a/Views/ProfileSettings.js b/Views/ProfileSettings.js index c80e576..d53ce4a 100644 --- a/Views/ProfileSettings.js +++ b/Views/ProfileSettings.js @@ -13,19 +13,20 @@ import * as ImagePicker from 'expo-image-picker'; -let ProfileSettings = ()=>{ +let ProfileSettings = () => { const gState = useSnapshot(GlobalState); const viewer = gState.me; const [photo, setPhoto] = React.useState(null); const [name, setName] = React.useState(viewer.profile.firstName); const [lastName, setLastName] = React.useState(viewer.profile.lastName); const [photoUrl, setphotoUrl] = React.useState(viewer.profile.photo); + const [language, setLanguage] = React.useState(viewer.profile.language); const [updateKey, setUpdateKey] = React.useState(0); const [description, setDescription] = React.useState(viewer.profile.description); const [uploading, setUploading] = React.useState(false); const pickImage = async () => { - if(uploading) return; + if (uploading) return; // No permissions request is necessary for launching the image library let result = await ImagePicker.launchImageLibraryAsync({ mediaTypes: ImagePicker.MediaTypeOptions.Images, @@ -38,7 +39,7 @@ let ProfileSettings = ()=>{ setUploading(true); setPhoto(result); let newPhotoURL = await handleUploadPhoto(result.assets[0]); - if(newPhotoURL !== ""){ + if (newPhotoURL !== "") { setphotoUrl(newPhotoURL); GlobalState.me.profile.photo = newPhotoURL; updateProfile() @@ -88,98 +89,115 @@ let ProfileSettings = ()=>{ return uploadedFile; }; - let updateProfile = () => { - GlobalState.me.profile.firstName = name; - GlobalState.me.profile.lastName = lastName; - GlobalState.me.profile.description = description; - API.updateMyProfile(GlobalState.me.profile, viewer.data); - setUpdateKey(updateKey+1); + let updateProfile = async () => { + let currentProfile = await API.getUserProfile(viewer._id) + currentData = currentProfile.data; + currentProfile = currentProfile.profile; + try { + //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 ( - - Profile Settings - + Profile Settings + setName(text)} /> setLastName(text)} /> setDescription(text)} /> Language: - - - - + + + + + + - + - - Preview: + + Preview: - {i18n.t("message.optional")}: - + {i18n.t("message.optional")}: + {i18n.t("message.birthday")} - + setName(text)} + style={{ width: "48%", backgroundColor: "rgba(0,0,0,0)" }} + //value={name} + //onChangeText={text => setName(text)} /> setLastName(text)} + style={{ width: "48%", backgroundColor: "rgba(0,0,0,0)" }} + //value={lastName} + //onChangeText={text => setLastName(text)} /> setLastName(text)} - /> + label={i18n.t("message.localMinistry")} + style={{ backgroundColor: "rgba(0,0,0,0)" }} + //value={lastName} + //onChangeText={text => setLastName(text)} + /> setLastName(text)} - /> + label={i18n.t("message.country")} + style={{ backgroundColor: "rgba(0,0,0,0)" }} + //value={lastName} + //onChangeText={text => setLastName(text)} + /> setLastName(text)} - /> + label={i18n.t("message.ocupation")} + style={{ backgroundColor: "rgba(0,0,0,0)" }} + //value={lastName} + //onChangeText={text => setLastName(text)} + />