2024-04-25 16:01:08: merge [main:7f9a52684105c7ff0a068812245c462ceb6d553e];
This commit is contained in:
1 parent
5a5f104174
commit
a31c44eb7b
121 files changed
+14802
-84
No files matched your search
@@ -0,0 +1,55 @@
|
||||
import { combineReducers, configureStore } from '@reduxjs/toolkit'
|
||||
import { theme } from 'antd'
|
||||
import { MapToken, SeedToken } from 'antd/es/theme/interface'
|
||||
import { createContext, Dispatch, SetStateAction } from 'react'
|
||||
|
||||
import sessionServiceApi from '@services/sessionService.ts'
|
||||
import accessListApi from '@services/accessListService.ts'
|
||||
import appApi from '@services/appService.ts'
|
||||
import roleApi from '@services/roleService.ts'
|
||||
import securityLogServiceApi from '@services/securityLogService.ts'
|
||||
import userServiceApi from '@services/userService.ts'
|
||||
import routeApi from '@services/routeService.ts'
|
||||
|
||||
import profileReducer from './redusers/ProfileSlice.ts'
|
||||
|
||||
export interface ContextProps {
|
||||
setTheme: Dispatch<
|
||||
SetStateAction<{ algorithm: (token: SeedToken) => MapToken }>
|
||||
>
|
||||
}
|
||||
|
||||
export const Context = createContext<ContextProps>({
|
||||
setTheme: () => theme.defaultAlgorithm
|
||||
})
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
profileReducer,
|
||||
[roleApi.reducerPath]: roleApi.reducer,
|
||||
[userServiceApi.reducerPath]: userServiceApi.reducer,
|
||||
[sessionServiceApi.reducerPath]: sessionServiceApi.reducer,
|
||||
[securityLogServiceApi.reducerPath]: securityLogServiceApi.reducer,
|
||||
[appApi.reducerPath]: appApi.reducer,
|
||||
[accessListApi.reducerPath]: accessListApi.reducer,
|
||||
[routeApi.reducerPath]: routeApi.reducer
|
||||
})
|
||||
|
||||
export const setupStore = () =>
|
||||
configureStore({
|
||||
reducer: rootReducer,
|
||||
middleware: (getDefaultMiddleware) =>
|
||||
getDefaultMiddleware().concat(
|
||||
roleApi.middleware,
|
||||
userServiceApi.middleware,
|
||||
securityLogServiceApi.middleware,
|
||||
appApi.middleware,
|
||||
accessListApi.middleware,
|
||||
routeApi.middleware,
|
||||
userServiceApi.middleware,
|
||||
sessionServiceApi.middleware
|
||||
)
|
||||
})
|
||||
|
||||
export type RootState = ReturnType<typeof rootReducer>
|
||||
export type AppStore = ReturnType<typeof setupStore>
|
||||
export type AppDispatch = AppStore['dispatch']
|
||||
@@ -0,0 +1,22 @@
|
||||
import { createAsyncThunk } from '@reduxjs/toolkit'
|
||||
|
||||
import { apiPaths } from '@constants/api/apiPaths.ts'
|
||||
|
||||
import { ProfileDataType } from '@pages/ProfilePage/profile-page.type.ts'
|
||||
|
||||
import { apiService } from '@services/apiService.ts'
|
||||
|
||||
|
||||
export const fetchProfile = createAsyncThunk(
|
||||
'profile/fetchProfile',
|
||||
async (_, { rejectWithValue }) => {
|
||||
try {
|
||||
const response = await apiService.post<ProfileDataType>(
|
||||
apiPaths.getProfile
|
||||
)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
return rejectWithValue(error)
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,63 @@
|
||||
import {
|
||||
ActionReducerMapBuilder,
|
||||
createSlice,
|
||||
PayloadAction
|
||||
} from '@reduxjs/toolkit'
|
||||
|
||||
import {
|
||||
ProfileDataType,
|
||||
ProfileType
|
||||
} from '@pages/ProfilePage/profile-page.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