aboutsummaryrefslogtreecommitdiff
path: root/src/store/actions
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-03-23 16:18:19 -0400
committerIvan Chen <ivan@tagg.id>2021-03-23 16:18:19 -0400
commit4844b69ed6c381fe8e573e77d32302965c4de274 (patch)
tree605f08e0019c877564a9631be604d83e67dd7caf /src/store/actions
parent8022d908ca09860424529d818e210d63fff9f398 (diff)
updated types, using api/profile
Diffstat (limited to 'src/store/actions')
-rw-r--r--src/store/actions/userX.ts77
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);
}