st: refactor: 연도 & 전년도 데이터 가져오기 & 그리드 내 데이터 editable 판별 로직 수정
This commit is contained in:
@@ -40,7 +40,10 @@ const SeweragePenetrationRateInp = () => {
|
||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||
const [searchValues, setSearchValues] = useState<SearchFormValues | null>(null);
|
||||
const [isEnterable, setIsEnterable] = useState<boolean>(true);
|
||||
const [lastSearchedYear, setLastSearchedYear] = useState<string | null>(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 &&
|
||||
<div className="card !py-0">
|
||||
<div className="flex justify-end items-center gap-[0.6rem] mx-[0.6rem]">
|
||||
<SubmitExceptionButton SubmitExceptionFunc={SubmitExceptionFunc} />
|
||||
<LastYearDataButton getLastYearDataFunc={() => getLastYearDataFunc(searchValues ?? {})} />
|
||||
<SubmitButton submitFunc={submitFunc} />
|
||||
<SaveButton saveFunc={saveFunc} />
|
||||
{isEnterable && <SubmitExceptionButton SubmitExceptionFunc={SubmitExceptionFunc} />}
|
||||
{isEnterable && <LastYearDataButton getLastYearDataFunc={() => getLastYearDataFunc(searchValues ?? {})} />}
|
||||
{isEnterable && <SubmitButton submitFunc={submitFunc} />}
|
||||
{
|
||||
// 최고 관리자일땐 저장 가능하게
|
||||
<SaveButton saveFunc={saveFunc} />
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@@ -141,6 +154,7 @@ const SeweragePenetrationRateInp = () => {
|
||||
<DataGrid
|
||||
key={isEnterable ? 'enterable' : 'readonly'}
|
||||
columnInfo={columnInfo}
|
||||
isExcelImport={(rowData.length > 0) && isEnterable}
|
||||
rowStartNum={3}
|
||||
fixedColumns={1}
|
||||
rowData={rowData}
|
||||
|
||||
Reference in New Issue
Block a user