import { useRef, useState } from "react"; import { useAlertStore } from "@/shared/lib"; import { LoadingWithAnimation } from "@common/components"; import SearchForm from "@/components/module/SearchForm"; import DataGrid from "@/components/module/DataGrid"; import type { ColumnInfo } from "@/components/type/DataGrid.type"; import type { SearchFormValues } from "@/components/type/SearchForm.type"; import { toGridRows } from "@/components/util/grid/gridFunction"; // 분리된 중계펌프장용 컬럼 구성 임포트 import { MediationPumpStatusColumnConfig } from "@/components/util/column/total/SewerMediationPumpStatusColumn"; // 집계표(TOTAL) API 및 인터페이스 명세 호출 import { statisticsTotalStatusApi } from "@/entities/statistics/api/statistics-total-service"; import type { MediationPumpMaintainTotalRequest } from "@/entities/statistics/model/statistics-total/statistics-mediation-pump-total-interface"; import CellColorInfo from "./CellColorInfo"; const PumpingStationTot = () => { const { setMessage: alert } = useAlertStore((state) => state); // null 타입 컴파일 에러가 발생하지 않도록 엄격하게 정의한 데이터 상태 const [rowData, setRowData] = useState[]>([]); const [isLoading, setIsLoading] = useState(false); const lastSearchedValuesRef = useRef(null); const config = MediationPumpStatusColumnConfig; const handleReset = () => { setRowData([]); lastSearchedValuesRef.current = null; }; const loadGridData = async (values: SearchFormValues): Promise => { const param: MediationPumpMaintainTotalRequest = { ctpvNm: values.sido === "ALL" ? "" : values.sido, sggNm: values.gugun === "ALL" ? "" : values.gugun, sewerBzmnCd: values.bsnmCd, statsYr: values.year, rowDataYn: values.isDetail, summaryYn: values.isSummary !== 'ALL', summaryYearCnt: values.isSummary !== 'ALL' ? Number(values.isSummary) : undefined }; try { const response = await statisticsTotalStatusApi.getMediationPumpStationStatusTotalList(param); if (response && response.status === "success" && response.data) { // object[]로 변환하여 주입함으로써 null 에러 전면 방지 setRowData(toGridRows(response.data as object[])); return true; } alert(response?.message || "데이터 조회 중 오류가 발생했습니다."); return false; } catch { alert("서버 연결 중 오류가 발생했습니다."); return false; } }; const handleSearch = async (values: SearchFormValues) => { try { setIsLoading(true); const ok = await loadGridData(values); if (ok) { lastSearchedValuesRef.current = values; } else { lastSearchedValuesRef.current = null; } } catch { alert("데이터 조회 중 오류가 발생했습니다."); lastSearchedValuesRef.current = null; } finally { setIsLoading(false); } }; const gridColumnInfo: ColumnInfo = { columns: config.columns, columnLayout: config.columnLayout, }; return (
{isLoading && (
)}
{ const rowType = String(row.rowType ?? ''); if (rowType === 'DETAIL') return undefined; if (rowType === 'BIZ_SUM') return 'rg-cell-rowtype-biz-sum'; if (rowType === 'SUMMARY') return 'rg-cell-rowtype-summary'; return 'rg-cell-rowtype-other'; }} />
); }; export default PumpingStationTot;