diff options
author | Ivan Chen <ivan@tagg.id> | 2021-03-29 14:02:31 -0400 |
---|---|---|
committer | Ivan Chen <ivan@tagg.id> | 2021-03-29 14:02:31 -0400 |
commit | 04bf806285e7626644234b7febee2dad5c912f8d (patch) | |
tree | 9ed3ec581792d6a0e1135f02a1d4716890ca75fc /src/services/UserProfileService.ts | |
parent | e8324a7278a82d926acceedc10921f0b14e6d403 (diff) | |
parent | 4de1ebd43437712e28a89bb624c5b12afad45cc6 (diff) |
Merge branch 'master' into tma-701-private-account-banner
# Conflicts:
# src/constants/strings.ts
Diffstat (limited to 'src/services/UserProfileService.ts')
-rw-r--r-- | src/services/UserProfileService.ts | 48 |
1 files changed, 40 insertions, 8 deletions
diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts index e00c0530..085787c3 100644 --- a/src/services/UserProfileService.ts +++ b/src/services/UserProfileService.ts @@ -2,6 +2,7 @@ import AsyncStorage from '@react-native-community/async-storage'; import moment from 'moment'; import {Alert} from 'react-native'; import { + EDIT_PROFILE_ENDPOINT, GET_FB_POSTS_ENDPOINT, GET_IG_POSTS_ENDPOINT, GET_TWITTER_POSTS_ENDPOINT, @@ -296,16 +297,19 @@ export const sendRegister = async ( password: string, ) => { try { + const form = new FormData(); + form.append('first_name', firstName); + form.append('last_name', lastName); + form.append('email', email); + form.append('phone_number', phone); + form.append('username', username); + form.append('password', password); const response = await fetch(REGISTER_ENDPOINT, { method: 'POST', - body: JSON.stringify({ - first_name: firstName, - last_name: lastName, - email: email, - phone_number: phone, - username: username, - password: password, - }), + headers: { + 'Content-Type': 'multipart/form-data', + }, + body: form, }); return response; } catch (error) { @@ -334,3 +338,31 @@ export const fetchUserProfile = async (userId: string, token?: string) => { return undefined; } }; + +export const patchEditProfile = async (form: FormData, userId: string) => { + 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: form, + }); + let statusCode = response.status; + if (statusCode === 200) { + return true; + } else if (statusCode === 400) { + let data = await response.json(); + throw ( + 'Profile update failed. 😔' + data.error || 'Something went wrong! ðŸ˜' + ); + } else { + throw ERROR_SOMETHING_WENT_WRONG_REFRESH; + } + } catch (error) { + throw ERROR_DOUBLE_CHECK_CONNECTION; + } +}; |