From eca74c1f2ec48d7c80be3bcb8002ffd69702ff2d Mon Sep 17 00:00:00 2001 From: rsone001 Date: Wed, 4 Feb 2026 17:54:02 +0900 Subject: [PATCH] =?UTF-8?q?st:=20refactor:=20=EC=97=B0=EB=8F=84=20&=20?= =?UTF-8?q?=EC=A0=84=EB=85=84=EB=8F=84=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20?= =?UTF-8?q?=EA=B0=80=EC=A0=B8=EC=98=A4=EA=B8=B0=20&=20=EA=B7=B8=EB=A6=AC?= =?UTF-8?q?=EB=93=9C=20=EB=82=B4=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20editable?= =?UTF-8?q?=20=ED=8C=90=EB=B3=84=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/st/src/components/module/SearchForm.tsx | 29 ++++++++--------- .../input/SeweragePenetrationRateInp.tsx | 32 +++++++++++++------ 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/apps/st/src/components/module/SearchForm.tsx b/apps/st/src/components/module/SearchForm.tsx index bd15477f8..0b50ecf89 100644 --- a/apps/st/src/components/module/SearchForm.tsx +++ b/apps/st/src/components/module/SearchForm.tsx @@ -31,23 +31,9 @@ const getSggListFetcher = async (key: [string, string]): Promise { const { setMessage: alert } = useAlertStore((state) => state); const mergedProps = { ...defaultSearchFormProps, ...props }; - + const currentYear = new Date().getFullYear(); const defaultYear = currentYear - 1; - const startYear = currentYear - 10; - - const [values, setValues] = useState({ - sido: props.defaultValues?.sido || "", - gugun: props.defaultValues?.gugun || '', - year: props.defaultValues?.year || String(defaultYear), - order: props.defaultValues?.order || '', - fctName: props.defaultValues?.fctName || '', - bsnmCd: props.defaultValues?.bsnmCd || '', - }); - - useEffect(() => { - props.onValuesChange?.(values); - }, [values]); const { data: sidoList } = useSWR>( "sido-list", @@ -71,6 +57,15 @@ const SearchForm = (props: SearchFormProps = {}) => { } ); + const [values, setValues] = useState({ + sido: props.defaultValues?.sido || '', + gugun: props.defaultValues?.gugun || '', + year: props.defaultValues?.year || defaultYear.toString(), + order: props.defaultValues?.order || '', + fctName: props.defaultValues?.fctName || '', + bsnmCd: props.defaultValues?.bsnmCd || '', + }); + const { data: sggList } = useSWR>( values.sido && values.sido !== "ALL" ? ["sgg-list", values.sido] : null, getSggListFetcher, @@ -123,6 +118,10 @@ const SearchForm = (props: SearchFormProps = {}) => { })); }; + useEffect(() => { + props.onValuesChange?.(values); + }, [values]); + return (
diff --git a/apps/st/src/components/statistics/input/SeweragePenetrationRateInp.tsx b/apps/st/src/components/statistics/input/SeweragePenetrationRateInp.tsx index 24a88436c..7644ab1e3 100644 --- a/apps/st/src/components/statistics/input/SeweragePenetrationRateInp.tsx +++ b/apps/st/src/components/statistics/input/SeweragePenetrationRateInp.tsx @@ -40,7 +40,10 @@ const SeweragePenetrationRateInp = () => { const [isLoading, setIsLoading] = useState(false); const [searchValues, setSearchValues] = useState(null); const [isEnterable, setIsEnterable] = useState(true); + const [lastSearchedYear, setLastSearchedYear] = useState(null); + + // 최상위 관리자일땐 모든 상황에서 edit 가능하게 수정 필요. const columnInfo = useMemo(() => { const { columns, columnLayout } = SeweragePenetrationRateInpColumn; return { @@ -53,6 +56,7 @@ const SeweragePenetrationRateInp = () => { const handleReset = () => { setRowData([]); + setLastSearchedYear(null); }; const fetchSewerageSupplyRate = async (params: SewerageSupplyRateRequestParams) => { @@ -64,6 +68,7 @@ const SeweragePenetrationRateInp = () => { ...d, speclCntrplnAr: d.speclCntrplnAr === '' || d.speclCntrplnAr === null ? '해당없음' : d.speclCntrplnAr, })); + setRowData(toGridRows(convertedData)); } else { alert(response.message); @@ -83,10 +88,11 @@ const SeweragePenetrationRateInp = () => { } try { - const response = await statisticsInputAPi.checkInputPeriod(searchValues?.year || ''); + const response = await statisticsInputAPi.checkInputPeriod(values.year || ''); if (response.status === 'success') { setIsEnterable(response.data); + setLastSearchedYear(values.year || null); await fetchSewerageSupplyRate(getSewerageSupplyRateParams(values)); } else { @@ -106,10 +112,14 @@ const SeweragePenetrationRateInp = () => { alert('시도를 선택해주세요.'); return; } - const prevYear = (Number(values.year) - 1).toString(); - await fetchSewerageSupplyRate( - getSewerageSupplyRateParams(values, { yr: prevYear, demoYr: prevYear, mode: 'PRE' }) - ); + + // 실제 조회된 연도가 없으면 실행 불가 + if (!lastSearchedYear) { + alert('먼저 데이터를 조회해주세요.'); + return; + } + + await fetchSewerageSupplyRate(getSewerageSupplyRateParams(values, { mode: 'PRE' })); }; const submitFunc = () => { @@ -126,10 +136,13 @@ const SeweragePenetrationRateInp = () => { {rowData.length > 0 &&
- - getLastYearDataFunc(searchValues ?? {})} /> - - + {isEnterable && } + {isEnterable && getLastYearDataFunc(searchValues ?? {})} />} + {isEnterable && } + { + // 최고 관리자일땐 저장 가능하게 + + }
} @@ -141,6 +154,7 @@ const SeweragePenetrationRateInp = () => { 0) && isEnterable} rowStartNum={3} fixedColumns={1} rowData={rowData}