diff --git a/apps/admin/apis/study/studyApi.ts b/apps/admin/apis/study/studyApi.ts index 38dd2deb..4bad8934 100644 --- a/apps/admin/apis/study/studyApi.ts +++ b/apps/admin/apis/study/studyApi.ts @@ -161,4 +161,15 @@ export const studyApi = { ); return response.data; }, + getStudyStudentsExcel: async (studyId: number) => { + const response = await fetcher.get( + `/mentor/studies/${studyId}/students/excel`, + { + next: { tags: [tags.studentsExcel] }, + cache: "force-cache", + } + ); + + return response.data; + }, }; diff --git a/apps/admin/app/students/_components/StudentsHeader.tsx b/apps/admin/app/students/_components/StudentsHeader.tsx index 26b7f97d..3cd386a8 100644 --- a/apps/admin/app/students/_components/StudentsHeader.tsx +++ b/apps/admin/app/students/_components/StudentsHeader.tsx @@ -1,31 +1,54 @@ import { Flex, styled } from "@styled-system/jsx"; import { Text } from "@wow-class/ui"; +import { studyApi } from "apis/study/studyApi"; import ItemSeparator from "components/ItemSeparator"; import Image from "next/image"; import type { CSSProperties } from "react"; +import { useEffect, useState } from "react"; import type { StudyListApiResponseDto } from "types/dtos/studyList"; import StudyDropDown from "./StudyDropDown"; const StudentsHeader = ({ studyList, + studyId, + studentLength, }: { studyList: StudyListApiResponseDto[]; + studyId?: number; + studentLength: number; }) => { + const [url, setUrl] = useState(""); + + useEffect(() => { + const fetchData = async () => { + const response = await studyApi.getStudyStudentsExcel(studyId); + const blob = new Blob([response], { + type: "application/vnd.ms-excel", + }); + const url = URL.createObjectURL(blob); + if (url) setUrl(url); + }; + + if (studentLength) fetchData(); + }, [studyId, studentLength]); + return ( 수강생 관리 - - 다운로드 - + {studyId && studentLength ? ( + + 다운로드 + + ) : null} ); }; diff --git a/apps/admin/app/students/page.tsx b/apps/admin/app/students/page.tsx index 74df6895..a35abd86 100644 --- a/apps/admin/app/students/page.tsx +++ b/apps/admin/app/students/page.tsx @@ -22,9 +22,11 @@ const StudentsPage = () => { useEffect(() => { const fetchData = async () => { const adminStatus = await isAdmin(); - const data = adminStatus - ? await studyApi.getStudyList() - : await studyApi.getMyStudyList(); + const data = + // adminStatus + // ? await studyApi.getStudyList() + // : + await studyApi.getMyStudyList(); if (data && data.length && data[0]) { setStudyList(data); @@ -41,11 +43,16 @@ const StudentsPage = () => { }; const { studentList, pageInfo } = useFetchStudents(selectedStudy, page); + if (!selectedStudy) return null; if (!studyList) return 담당한 스터디가 없어요.; return ( - + {studentList.length ? : null}