feat: 도시침수예방사업, 노후하수관로 정비사업 페이지 분기 조건 체크 구현

This commit is contained in:
swcho
2025-07-07 21:12:57 +09:00
parent b396a14a5d
commit 3c73ba7125
2 changed files with 46 additions and 18 deletions
+25 -13
View File
@@ -13,23 +13,35 @@ export const yearOptions = Array.from({ length: 10 }, (_, i) => {
});
// 현재 날짜를 기준으로 현재 분기까지의 분기 옵션 생성
export const getQuarterOptions = (): { text: string; val: string }[] => {
export const getQuarterOptions = (selectedYear?: string): { text: string; val: string }[] => {
const currentDate = new Date();
const currentYear = currentDate.getFullYear().toString();
const currentMonth = currentDate.getMonth() + 1; // 0부터 시작하므로 +1
// 현재 월을 기준으로 현재 분기 계산
const currentQuarter = Math.ceil(currentMonth / 3);
// 현재 분기까지의 분기 옵션 생성
const quarterOptions = [];
for (let i = 1; i <= currentQuarter; i++) {
quarterOptions.push({
text: `${i}분기`,
val: i.toString()
});
// 현재 년도인 경우에만 현재 날짜까지의 분기 표시
if (selectedYear === currentYear) {
// 현재 월을 기준으로 현재 분기 계산
const currentQuarter = Math.ceil(currentMonth / 3);
// 현재 분기까지의 분기 옵션 생성
const quarterOptions = [];
for (let i = 1; i <= currentQuarter; i++) {
quarterOptions.push({
text: `${i}분기`,
val: i.toString()
});
}
return quarterOptions;
} else {
// 이전 년도인 경우 모든 분기 표시
return [
{ text: "1분기", val: "1" },
{ text: "2분기", val: "2" },
{ text: "3분기", val: "3" },
{ text: "4분기", val: "4" }
];
}
return quarterOptions;
};
// ["202506", "202505", "202502", "202405"] 을 SelectBox의 옵션으로 변환
@@ -1,6 +1,6 @@
"use client"
import { SelectBox } from '@common/business_components/ui';
import React, { useState } from 'react'
import React, { useState, useEffect } from 'react'
import FileUploadForm from './fileUploadForm';
import { yearOptions, getQuarterOptions } from '@/components/lib/utils';
@@ -8,11 +8,24 @@ const operFileUploadForm = ({ title, onSubmit }: { title: string, onSubmit: (fil
const [atflCd, setAtflCd] = useState<string | null>(null);
const [atflId, setAtflId] = useState<string | null>(null);
const quaterOptions = getQuarterOptions();
const [selectedYear, setSelectedYear] = useState<string>(yearOptions[0]?.val || '');
const [quaterOptions, setQuaterOptions] = useState(() => getQuarterOptions(selectedYear));
const [selectedQuarter, setSelectedQuarter] = useState<string>(quaterOptions[0]?.val || '');
// 년도가 변경될 때 분기 옵션 업데이트
useEffect(() => {
const updatedQuarterOptions = getQuarterOptions(selectedYear);
setQuaterOptions(updatedQuarterOptions);
// 분기 옵션이 변경되면 첫 번째 옵션으로 자동 선택
setSelectedQuarter(updatedQuarterOptions[0]?.val || '');
}, [selectedYear]);
// 년도 변경 핸들러
const handleYearChange = (value: string | number) => {
const yearValue = String(value);
setSelectedYear(yearValue);
};
return (
<div>
<div className='card-header'>
@@ -26,13 +39,16 @@ const operFileUploadForm = ({ title, onSubmit }: { title: string, onSubmit: (fil
selectClass="rounded-lg bg-white"
label="년도"
selectArray={yearOptions}
onSelectValue={(value: string | number) => setSelectedYear(String(value))}
/><SelectBox
onSelectValue={handleYearChange}
value={selectedYear}
/>
<SelectBox
className="w-50"
selectClass="rounded-lg bg-white"
label="분기"
selectArray={quaterOptions}
onSelectValue={(value: string | number) => setSelectedQuarter(String(value))}
value={selectedQuarter}
/>
<FileUploadForm
onSubmit={(files, year, quarter, code, id) => {