diff --git a/src/apis/hooks/yearId/useGetClassYearList.ts b/src/apis/hooks/yearId/useGetClassYearList.ts new file mode 100644 index 0000000..c74c481 --- /dev/null +++ b/src/apis/hooks/yearId/useGetClassYearList.ts @@ -0,0 +1,32 @@ +import { useQuery, UseQueryResult } from '@tanstack/react-query'; + +import { fetchInstance } from '@gdg/apis/instance/Api_JWT'; + +export type classYearList = { + id: number; + name: string; + applyStartDateTime: string; + applyEndDateTime: string; +}; + +const getClassYearListPath = () => '/api/admin/class-year'; + +const teamListQueryKey = [getClassYearListPath()]; + +const getClassYearList = async () => { + const response = await fetchInstance.get(getClassYearListPath()); + return response.data; +}; + +export const useGetClassYearList = (): UseQueryResult< + classYearList[], + Error +> => { + const accessToken = sessionStorage.getItem('accessToken'); + + return useQuery({ + queryKey: teamListQueryKey, + queryFn: getClassYearList, + enabled: !!accessToken, + }); +}; diff --git a/src/pages/admin/components/docs/ClassYearIdDropDown.tsx b/src/pages/admin/components/docs/ClassYearIdDropDown.tsx index c7bb610..72281b0 100644 --- a/src/pages/admin/components/docs/ClassYearIdDropDown.tsx +++ b/src/pages/admin/components/docs/ClassYearIdDropDown.tsx @@ -1,6 +1,7 @@ import styled from '@emotion/styled'; import { displayCenter } from '@gdg/styles/LayoutStyle'; +import { useGetClassYearList } from '@gdg/apis/hooks/yearId/useGetClassYearList'; import { DividingLine } from './ApplyDetailModal.style'; @@ -41,16 +42,16 @@ const ClassYearIdDropDown = ({ }: { onYearIdClick: (id: number) => void; }) => { - const yearIdList = [1, 2, 3, 4]; + const { data: yearIdList } = useGetClassYearList(); return ( - {yearIdList.map((id) => ( -
- onYearIdClick(id)} - >{`${id}κΈ°`} - {id < yearIdList.length && } + {yearIdList?.map((id) => ( +
+ onYearIdClick(id.id)}> + {id.name} + + {id.id < yearIdList.length && }
))}