diff options
Diffstat (limited to 'src/services/UserProfileService.ts')
-rw-r--r-- | src/services/UserProfileService.ts | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts index 085787c3..c1901be1 100644 --- a/src/services/UserProfileService.ts +++ b/src/services/UserProfileService.ts @@ -1,6 +1,8 @@ import AsyncStorage from '@react-native-community/async-storage'; import moment from 'moment'; +import {useEffect} from 'react'; import {Alert} from 'react-native'; +import {loadUserData} from '../store/actions'; import { EDIT_PROFILE_ENDPOINT, GET_FB_POSTS_ENDPOINT, @@ -20,6 +22,7 @@ import { ERROR_DOUBLE_CHECK_CONNECTION, ERROR_DUP_OLD_PWD, ERROR_INVALID_PWD_CODE, + ERROR_PROFILE_UPDATE_SHORT, ERROR_PWD_ACCOUNT, ERROR_SOMETHING_WENT_WRONG, ERROR_SOMETHING_WENT_WRONG_REFRESH, @@ -27,7 +30,12 @@ import { SUCCESS_PWD_RESET, SUCCESS_VERIFICATION_CODE_SENT, } from '../constants/strings'; -import {ProfileInfoType, ProfileType, SocialAccountType} from '../types'; +import { + ProfileInfoType, + ProfileType, + SocialAccountType, + UserType, +} from '../types'; export const loadProfileInfo = async (token: string, userId: string) => { try { @@ -75,6 +83,43 @@ export const getProfilePic = async ( } }; +export const updateProfileVisibility = async ( + token: string, + user: UserType, + isPrivateAccount: Boolean, + dispatch: Function, +) => { + try { + const url = EDIT_PROFILE_ENDPOINT + `${user.userId}/`; + const request = new FormData(); + request.append('is_private', isPrivateAccount); + let response = await fetch(url, { + method: 'PATCH', + headers: { + 'Content-Type': 'application/json', + Authorization: 'Token ' + token, + }, + body: request, + }); + const {status} = response; + let data = await response.json(); + if (status === 200) { + dispatch(loadUserData(user)); + } else if (status >= 400) { + Alert.alert( + ERROR_PROFILE_UPDATE_SHORT, + data.error || 'Something went wrong! ðŸ˜', + ); + } + } catch (error) { + Alert.alert(ERROR_PROFILE_UPDATE_SHORT, ERROR_DOUBLE_CHECK_CONNECTION); + return { + name: 'Profile update error', + description: error, + }; + } +}; + const integratedSocialPostsEndpoints: {[social: string]: string} = { Facebook: GET_FB_POSTS_ENDPOINT, Instagram: GET_IG_POSTS_ENDPOINT, |