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,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