st: refactor: 연도 & 전년도 데이터 가져오기 & 그리드 내 데이터 editable 판별 로직 수정
This commit is contained in:
@@ -34,20 +34,6 @@ const SearchForm = (props: SearchFormProps = {}) => {
|
|||||||
|
|
||||||
const currentYear = new Date().getFullYear();
|
const currentYear = new Date().getFullYear();
|
||||||
const defaultYear = currentYear - 1;
|
const defaultYear = currentYear - 1;
|
||||||
const startYear = currentYear - 10;
|
|
||||||
|
|
||||||
const [values, setValues] = useState<SearchFormValues>({
|
|
||||||
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<ApiResponse<SearchCondition>>(
|
const { data: sidoList } = useSWR<ApiResponse<SearchCondition>>(
|
||||||
"sido-list",
|
"sido-list",
|
||||||
@@ -71,6 +57,15 @@ const SearchForm = (props: SearchFormProps = {}) => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const [values, setValues] = useState<SearchFormValues>({
|
||||||
|
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<ApiResponse<Sgg[]>>(
|
const { data: sggList } = useSWR<ApiResponse<Sgg[]>>(
|
||||||
values.sido && values.sido !== "ALL" ? ["sgg-list", values.sido] : null,
|
values.sido && values.sido !== "ALL" ? ["sgg-list", values.sido] : null,
|
||||||
getSggListFetcher,
|
getSggListFetcher,
|
||||||
@@ -123,6 +118,10 @@ const SearchForm = (props: SearchFormProps = {}) => {
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
props.onValuesChange?.(values);
|
||||||
|
}, [values]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="card card-border">
|
<div className="card card-border">
|
||||||
<form onSubmit={handleSubmit}>
|
<form onSubmit={handleSubmit}>
|
||||||
|
|||||||
@@ -40,7 +40,10 @@ const SeweragePenetrationRateInp = () => {
|
|||||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||||
const [searchValues, setSearchValues] = useState<SearchFormValues | null>(null);
|
const [searchValues, setSearchValues] = useState<SearchFormValues | null>(null);
|
||||||
const [isEnterable, setIsEnterable] = useState<boolean>(true);
|
const [isEnterable, setIsEnterable] = useState<boolean>(true);
|
||||||
|
const [lastSearchedYear, setLastSearchedYear] = useState<string | null>(null);
|
||||||
|
|
||||||
|
|
||||||
|
// 최상위 관리자일땐 모든 상황에서 edit 가능하게 수정 필요.
|
||||||
const columnInfo = useMemo(() => {
|
const columnInfo = useMemo(() => {
|
||||||
const { columns, columnLayout } = SeweragePenetrationRateInpColumn;
|
const { columns, columnLayout } = SeweragePenetrationRateInpColumn;
|
||||||
return {
|
return {
|
||||||
@@ -53,6 +56,7 @@ const SeweragePenetrationRateInp = () => {
|
|||||||
|
|
||||||
const handleReset = () => {
|
const handleReset = () => {
|
||||||
setRowData([]);
|
setRowData([]);
|
||||||
|
setLastSearchedYear(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchSewerageSupplyRate = async (params: SewerageSupplyRateRequestParams) => {
|
const fetchSewerageSupplyRate = async (params: SewerageSupplyRateRequestParams) => {
|
||||||
@@ -64,6 +68,7 @@ const SeweragePenetrationRateInp = () => {
|
|||||||
...d,
|
...d,
|
||||||
speclCntrplnAr: d.speclCntrplnAr === '' || d.speclCntrplnAr === null ? '해당없음' : d.speclCntrplnAr,
|
speclCntrplnAr: d.speclCntrplnAr === '' || d.speclCntrplnAr === null ? '해당없음' : d.speclCntrplnAr,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
setRowData(toGridRows(convertedData));
|
setRowData(toGridRows(convertedData));
|
||||||
} else {
|
} else {
|
||||||
alert(response.message);
|
alert(response.message);
|
||||||
@@ -83,10 +88,11 @@ const SeweragePenetrationRateInp = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await statisticsInputAPi.checkInputPeriod(searchValues?.year || '');
|
const response = await statisticsInputAPi.checkInputPeriod(values.year || '');
|
||||||
|
|
||||||
if (response.status === 'success') {
|
if (response.status === 'success') {
|
||||||
setIsEnterable(response.data);
|
setIsEnterable(response.data);
|
||||||
|
setLastSearchedYear(values.year || null);
|
||||||
|
|
||||||
await fetchSewerageSupplyRate(getSewerageSupplyRateParams(values));
|
await fetchSewerageSupplyRate(getSewerageSupplyRateParams(values));
|
||||||
} else {
|
} else {
|
||||||
@@ -106,10 +112,14 @@ const SeweragePenetrationRateInp = () => {
|
|||||||
alert('시도를 선택해주세요.');
|
alert('시도를 선택해주세요.');
|
||||||
return;
|
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 = () => {
|
const submitFunc = () => {
|
||||||
@@ -126,10 +136,13 @@ const SeweragePenetrationRateInp = () => {
|
|||||||
{rowData.length > 0 &&
|
{rowData.length > 0 &&
|
||||||
<div className="card !py-0">
|
<div className="card !py-0">
|
||||||
<div className="flex justify-end items-center gap-[0.6rem] mx-[0.6rem]">
|
<div className="flex justify-end items-center gap-[0.6rem] mx-[0.6rem]">
|
||||||
<SubmitExceptionButton SubmitExceptionFunc={SubmitExceptionFunc} />
|
{isEnterable && <SubmitExceptionButton SubmitExceptionFunc={SubmitExceptionFunc} />}
|
||||||
<LastYearDataButton getLastYearDataFunc={() => getLastYearDataFunc(searchValues ?? {})} />
|
{isEnterable && <LastYearDataButton getLastYearDataFunc={() => getLastYearDataFunc(searchValues ?? {})} />}
|
||||||
<SubmitButton submitFunc={submitFunc} />
|
{isEnterable && <SubmitButton submitFunc={submitFunc} />}
|
||||||
<SaveButton saveFunc={saveFunc} />
|
{
|
||||||
|
// 최고 관리자일땐 저장 가능하게
|
||||||
|
<SaveButton saveFunc={saveFunc} />
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
@@ -141,6 +154,7 @@ const SeweragePenetrationRateInp = () => {
|
|||||||
<DataGrid
|
<DataGrid
|
||||||
key={isEnterable ? 'enterable' : 'readonly'}
|
key={isEnterable ? 'enterable' : 'readonly'}
|
||||||
columnInfo={columnInfo}
|
columnInfo={columnInfo}
|
||||||
|
isExcelImport={(rowData.length > 0) && isEnterable}
|
||||||
rowStartNum={3}
|
rowStartNum={3}
|
||||||
fixedColumns={1}
|
fixedColumns={1}
|
||||||
rowData={rowData}
|
rowData={rowData}
|
||||||
|
|||||||
Reference in New Issue
Block a user