diff options
Diffstat (limited to 'src/store/actions')
| -rw-r--r-- | src/store/actions/userX.ts | 77 |
1 files changed, 52 insertions, 25 deletions
diff --git a/src/store/actions/userX.ts b/src/store/actions/userX.ts index 325c7568..5d49cdf9 100644 --- a/src/store/actions/userX.ts +++ b/src/store/actions/userX.ts @@ -1,8 +1,8 @@ import {Action, ThunkAction} from '@reduxjs/toolkit'; +import moment from 'moment'; import { - getProfilePic, + fetchUserProfile, loadFriends, - loadMomentCategories, loadMoments, loadProfileInfo, } from '../../services'; @@ -37,11 +37,56 @@ export const loadUserX = ( payload: {screenType, userId, user}, }); const token = await getTokenOrLogout(dispatch); - loadProfileInfo(token, userId).then((data) => { - dispatch({ - type: userXProfileFetched.type, - payload: {screenType, userId, data}, - }); + fetchUserProfile(userId, token).then((profile) => { + if (profile) { + let { + name, + biography, + website, + birthday, + gender, + snapchat, + tiktok, + university_class, + profile_completion_stage, + suggested_people_linked, + friendship_status, + friendship_requester_id, + } = profile.profile_info; + dispatch({ + type: userXProfileFetched.type, + payload: { + screenType, + userId, + data: { + name, + biography, + website, + birthday: birthday && moment(birthday).format('YYYY-MM-DD'), + gender, + snapchat, + tiktok, + university_class, + profile_completion_stage, + suggested_people_linked, + friendship_status, + friendship_requester_id, + }, + }, + }); + dispatch({ + type: userXAvatarFetched.type, + payload: {screenType, userId, data: profile.profile_pic}, + }); + dispatch({ + type: userXCoverFetched.type, + payload: {screenType, userId, data: profile.header_pic}, + }); + dispatch({ + type: userXMomentCategoriesFetched.type, + payload: {screenType, userId, data: profile.moment_categories}, + }); + } }); loadAllSocialsForUser(userId).then((data) => dispatch({ @@ -49,18 +94,6 @@ export const loadUserX = ( payload: {screenType, userId, data}, }), ); - getProfilePic(token, userId, 'small').then((data) => - dispatch({ - type: userXAvatarFetched.type, - payload: {screenType, userId, data}, - }), - ); - getProfilePic(token, userId, 'large').then((data) => - dispatch({ - type: userXCoverFetched.type, - payload: {screenType, userId, data}, - }), - ); loadFriends(userId, token).then((data) => dispatch({ type: userXFriendsFetched.type, @@ -73,12 +106,6 @@ export const loadUserX = ( payload: {screenType, userId, data}, }), ); - loadMomentCategories(userId, token).then((data) => { - dispatch({ - type: userXMomentCategoriesFetched.type, - payload: {screenType, userId, data}, - }); - }); } catch (error) { console.log(error); } |
