aboutsummaryrefslogtreecommitdiff
path: root/src/services/UserProfileService.ts
diff options
context:
space:
mode:
authorankit-thanekar007 <ankit.thanekar007@gmail.com>2021-03-25 13:51:14 -0700
committerankit-thanekar007 <ankit.thanekar007@gmail.com>2021-03-29 12:07:23 -0700
commit7a521127177838bcae0cd85b2e5bd912c46406b9 (patch)
tree19a470ea25cf725bb403060f27e397344bc6b373 /src/services/UserProfileService.ts
parentff3f0acadf810cd1b5bf276b9ee926f2c480b7be (diff)
Added API for updating account toggle
Diffstat (limited to 'src/services/UserProfileService.ts')
-rw-r--r--src/services/UserProfileService.ts47
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,