aboutsummaryrefslogtreecommitdiff
path: root/src/store
diff options
context:
space:
mode:
authorAshm Walia <40498934+ashmgarv@users.noreply.github.com>2021-01-12 15:38:21 -0800
committerGitHub <noreply@github.com>2021-01-12 18:38:21 -0500
commitd495bff07b50c47e842dc2c139922d56c87f5c9b (patch)
treec6f592fa72a6158981fef2feba1b3dca5ff6cc2a /src/store
parentc758389ad2ebe98196d4618ec08dbf2b24d95bfa (diff)
[TMA 491 Frontend] Revamp onboarding (#173)
* First commit, arrow excluded * Done from my side * Some small nitpicks * exclude tsconfig * Show profile screen after onboarding * Update string * Small fix * small cosmetic
Diffstat (limited to 'src/store')
-rw-r--r--src/store/actions/momentCategories.tsx20
-rw-r--r--src/store/actions/user.ts39
-rw-r--r--src/store/initialStates.ts2
-rw-r--r--src/store/reducers/userReducer.ts10
4 files changed, 66 insertions, 5 deletions
diff --git a/src/store/actions/momentCategories.tsx b/src/store/actions/momentCategories.tsx
index 987fc9e5..c91e9ec8 100644
--- a/src/store/actions/momentCategories.tsx
+++ b/src/store/actions/momentCategories.tsx
@@ -1,7 +1,10 @@
import {RootState} from '../rootReducer';
import {loadMomentCategories, postMomentCategories} from '../../services';
import {Action, ThunkAction} from '@reduxjs/toolkit';
-import {momentCategoriesFetched} from '../reducers';
+import {
+ momentCategoriesFetched,
+ profileCompletionStageUpdated,
+} from '../reducers';
import {getTokenOrLogout} from '../../utils';
/**
@@ -28,21 +31,32 @@ export const loadUserMomentCategories = (
/**
* Handle addition / deletion of categories for a user
* @param categories List of categories
- * @param userId id of the user for whom categories should be updated
+ * @param add true if the call to his function is to add categories
*/
export const updateMomentCategories = (
categories: string[],
+ add: boolean,
): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
dispatch,
) => {
try {
const token = await getTokenOrLogout(dispatch);
- const success = await postMomentCategories(categories, token);
+ let success = false;
+ let stage: number | undefined = 1;
+
+ stage = await postMomentCategories(categories, token);
+ success = stage ? true : false;
if (success) {
dispatch({
type: momentCategoriesFetched.type,
payload: {categories},
});
+ if (add) {
+ dispatch({
+ type: profileCompletionStageUpdated.type,
+ payload: {stage},
+ });
+ }
}
} catch (error) {
console.log(error);
diff --git a/src/store/actions/user.ts b/src/store/actions/user.ts
index eee5fcde..8550f3bd 100644
--- a/src/store/actions/user.ts
+++ b/src/store/actions/user.ts
@@ -2,7 +2,13 @@ import {RootState} from '../rootReducer';
import {UserType} from '../../types/types';
import {loadProfileInfo, loadAvatar, loadCover} from '../../services';
import {Action, ThunkAction} from '@reduxjs/toolkit';
-import {userLoggedIn, userDetailsFetched, socialEdited} from '../reducers';
+import {
+ userLoggedIn,
+ userDetailsFetched,
+ socialEdited,
+ profileCompletionStageUpdated,
+ setIsOnboardedUser,
+} from '../reducers';
import {getTokenOrLogout} from '../../utils';
/**
@@ -50,7 +56,6 @@ export const updateSocial = (
dispatch,
) => {
try {
- console.log(social);
dispatch({
type: socialEdited.type,
payload: {social, value},
@@ -60,6 +65,36 @@ export const updateSocial = (
}
};
+export const updateProfileCompletionStage = (
+ stage: number,
+): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
+ dispatch,
+) => {
+ try {
+ dispatch({
+ type: profileCompletionStageUpdated.type,
+ payload: {stage},
+ });
+ } catch (error) {
+ console.log(error);
+ }
+};
+
+export const updateIsOnboardedUser = (
+ isOnboardedUser: boolean,
+): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
+ dispatch,
+) => {
+ try {
+ dispatch({
+ type: setIsOnboardedUser.type,
+ payload: {isOnboardedUser},
+ });
+ } catch (error) {
+ console.log(error);
+ }
+};
+
export const logout = (): ThunkAction<
Promise<void>,
RootState,
diff --git a/src/store/initialStates.ts b/src/store/initialStates.ts
index 09607758..de97b129 100644
--- a/src/store/initialStates.ts
+++ b/src/store/initialStates.ts
@@ -16,6 +16,7 @@ export const NO_PROFILE: ProfileType = {
gender: '',
birthday: undefined,
university_class: 2021,
+ profile_completion_stage: 1,
snapchat: '',
tiktok: '',
};
@@ -36,6 +37,7 @@ export const NO_USER_DATA = {
profile: <ProfileType>NO_PROFILE,
avatar: <string | null>'',
cover: <string | null>'',
+ isOnboardedUser: false,
};
export const NO_FRIENDS_DATA = {
diff --git a/src/store/reducers/userReducer.ts b/src/store/reducers/userReducer.ts
index 2fd5c462..2e71e38e 100644
--- a/src/store/reducers/userReducer.ts
+++ b/src/store/reducers/userReducer.ts
@@ -41,6 +41,14 @@ const userDataSlice = createSlice({
break;
}
},
+
+ profileCompletionStageUpdated: (state, action) => {
+ state.profile.profile_completion_stage = action.payload.stage;
+ },
+
+ setIsOnboardedUser: (state, action) => {
+ state.isOnboardedUser = action.payload.isOnboardedUser;
+ },
},
});
@@ -48,5 +56,7 @@ export const {
userLoggedIn,
userDetailsFetched,
socialEdited,
+ profileCompletionStageUpdated,
+ setIsOnboardedUser,
} = userDataSlice.actions;
export const userDataReducer = userDataSlice.reducer;