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}