diff --git a/src/components/common/Filter/SemesterDropdown.tsx b/src/components/common/Filter/SemesterDropdown.tsx index 66367a8..60be290 100644 --- a/src/components/common/Filter/SemesterDropdown.tsx +++ b/src/components/common/Filter/SemesterDropdown.tsx @@ -2,27 +2,29 @@ import { Box, FormControl, InputLabel, MenuItem, Select, styled } from '@mui/mat import { useEffect } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { setSemester } from 'src/redux/slices/filter'; +import { generateSemesters, currentYear } from 'src/utils/semesterAutoGenerate'; +// const SEMESTERS = [ +// '전체', -const SEMESTERS = [ - '전체', - - '2020-01', - '2020-02', - '2021-01', - '2021-02', - '2022-01', - '2022-02', - '2023-01', - '2023-02', - '2024-01', - '2024-02', - '2025-01', - '2025-02', - '2026-01', - '2026-02', -]; +// '2020-01', +// '2020-02', +// '2021-01', +// '2021-02', +// '2022-01', +// '2022-02', +// '2023-01', +// '2023-02', +// '2024-01', +// '2024-02', +// '2025-01', +// '2025-02', +// '2026-01', +// '2026-02', +// ]; export default function SemesterDropdown() { + const SEMESTERS = generateSemesters(currentYear); + const semester = useSelector((state) => state.filter.semester); const dispatch = useDispatch(); diff --git a/src/components/common/Select/SemesterMagicianSelect.tsx b/src/components/common/Select/SemesterMagicianSelect.tsx index 5379032..a918e82 100644 --- a/src/components/common/Select/SemesterMagicianSelect.tsx +++ b/src/components/common/Select/SemesterMagicianSelect.tsx @@ -2,26 +2,27 @@ import { FormControl, InputLabel, MenuItem, Select } from '@mui/material'; import { ErrorMessage, Field } from 'formik'; import { useSelector } from 'react-redux'; import { CATEGORYID, SEMESTER } from 'src/assets/data/fields'; - +import { generateSemesters, currentYear } from 'src/utils/semesterAutoGenerate'; export default function SemesterMagicianSelect({ semester, setSemester }) { - const semesters = [ - '2020-01', - '2020-02', - '2021-01', - '2021-02', - '2022-01', - '2022-02', - '2023-01', - '2023-02', - '2024-01', - '2024-02', - '2025-01', - '2025-02', - '2026-01', - '2026-02', - '2027-01', - '2027-02', - ]; + // const semesters = [ + // '2020-01', + // '2020-02', + // '2021-01', + // '2021-02', + // '2022-01', + // '2022-02', + // '2023-01', + // '2023-02', + // '2024-01', + // '2024-02', + // '2025-01', + // '2025-02', + // '2026-01', + // '2026-02', + // '2027-01', + // '2027-02', + // ]; + const semesters = generateSemesters(currentYear); return ( diff --git a/src/utils/semesterAutoGenerate.js b/src/utils/semesterAutoGenerate.js new file mode 100644 index 0000000..f60c545 --- /dev/null +++ b/src/utils/semesterAutoGenerate.js @@ -0,0 +1,15 @@ +export const generateSemesters = (currentYear) => { + const startYear = currentYear - 4; + const endYear = currentYear + 1; + const semesters = []; + + for (let year = startYear; year <= endYear; year += 1) { + semesters.push(`${year}-01`); + semesters.push(`${year}-02`); + } + + return semesters; +}; + +const currentDate = new Date(); +export const currentYear = currentDate.getFullYear();