From 84c88301710de2a2500e89191bdef49846b34f12 Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Thu, 11 Feb 2021 07:00:17 -0800 Subject: added async function to services for backend call --- src/services/UserProfileService.ts | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/services') diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts index d0610714..39c99f33 100644 --- a/src/services/UserProfileService.ts +++ b/src/services/UserProfileService.ts @@ -2,7 +2,7 @@ import AsyncStorage from '@react-native-community/async-storage'; import moment from 'moment'; import {Alert} from 'react-native'; import RNFetchBlob from 'rn-fetch-blob'; -import {SocialAccountType} from '../types'; +import {SocialAccountType, UserType} from '../types'; import { PROFILE_PHOTO_ENDPOINT, HEADER_PHOTO_ENDPOINT, @@ -15,6 +15,7 @@ import { VERIFY_OTP_ENDPOINT, SEND_OTP_ENDPOINT, PROFILE_PHOTO_THUMBNAIL_ENDPOINT, + EDIT_PROFILE_ENDPOINT, } from '../constants'; import { ERROR_DOUBLE_CHECK_CONNECTION, @@ -49,10 +50,15 @@ export const loadProfileInfo = async (token: string, userId: string) => { tiktok, university_class, profile_completion_stage, + sp_swipe_tutorial, friendship_status, friendship_requester_id, } = info; birthday = birthday && moment(birthday).format('YYYY-MM-DD'); + console.log( + 'Suggested People loaded from backend for logged in user: ', + sp_swipe_tutorial, + ); return { name, biography, @@ -63,6 +69,7 @@ export const loadProfileInfo = async (token: string, userId: string) => { tiktok, university_class, profile_completion_stage, + sp_swipe_tutorial, friendship_status, friendship_requester_id, }; @@ -313,3 +320,29 @@ export const sendOtp = async (phone: string) => { return false; } }; + +export const editSPSwipeTutorial = async (user: UserType) => { + try { + const request = new FormData(); + request.append('sp_swipe_tutorial', 1); + const endpoint = EDIT_PROFILE_ENDPOINT + `${user.userId}/`; + const token = await AsyncStorage.getItem('token'); + console.log('token: ', token); + let response = await fetch(endpoint, { + method: 'PATCH', + headers: { + 'Content-Type': 'multipart/form-data', + Authorization: 'Token ' + token, + }, + body: request, + }); + if (response.status === 200) { + console.log('updatedbackend'); + return true; + } else { + return false; + } + } catch (error) { + console.log('Error updating animated tutorial close button press'); + } +}; -- cgit v1.2.3-70-g09d2 From ebc1b4dd9a39a1d82cb81f070bcae1f9f2146832 Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Thu, 11 Feb 2021 13:56:40 -0800 Subject: removed console log for token --- src/services/UserProfileService.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'src/services') diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts index 39c99f33..9061dd5e 100644 --- a/src/services/UserProfileService.ts +++ b/src/services/UserProfileService.ts @@ -327,7 +327,6 @@ export const editSPSwipeTutorial = async (user: UserType) => { request.append('sp_swipe_tutorial', 1); const endpoint = EDIT_PROFILE_ENDPOINT + `${user.userId}/`; const token = await AsyncStorage.getItem('token'); - console.log('token: ', token); let response = await fetch(endpoint, { method: 'PATCH', headers: { -- cgit v1.2.3-70-g09d2 From da61f04d037d92fce7cf9852a3be79eb41158d5a Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Thu, 11 Feb 2021 14:04:04 -0800 Subject: dispatching reducer while updating backend --- src/services/UserProfileService.ts | 1 - src/store/actions/user.ts | 10 ++++------ 2 files changed, 4 insertions(+), 7 deletions(-) (limited to 'src/services') diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts index 9061dd5e..3bca66f3 100644 --- a/src/services/UserProfileService.ts +++ b/src/services/UserProfileService.ts @@ -336,7 +336,6 @@ export const editSPSwipeTutorial = async (user: UserType) => { body: request, }); if (response.status === 200) { - console.log('updatedbackend'); return true; } else { return false; diff --git a/src/store/actions/user.ts b/src/store/actions/user.ts index 98e1727b..50f810e4 100644 --- a/src/store/actions/user.ts +++ b/src/store/actions/user.ts @@ -158,12 +158,10 @@ export const updateSPSwipeTutorial = ( > => async (dispatch) => { try { const success = await editSPSwipeTutorial(user); - if (success) { - dispatch({ - type: spSwipeTutorialUpdated.type, - payload: {sp_swipe_tutorial: data}, - }); - } + dispatch({ + type: spSwipeTutorialUpdated.type, + payload: {sp_swipe_tutorial: data}, + }); return success; } catch (error) { console.log('Error while updating suggested people linked state: ', error); -- cgit v1.2.3-70-g09d2