diff options
Diffstat (limited to 'src/screens/profile/EditProfile.tsx')
-rw-r--r-- | src/screens/profile/EditProfile.tsx | 38 |
1 files changed, 8 insertions, 30 deletions
diff --git a/src/screens/profile/EditProfile.tsx b/src/screens/profile/EditProfile.tsx index 56bed11f..8afaeb6d 100644 --- a/src/screens/profile/EditProfile.tsx +++ b/src/screens/profile/EditProfile.tsx @@ -46,6 +46,7 @@ import { ERROR_UPLOAD_SMALL_PROFILE_PIC, } from '../../constants/strings'; import TaggLoadingIndicator from '../../components/common/TaggLoadingIndicator'; +import {patchEditProfile} from '../../services'; type EditProfileNavigationProp = StackNavigationProp< MainStackParams, @@ -364,38 +365,15 @@ const EditProfile: React.FC<EditProfileProps> = ({route, navigation}) => { return; } - const endpoint = EDIT_PROFILE_ENDPOINT + `${userId}/`; - try { - const token = await AsyncStorage.getItem('token'); - let response = await fetch(endpoint, { - method: 'PATCH', - headers: { - 'Content-Type': 'multipart/form-data', - Authorization: 'Token ' + token, - }, - body: request, - }); - let statusCode = response.status; - let data = await response.json(); - if (statusCode === 200) { + patchEditProfile(request, userId) + .then((_) => { setNeedsUpdate(true); navigation.pop(); - } else if (statusCode === 400) { - Alert.alert( - 'Profile update failed. 😔', - data.error || 'Something went wrong! ðŸ˜', - ); - } else { - Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); - } - } catch (error) { - Alert.alert(ERROR_DOUBLE_CHECK_CONNECTION); - return { - name: 'Profile creation error', - description: error, - }; - } - }, [isCustomGender, form, navigation, userId]); + }) + .catch((error) => { + Alert.alert(error); + }); + }, [form, isCustomGender, university_class, userId, navigation]); React.useLayoutEffect(() => { navigation.setOptions({ |