112 lines
2.9 KiB
TypeScript
112 lines
2.9 KiB
TypeScript
import { fetchType, getFetch } from "@/components/lib/api";
|
|
import type { CommonTableProps } from "../../common/type/header";
|
|
import type { WaterReuseFacility } from "../../ruseFcltMng/fcltSttn/pbnstSttn/type";
|
|
import {
|
|
pbnstSttNodeListExport,
|
|
pbnSttHeadListExport,
|
|
} from "../../ruseFcltMng/fcltSttn/pbnstSttn/headList";
|
|
import type { ReturnType } from "@common/business_components/ui";
|
|
import { hasuListFetch } from "../../ruseFcltMng/fcltSttn/pbnstSttn";
|
|
import type { customPbnst } from "../../ruseFcltMng/fcltReg/pbnstReg/type";
|
|
|
|
export const ruseMapSize = 15;
|
|
export type ruseMapState = {
|
|
ruseMap: {
|
|
ruseMapRes: WaterReuseFacility[];
|
|
ruseMapCount: number;
|
|
isInit: boolean;
|
|
fclts: string[];
|
|
ruseMapHeadList: CommonTableProps[];
|
|
ruseMapNodeList: CommonTableProps[];
|
|
};
|
|
};
|
|
|
|
type ruseMapActions = {
|
|
getMapFlcts: () => void;
|
|
ruseMapInit: (
|
|
page: number,
|
|
total: number,
|
|
reurnValue: ReturnType,
|
|
year: string,
|
|
fclts: string[]
|
|
) => void;
|
|
ruseMapDetail: (ruseFcltId: string) => Promise<customPbnst | undefined>;
|
|
};
|
|
|
|
export type ruseMapType = ruseMapState & ruseMapActions;
|
|
|
|
export const ruseMapStateExport: ruseMapState = {
|
|
ruseMap: {
|
|
isInit: false,
|
|
ruseMapRes: [],
|
|
fclts: [],
|
|
ruseMapCount: 1,
|
|
ruseMapHeadList: pbnSttHeadListExport,
|
|
ruseMapNodeList: pbnstSttNodeListExport,
|
|
},
|
|
};
|
|
|
|
export const ruseMapActionsExport: (set: any) => ruseMapActions = (
|
|
set: any
|
|
) => {
|
|
return {
|
|
getMapFlcts: async () => {
|
|
const fclts = await getFetch(fetchType.WR, "/reuseFc/pubFc");
|
|
|
|
return set((state: ruseMapState) => ({
|
|
ruseMap: {
|
|
...state.ruseMap,
|
|
fclts: fclts,
|
|
},
|
|
}));
|
|
},
|
|
ruseMapInit: async (
|
|
page: number,
|
|
total: number,
|
|
reurnValue: ReturnType,
|
|
year: string,
|
|
fclts: string[]
|
|
) => {
|
|
try {
|
|
const ruseMapRes = await hasuListFetch(
|
|
String(page),
|
|
String(total),
|
|
reurnValue,
|
|
undefined,
|
|
year,
|
|
fclts
|
|
);
|
|
|
|
set((state: ruseMapState) => {
|
|
return {
|
|
...state,
|
|
ruseMap: {
|
|
...state.ruseMap,
|
|
ruseMapRes: ruseMapRes.data,
|
|
ruseMapCount: ruseMapRes.count,
|
|
isInit: false,
|
|
},
|
|
};
|
|
});
|
|
} catch (e) {
|
|
console.log(e);
|
|
}
|
|
},
|
|
ruseMapDetail: async (ruseFcltId: string) => {
|
|
try {
|
|
let ruseDetail = await getFetch("wr", `/reuseFc/pubFc/${ruseFcltId}`);
|
|
if (ruseDetail.length >= 0) {
|
|
ruseDetail = ruseDetail.find(
|
|
(item: customPbnst) => item.pbnstRuseFcltId === ruseFcltId
|
|
);
|
|
}
|
|
// 🔑 스토어 업데이트 대신 리턴
|
|
return ruseDetail;
|
|
} catch (errorHasu) {
|
|
console.log(errorHasu);
|
|
throw errorHasu; // 호출부에서 catch 가능하도록
|
|
}
|
|
},
|
|
};
|
|
};
|