RC-4: move AuthContext to src/app/contexts and update it and userSlice

This commit is contained in:
2023-06-22 19:58:51 +01:00
parent 2892395c8b
commit 592e9e4dee
2 changed files with 25 additions and 56 deletions

View File

@@ -5,7 +5,7 @@ import _ from '@lodash';
import { setInitialSettings } from 'app/store/fuse/settingsSlice';
import { showMessage } from 'app/store/fuse/messageSlice';
import settingsConfig from 'app/configs/settingsConfig';
import jwtService from '../auth/services/jwtService';
import { authService } from '../services';
export const setUser = createAsyncThunk('user/setUser', async (user, { dispatch, getState }) => {
/*
@@ -30,24 +30,6 @@ export const updateUserSettings = createAsyncThunk(
}
);
export const updateUserShortcuts = createAsyncThunk(
'user/updateShortucts',
async (shortcuts, { dispatch, getState }) => {
const { user } = getState();
const newUser = {
...user,
data: {
...user.data,
shortcuts,
},
};
dispatch(updateUserData(newUser));
return newUser;
}
);
export const logoutUser = () => async (dispatch, getState) => {
const { user } = getState();
@@ -71,10 +53,10 @@ export const updateUserData = (user) => async (dispatch, getState) => {
return;
}
jwtService
authService
.updateUserData(user)
.then(() => {
dispatch(showMessage({ message: 'User data saved with api' }));
dispatch(showMessage({ message: 'User data saved' }));
})
.catch((error) => {
dispatch(showMessage({ message: error.message }));
@@ -87,7 +69,6 @@ const initialState = {
displayName: 'John Doe',
photoURL: 'assets/images/avatars/brian-hughes.jpg',
email: 'johndoe@withinpixels.com',
shortcuts: ['apps.calendar', 'apps.mailbox', 'apps.contacts', 'apps.tasks'],
},
};
@@ -99,7 +80,6 @@ const userSlice = createSlice({
},
extraReducers: {
[updateUserSettings.fulfilled]: (state, action) => action.payload,
[updateUserShortcuts.fulfilled]: (state, action) => action.payload,
[setUser.fulfilled]: (state, action) => action.payload,
},
});
@@ -108,6 +88,4 @@ export const { userLoggedOut } = userSlice.actions;
export const selectUser = ({ user }) => user;
export const selectUserShortcuts = ({ user }) => user.data.shortcuts;
export default userSlice.reducer;