38 lines
989 B
JavaScript
38 lines
989 B
JavaScript
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
|
import { mainSubBaseUrl } from "@CON";
|
|
import axios from "axios";
|
|
|
|
export const fetchSysMainSub = createAsyncThunk(
|
|
"systemList/fetchSysMainSub",
|
|
async (building_tag, { fulfillWithValue }) => {
|
|
const res = await axios({
|
|
method: "post",
|
|
url: mainSubBaseUrl,
|
|
data: { building_tag },
|
|
});
|
|
let result = [];
|
|
res.data.history_Main_Systems.forEach((mainSys) => {
|
|
mainSys.history_Sub_systems.forEach((subSys) => {
|
|
result.push({ ...subSys, main_system_tag: mainSys.main_system_tag });
|
|
});
|
|
});
|
|
return fulfillWithValue(result);
|
|
},
|
|
);
|
|
|
|
const systemSlice = createSlice({
|
|
name: "systemList",
|
|
initialState: {
|
|
mainSub: [],
|
|
},
|
|
reducers: {},
|
|
extraReducers: (builder) => {
|
|
builder.addCase(fetchSysMainSub.fulfilled, (state, { payload }) => {
|
|
state.mainSub = payload;
|
|
});
|
|
},
|
|
});
|
|
|
|
const { reducer, actions } = systemSlice;
|
|
export default reducer;
|