MSP-3074 add roles
This commit is contained in:
1 parent
5a29bfc7f6
commit
9c1b859971
36 files changed
+1063
-100
No files matched your search
@@ -0,0 +1,50 @@
|
||||
import {PayloadAction, createSlice, ActionReducerMapBuilder} from '@reduxjs/toolkit';
|
||||
import {ProfileDataType, ProfileType} from "../types/profile.type.ts";
|
||||
import {fetchProfile} from "./ActionCreators.ts";
|
||||
|
||||
export enum StateProfileStatus {
|
||||
resolved = 'resolved',
|
||||
pending = 'pending',
|
||||
rejected = 'rejected',
|
||||
notInit = 'notInit',
|
||||
}
|
||||
|
||||
export const initialState: ProfileType = {
|
||||
profile: {
|
||||
email: '',
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
role: '',
|
||||
roles: [],
|
||||
permissions: [],
|
||||
idleTimeoutMs: 0,
|
||||
},
|
||||
status: StateProfileStatus.notInit,
|
||||
error: '',
|
||||
};
|
||||
|
||||
export const profileSlice = createSlice({
|
||||
name: 'profile',
|
||||
initialState,
|
||||
reducers: {
|
||||
clearProfile(state) {
|
||||
state.profile = initialState.profile;
|
||||
},
|
||||
},
|
||||
extraReducers: (builder: ActionReducerMapBuilder<ProfileType>) => {
|
||||
builder
|
||||
.addCase(fetchProfile.fulfilled, (state, action: PayloadAction<ProfileDataType>) => {
|
||||
state.status = StateProfileStatus.resolved;
|
||||
state.profile = {...action.payload};
|
||||
})
|
||||
.addCase(fetchProfile.pending, (state) => {
|
||||
state.status = StateProfileStatus.pending;
|
||||
})
|
||||
.addCase(fetchProfile.rejected, (state, action: any) => {
|
||||
state.status = StateProfileStatus.rejected;
|
||||
state.error = action.payload;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default profileSlice.reducer;
|
||||
Reference in new issue
Block a user