2024-04-27 16:21:14: merge [main:aa6853211bb46e321bc26b3b8132b18c03592910];
This commit is contained in:
1 parent
a31c44eb7b
commit
a6f4c85231
38 files changed
+1966
-60
No files matched your search
@@ -2,11 +2,15 @@ import { createAsyncThunk } from '@reduxjs/toolkit'
|
||||
|
||||
import { apiPaths } from '@constants/api/apiPaths.ts'
|
||||
|
||||
import { ProfileDataType } from '@pages/ProfilePage/profile-page.type.ts'
|
||||
import {
|
||||
ProfileDataType,
|
||||
UIDataType
|
||||
} from '@pages/ProfilePage/profile-page.type.ts'
|
||||
|
||||
import { initUI } from '@utils/UIUtiles.tsx'
|
||||
|
||||
import { apiService } from '@services/apiService.ts'
|
||||
|
||||
|
||||
export const fetchProfile = createAsyncThunk(
|
||||
'profile/fetchProfile',
|
||||
async (_, { rejectWithValue }) => {
|
||||
@@ -20,3 +24,15 @@ export const fetchProfile = createAsyncThunk(
|
||||
}
|
||||
}
|
||||
)
|
||||
export const fetchUI = createAsyncThunk(
|
||||
'ui/fetchUI',
|
||||
async (_, { rejectWithValue }) => {
|
||||
try {
|
||||
const response = await apiService.post<UIDataType>(apiPaths.getUI)
|
||||
initUI(response.data)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
return rejectWithValue(error)
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -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