aboutsummaryrefslogtreecommitdiff
path: root/src/services/UserProfileService.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/services/UserProfileService.ts')
-rw-r--r--src/services/UserProfileService.ts48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts
index 085787c3..1ce1d0b5 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,44 @@ 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 ? 'True' : 'False');
+ let response = await fetch(url, {
+ method: 'PATCH',
+ headers: {
+ 'Content-Type': 'multipart/form-data',
+ Authorization: 'Token ' + token,
+ },
+ body: request,
+ });
+ const {status} = response;
+ let data = await response.json();
+ if (status === 200) {
+ await dispatch(loadUserData(user));
+ } else if (status >= 400) {
+ Alert.alert(
+ ERROR_PROFILE_UPDATE_SHORT,
+ data.error || 'Something went wrong! 😭',
+ );
+ }
+ } catch (error) {
+ debugger;
+ 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,