From 3c73ba71258eac9c83e92e2be35a9425f08dc12d Mon Sep 17 00:00:00 2001 From: swcho Date: Mon, 7 Jul 2025 21:12:57 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=8F=84=EC=8B=9C=EC=B9=A8=EC=88=98?= =?UTF-8?q?=EC=98=88=EB=B0=A9=EC=82=AC=EC=97=85,=20=EB=85=B8=ED=9B=84?= =?UTF-8?q?=ED=95=98=EC=88=98=EA=B4=80=EB=A1=9C=20=EC=A0=95=EB=B9=84?= =?UTF-8?q?=EC=82=AC=EC=97=85=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EB=B6=84?= =?UTF-8?q?=EA=B8=B0=20=EC=A1=B0=EA=B1=B4=20=EC=B2=B4=ED=81=AC=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/sn/app/components/lib/utils/date.ts | 38 ++++++++++++------- .../app/components/ui/operFileUploadForm.tsx | 26 ++++++++++--- 2 files changed, 46 insertions(+), 18 deletions(-) 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} /> {