aboutsummaryrefslogtreecommitdiff
path: root/src/store/actions
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/actions
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/actions')
-rw-r--r--src/store/actions/momentCategories.tsx20
-rw-r--r--src/store/actions/user.ts39
2 files changed, 54 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,