add project structure
This commit is contained in:
1 parent
07fc6c0b6c
commit
6eaf18285a
28 files changed
+1309
-648
No files matched your search
@@ -0,0 +1,29 @@
|
||||
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 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
|
||||
})
|
||||
|
||||
export const setupStore = () =>
|
||||
configureStore({
|
||||
reducer: rootReducer
|
||||
})
|
||||
|
||||
export type RootState = ReturnType<typeof rootReducer>
|
||||
export type AppStore = ReturnType<typeof setupStore>
|
||||
export type AppDispatch = AppStore['dispatch']
|
||||
@@ -0,0 +1,17 @@
|
||||
import { createAsyncThunk } from '@reduxjs/toolkit'
|
||||
|
||||
import { apiPaths } from '../../constants/api/apiPaths.ts'
|
||||
import { apiService } from '../../services/apiService.ts'
|
||||
import { ProfileDataType } from '../../type/profile.type.ts'
|
||||
|
||||
export const fetchProfile = createAsyncThunk(
|
||||
'profile/fetchProfile',
|
||||
async (_, { rejectWithValue }) => {
|
||||
try {
|
||||
const response = await apiService.post<ProfileDataType>(apiPaths.baseUrl)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
return rejectWithValue(error)
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,58 @@
|
||||
import {
|
||||
ActionReducerMapBuilder,
|
||||
PayloadAction,
|
||||
createSlice
|
||||
} from '@reduxjs/toolkit'
|
||||
|
||||
import { ProfileDataType, ProfileType } from '../../type/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