41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
|
|
import axios from "axios";
|
|
import { userAuthBaseUrl, userInfoBaseUrl } from "@CON";
|
|
import { ajaxRes, deviceBuiListBaseUrl } from "@UTIL";
|
|
import { fetchBuiList } from "./buildingSlice";
|
|
|
|
export const fetchUserInfo = createAsyncThunk("user/fetchUserInfo", async (token, thunkAPI) => {
|
|
const res = await axios.post(userInfoBaseUrl);
|
|
console.log("user/fetchUserInfo", res);
|
|
return ajaxRes(res, thunkAPI);
|
|
});
|
|
|
|
export const fetchUserAuthPages = createAsyncThunk(
|
|
"user/fetchUserAuthPages",
|
|
async (token, thunkAPI) => {
|
|
const res = await axios.post(userAuthBaseUrl);
|
|
thunkAPI.dispatch(fetchBuiList());
|
|
return ajaxRes(res, thunkAPI);
|
|
},
|
|
);
|
|
|
|
const userSlice = createSlice({
|
|
name: "user",
|
|
initialState: {
|
|
userAuthPages: [],
|
|
userInfo: {},
|
|
},
|
|
reducers: {},
|
|
extraReducers: (builder) => {
|
|
builder.addCase(fetchUserInfo.fulfilled, (state, { payload }) => {
|
|
state.userInfo = payload;
|
|
});
|
|
builder.addCase(fetchUserAuthPages.fulfilled, (state, { payload }) => {
|
|
state.userAuthPages = payload;
|
|
});
|
|
},
|
|
});
|
|
|
|
const { reducer } = userSlice;
|
|
export default reducer;
|