diff options
Diffstat (limited to 'src/store')
| -rw-r--r-- | src/store/actions/momentCategories.tsx | 20 | ||||
| -rw-r--r-- | src/store/actions/user.ts | 39 | ||||
| -rw-r--r-- | src/store/initialStates.ts | 2 | ||||
| -rw-r--r-- | src/store/reducers/userReducer.ts | 10 |
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; |
