From 4844b69ed6c381fe8e573e77d32302965c4de274 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Tue, 23 Mar 2021 16:18:19 -0400 Subject: updated types, using api/profile --- src/store/actions/userX.ts | 77 +++++++++++++++++++++++++++++++--------------- src/store/initialStates.ts | 6 ++-- 2 files changed, 55 insertions(+), 28 deletions(-) (limited to 'src/store') 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 = []; export const NO_USER_DATA = { user: NO_USER, - profile: NO_PROFILE, + profile: NO_PROFILE, avatar: undefined, cover: undefined, isOnboardedUser: false, -- cgit v1.2.3-70-g09d2