106 lines
4.1 KiB
TypeScript
106 lines
4.1 KiB
TypeScript
import { useState } from "react";
|
|
|
|
import SearchForm from "@/components/module/SearchForm";
|
|
// import { DataGrid } from "@rsone/components";
|
|
import DataGrid from "@/components/module/DataGrid";
|
|
import SubmitButton from "@/components/button/SumitButton";
|
|
import SaveButton from "@/components/button/SaveButton";
|
|
import LastYearDataButton from "@/components/button/LastYearDataButton";
|
|
import SubmitExceptionButton from "@/components/button/SubmitExceptionButton";
|
|
import { LoadingWithAnimation } from "@common/components";
|
|
|
|
import { useAlertStore } from "@/shared/lib";
|
|
import { statisticsInputAPi } from "@/entities/statistics/api/statistics-input-service";
|
|
import type { SearchFormValues } from "@/components/type/SearchForm.type";
|
|
import type { SewerageSupplyRateItem } from "@/entities/statistics/model/statistics-input-interface";
|
|
import { SeweragePenetrationRateInpColumn } from "@/components/util/column/input/SeweragePenetrationRateInpColumn";
|
|
import { toGridRows } from "@/components/util/grid/gridFunction";
|
|
|
|
// 하수도 통계 관리 > 01. 하수도 보급률
|
|
const SeweragePenetrationRateInp = () => {
|
|
const { setMessage: alert } = useAlertStore((state) => state);
|
|
const [rowData, setRowData] = useState<Record<string, string | number>[]>([]);
|
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
|
|
|
const handleReset = () => {
|
|
setRowData([]);
|
|
};
|
|
|
|
const handleSearch = async (values: SearchFormValues) => {
|
|
try {
|
|
if (values.sido !== '' && values.sido !== 'ALL') {
|
|
setIsLoading(true);
|
|
|
|
const response = await statisticsInputAPi.getSewerageSupplyRateList({
|
|
sido: values.sido,
|
|
gugun: values.gugun === 'ALL' ? '' : values.gugun,
|
|
bsnmCd: values.bsnmCd,
|
|
yr: values.year,
|
|
demoYr: values.year,
|
|
});
|
|
|
|
if (response.status === 'success' && response.data) {
|
|
const convertedData: SewerageSupplyRateItem[] = response.data.sewerageSupplyRateList.map((d) => ({
|
|
...d,
|
|
speclCntrplnAr: d.speclCntrplnAr === '' || d.speclCntrplnAr === null ? '해당없음' : d.speclCntrplnAr,
|
|
}));
|
|
|
|
setRowData(toGridRows(convertedData));
|
|
} else {
|
|
alert(response.message);
|
|
}
|
|
} else {
|
|
alert('시도를 선택해주세요.');
|
|
}
|
|
} catch (error) {
|
|
alert('데이터 조회 중 오류가 발생했습니다.');
|
|
setRowData([]);
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
};
|
|
|
|
const SubmitExceptionFunc = () => {
|
|
// 예외 제출 로직
|
|
};
|
|
|
|
const getLastYearDataFunc = () => {
|
|
// 지난연도 데이터 가져오기
|
|
};
|
|
|
|
const submitFunc = () => {
|
|
// 제출 로직
|
|
};
|
|
|
|
const saveFunc = () => {
|
|
// 저장 로직
|
|
};
|
|
|
|
return (
|
|
<div className="relative">
|
|
<SearchForm onSubmit={handleSearch} onReset={handleReset} />
|
|
<div className="card !py-0">
|
|
<div className="flex justify-end items-center gap-[0.6rem] mx-[0.6rem]">
|
|
<SubmitExceptionButton SubmitExceptionFunc={SubmitExceptionFunc} />
|
|
<LastYearDataButton getLastYearDataFunc={getLastYearDataFunc} />
|
|
<SubmitButton submitFunc={submitFunc} />
|
|
<SaveButton saveFunc={saveFunc} />
|
|
</div>
|
|
</div>
|
|
{isLoading && <div className="absolute inset-0 z-50 [data-theme='black']:bg-transparent rounded-lg p-10 flex justify-center items-center">
|
|
<div className="relative size-[5rem]">
|
|
<LoadingWithAnimation color="primary" />
|
|
</div>
|
|
</div>}
|
|
<DataGrid
|
|
columnInfo={SeweragePenetrationRateInpColumn}
|
|
rowStartNum={3}
|
|
fixedColumns={1}
|
|
rowData={rowData}
|
|
setRowData={setRowData}
|
|
/>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default SeweragePenetrationRateInp; |