MSP-3237 create UISlice in reducers and add it in store
This commit is contained in:
1 parent
d2c21e7bfc
commit
634c8e0e4c
2 files changed
+54
-3
No files matched your search
@@ -5,6 +5,8 @@ import { createContext, Dispatch, SetStateAction } from 'react'
|
||||
|
||||
import accessListApi from '@services/accessListService.ts'
|
||||
import appApi from '@services/appService.ts'
|
||||
import applicationsGroupApi from '@services/applicationsGroupService.ts'
|
||||
import applicationsApi from '@services/applicationsService.ts'
|
||||
import modulesServiceApi from '@services/modulesService.ts'
|
||||
import roleApi from '@services/roleService.ts'
|
||||
import routeApi from '@services/routeService.ts'
|
||||
@@ -13,8 +15,7 @@ import sessionServiceApi from '@services/sessionService.ts'
|
||||
import userServiceApi from '@services/userService.ts'
|
||||
|
||||
import profileReducer from './redusers/ProfileSlice.ts'
|
||||
import applicationsGroupApi from '@services/applicationsGroupService.ts'
|
||||
import applicationsApi from '@services/applicationsService.ts'
|
||||
import UIReducer from './redusers/UISlice.ts'
|
||||
|
||||
export interface ContextProps {
|
||||
setTheme: Dispatch<
|
||||
@@ -28,6 +29,7 @@ export const Context = createContext<ContextProps>({
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
profileReducer,
|
||||
UIReducer,
|
||||
[roleApi.reducerPath]: roleApi.reducer,
|
||||
[userServiceApi.reducerPath]: userServiceApi.reducer,
|
||||
[sessionServiceApi.reducerPath]: sessionServiceApi.reducer,
|
||||
@@ -37,7 +39,7 @@ const rootReducer = combineReducers({
|
||||
[routeApi.reducerPath]: routeApi.reducer,
|
||||
[modulesServiceApi.reducerPath]: modulesServiceApi.reducer,
|
||||
[applicationsGroupApi.reducerPath]: applicationsGroupApi.reducer,
|
||||
[applicationsApi.reducerPath]: applicationsApi.reducer,
|
||||
[applicationsApi.reducerPath]: applicationsApi.reducer
|
||||
})
|
||||
|
||||
export const setupStore = () =>
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import {
|
||||
ActionReducerMapBuilder,
|
||||
createSlice,
|
||||
PayloadAction
|
||||
} from '@reduxjs/toolkit'
|
||||
|
||||
import { UIDataType, UIType } from '@pages/ProfilePage/profile-page.type.ts'
|
||||
|
||||
import { StateProfileStatus } from '@stores/redusers/ProfileSlice.ts'
|
||||
|
||||
import { fetchUI } from './ActionCreators.ts'
|
||||
|
||||
export const initialState: UIType = {
|
||||
ui: {
|
||||
name: '',
|
||||
primaryColor: ''
|
||||
},
|
||||
status: StateProfileStatus.notInit,
|
||||
error: ''
|
||||
}
|
||||
|
||||
export const UISlice = createSlice({
|
||||
name: 'ui',
|
||||
initialState,
|
||||
reducers: {
|
||||
clearUI(state) {
|
||||
state.ui = initialState.ui
|
||||
}
|
||||
},
|
||||
extraReducers: (builder: ActionReducerMapBuilder<UIType>) => {
|
||||
builder
|
||||
.addCase(
|
||||
fetchUI.fulfilled,
|
||||
(state, action: PayloadAction<UIDataType>) => {
|
||||
state.status = StateProfileStatus.resolved
|
||||
state.ui = { ...action.payload }
|
||||
}
|
||||
)
|
||||
.addCase(fetchUI.pending, (state) => {
|
||||
state.status = StateProfileStatus.pending
|
||||
})
|
||||
.addCase(fetchUI.rejected, (state, action: any) => {
|
||||
state.status = StateProfileStatus.rejected
|
||||
state.error = action.payload
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
export default UISlice.reducer
|
||||
Reference in new issue
Block a user