diff options
Diffstat (limited to 'src/store')
| -rw-r--r-- | src/store/actions/userX.ts | 77 | ||||
| -rw-r--r-- | src/store/initialStates.ts | 6 |
2 files changed, 55 insertions, 28 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); } diff --git a/src/store/initialStates.ts b/src/store/initialStates.ts index d89927a7..8ffdd559 100644 --- a/src/store/initialStates.ts +++ b/src/store/initialStates.ts @@ -3,14 +3,14 @@ import { MomentType, NotificationType, ProfilePreviewType, - ProfileType, + ProfileInfoType, ScreenType, SocialAccountType, UserType, UserXType, } from '../types'; -export const NO_PROFILE: ProfileType = { +export const NO_PROFILE: ProfileInfoType = { biography: '', website: '', name: '', @@ -40,7 +40,7 @@ export const EMPTY_PROFILE_PREVIEW_LIST = <ProfilePreviewType[]>[]; export const NO_USER_DATA = { user: <UserType>NO_USER, - profile: <ProfileType>NO_PROFILE, + profile: <ProfileInfoType>NO_PROFILE, avatar: <string | undefined>undefined, cover: <string | undefined>undefined, isOnboardedUser: false, |
