diff --git a/apps/sn/app/components/lib/utils/date.ts b/apps/sn/app/components/lib/utils/date.ts index f26944ce7..9c9106ec2 100644 --- a/apps/sn/app/components/lib/utils/date.ts +++ b/apps/sn/app/components/lib/utils/date.ts @@ -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의 옵션으로 변환 diff --git a/apps/sn/app/components/ui/operFileUploadForm.tsx b/apps/sn/app/components/ui/operFileUploadForm.tsx index 1e7ed727a..3c37673d2 100644 --- a/apps/sn/app/components/ui/operFileUploadForm.tsx +++ b/apps/sn/app/components/ui/operFileUploadForm.tsx @@ -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(null); const [atflId, setAtflId] = useState(null); - const quaterOptions = getQuarterOptions(); - const [selectedYear, setSelectedYear] = useState(yearOptions[0]?.val || ''); + const [quaterOptions, setQuaterOptions] = useState(() => getQuarterOptions(selectedYear)); const [selectedQuarter, setSelectedQuarter] = useState(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 (
@@ -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))} - /> + setSelectedQuarter(String(value))} + value={selectedQuarter} /> {