diff options
author | Shravya Ramesh <shravs1208@gmail.com> | 2021-02-11 07:03:02 -0800 |
---|---|---|
committer | Shravya Ramesh <shravs1208@gmail.com> | 2021-02-11 07:03:02 -0800 |
commit | e95ff2d483903b4d390c8dd0edf4ab60561b8334 (patch) | |
tree | 2a315d8aa817785bc47ad2ef50ee32130f2d0ccb /src | |
parent | 88433cda2938a2fa4f6bf3e4b2282fe0095dfe71 (diff) |
Create thunk action + reducer to set new variable
Diffstat (limited to 'src')
-rw-r--r-- | src/store/actions/user.ts | 33 | ||||
-rw-r--r-- | src/store/reducers/userReducer.ts | 7 |
2 files changed, 37 insertions, 3 deletions
diff --git a/src/store/actions/user.ts b/src/store/actions/user.ts index 5f49a103..98e1727b 100644 --- a/src/store/actions/user.ts +++ b/src/store/actions/user.ts @@ -1,7 +1,12 @@ -import { CommentThreadType } from './../../types/types'; +import {CommentThreadType} from './../../types/types'; import {RootState} from '../rootReducer'; import {UserType} from '../../types/types'; -import {loadProfileInfo, loadAvatar, loadCover} from '../../services'; +import { + loadProfileInfo, + loadAvatar, + loadCover, + editSPSwipeTutorial, +} from '../../services'; import {Action, ThunkAction} from '@reduxjs/toolkit'; import { userLoggedIn, @@ -13,6 +18,7 @@ import { setReplyPosted, } from '../reducers'; import {getTokenOrLogout} from '../../utils'; +import {spSwipeTutorialUpdated} from '../reducers/userReducer'; /** * Entry point to our store. @@ -140,3 +146,26 @@ export const logout = (): ThunkAction< console.log(error); } }; + +export const updateSPSwipeTutorial = ( + user: UserType, + data: number, +): ThunkAction< + Promise<boolean | undefined>, + RootState, + unknown, + Action<string> +> => async (dispatch) => { + try { + const success = await editSPSwipeTutorial(user); + if (success) { + dispatch({ + type: spSwipeTutorialUpdated.type, + payload: {sp_swipe_tutorial: data}, + }); + } + return success; + } catch (error) { + console.log('Error while updating suggested people linked state: ', error); + } +}; diff --git a/src/store/reducers/userReducer.ts b/src/store/reducers/userReducer.ts index 1e575339..b353cc60 100644 --- a/src/store/reducers/userReducer.ts +++ b/src/store/reducers/userReducer.ts @@ -1,4 +1,4 @@ -import {createSlice, Action} from '@reduxjs/toolkit'; +import {createSlice} from '@reduxjs/toolkit'; import {NO_USER_DATA} from '../initialStates'; /** @@ -46,6 +46,10 @@ const userDataSlice = createSlice({ state.profile.profile_completion_stage = action.payload.stage; }, + spSwipeTutorialUpdated: (state, action) => { + state.profile.sp_swipe_tutorial = action.payload.sp_swipe_tutorial; + }, + setIsOnboardedUser: (state, action) => { state.isOnboardedUser = action.payload.isOnboardedUser; }, @@ -68,5 +72,6 @@ export const { setIsOnboardedUser, setNewNotificationReceived, setReplyPosted, + spSwipeTutorialUpdated, } = userDataSlice.actions; export const userDataReducer = userDataSlice.reducer; |