Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

어드민페이지 기수별 지원서 개수 조회 구현 #195

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/apis/hooks/admin/docs/useGetStatistic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,27 @@ const getStatisticPath = () => '/api/admin/application/statistic';

const statisticQueryKey = [getStatisticPath()];

export const getStatistic = async (): Promise<statisticInterface> => {
const response =
await fetchInstance.get<statisticInterface>(getStatisticPath());
export const getStatistic = async (
classYearId: number
): Promise<statisticInterface> => {
const response = await fetchInstance.get<statisticInterface>(
getStatisticPath(),
{
params: {
classYearId: classYearId,
},
}
);

return response.data;
};

export const useGetStatistic = () => {
export const useGetStatistic = (classYearId: number) => {
const accessToken = sessionStorage.getItem('accessToken');

return useQuery<statisticInterface, Error>({
queryKey: [statisticQueryKey],
queryFn: getStatistic,
queryFn: () => getStatistic(classYearId),
enabled: !!accessToken,
});
};
12 changes: 8 additions & 4 deletions src/apis/hooks/admin/docs/useGetTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@ const getTrackPath = () => '/api/admin/application/statistic/track';

const statisticQueryKey = [getTrackPath()];

const getTrack = async (): Promise<TrackInterface> => {
const response = await fetchInstance.get<TrackInterface>(getTrackPath());
const getTrack = async (classYearId: number): Promise<TrackInterface> => {
const response = await fetchInstance.get<TrackInterface>(getTrackPath(), {
params: {
classYearId: classYearId,
},
});

return response.data;
};

export const useGetTrack = () => {
export const useGetTrack = (classYearId: number) => {
const accessToken = sessionStorage.getItem('accessToken');

return useQuery<TrackInterface, Error>({
queryKey: [statisticQueryKey],
queryFn: getTrack,
queryFn: () => getTrack(classYearId),
enabled: !!accessToken,
});
};
39 changes: 31 additions & 8 deletions src/pages/admin/AdminDocConfirmPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useState, lazy } from 'react';
import { useState, useEffect, lazy } from 'react';

import { useGetStatistic } from '@gdg/apis/hooks/admin/docs/useGetStatistic';
import { useGetTrack } from '@gdg/apis/hooks/admin/docs/useGetTrack';
import { useGetClassYearList } from '@gdg/apis/hooks/yearId/useGetClassYearList';
import { DisplayLayout } from '@gdg/styles/LayoutStyle';

import ClassYearIdDropDown from './components/docs/ClassYearIdDropDown';
Expand All @@ -23,11 +24,32 @@ const CurrentApplyInfo = lazy(
const AdminSearchBar = lazy(() => import('./components/AdminSearchBar'));

const AdminDocConfirmPage = () => {
const { data: yearIdList } = useGetClassYearList();

const [isMarked, setIsMarked] = useState<boolean>(false);
const [searchName, setSearchName] = useState<string>('');
const [trackIdx, setTrackIdx] = useState<number>(0);
const [isDropdownOpen, setIsDropdownOpen] = useState<boolean>(false);
const [classYearId, setClassYearId] = useState<number>(4);
const [classYearId, setClassYearId] = useState<number>(1);
const [classYearname, setClassYearName] = useState<string>('1기');

const { data: applyData, refetch: refetchApplyData } =
useGetStatistic(classYearId);
const { data: trackData, refetch: refetchTrackData } =
useGetTrack(classYearId);

useEffect(() => {
if (yearIdList && yearIdList.length > 0) {
const lastYear = yearIdList[yearIdList.length - 1];
setClassYearId(lastYear.id);
setClassYearName(lastYear.name);
}
}, [yearIdList]);

useEffect(() => {
refetchApplyData();
refetchTrackData();
}, [classYearId, refetchApplyData, refetchTrackData]);

const handlePassCheck = () => {
setIsMarked((prev) => !prev);
Expand All @@ -37,14 +59,12 @@ const AdminDocConfirmPage = () => {
setIsDropdownOpen((prev) => !prev);
};

const handleYearIdClick = (id: number) => {
const handleYearIdClick = (id: number, name: string) => {
setClassYearId(id);
setClassYearName(name);
setIsDropdownOpen(false);
};

const { data: applyData } = useGetStatistic();
const { data: trackData } = useGetTrack();

const handleTrackSelect = (index: number) => {
setTrackIdx(index);
};
Expand All @@ -66,10 +86,13 @@ const AdminDocConfirmPage = () => {
isSelected={isDropdownOpen}
onClick={handleClassYearIdCheck}
>
{`${classYearId}기 ${'\u00A0'} ▾`}
{`${classYearname} ${'\u00A0'} ▾`}
</PassBtn>
{isDropdownOpen && (
<ClassYearIdDropDown onYearIdClick={handleYearIdClick} />
<ClassYearIdDropDown
yearIdList={yearIdList}
onYearIdClick={handleYearIdClick}
/>
)}
</ButtonContainer>
</ButtonBox>
Expand Down
10 changes: 5 additions & 5 deletions src/pages/admin/components/docs/ClassYearIdDropDown.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled from '@emotion/styled';

import { displayCenter } from '@gdg/styles/LayoutStyle';
import { useGetClassYearList } from '@gdg/apis/hooks/yearId/useGetClassYearList';
import { classYearList } from '@gdg/apis/hooks/yearId/useGetClassYearList';

import { DividingLine } from './ApplyDetailModal.style';
const DropdownContainer = styled.div`
Expand Down Expand Up @@ -37,17 +37,17 @@ const YearIdButton = styled.div`
`;

const ClassYearIdDropDown = ({
yearIdList,
onYearIdClick,
}: {
onYearIdClick: (id: number) => void;
yearIdList: classYearList[] | undefined;
onYearIdClick: (id: number, name: string) => void;
}) => {
const { data: yearIdList } = useGetClassYearList();

return (
<DropdownContainer>
{yearIdList?.map((id) => (
<div key={id.id}>
<YearIdButton onClick={() => onYearIdClick(id.id)}>
<YearIdButton onClick={() => onYearIdClick(id.id, id.name)}>
{id.name}
</YearIdButton>
{id.id < yearIdList.length && <DividingLine />}
Expand Down
Loading