Skip to content

Commit

Permalink
feat: 수강생 엑셀 다운로드, 스터디리스트 코어멤버도 자신이 생성한 스터디만 보이도록 임시수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hamo-o committed Nov 4, 2024
1 parent 2910db5 commit 839f51d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
11 changes: 11 additions & 0 deletions apps/admin/apis/study/studyApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
};
39 changes: 31 additions & 8 deletions apps/admin/app/students/_components/StudentsHeader.tsx
Original file line number Diff line number Diff line change
@@ -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<string>("");

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 (
<Flex justify="space-between" paddingBottom="1.5rem">
<Text as="h1" style={titleStyle} typo="h1">
수강생 관리 <ItemSeparator height={6} width={6} />
<StudyDropDown studyList={studyList} />
</Text>
<styled.button cursor="pointer">
<Image
alt="다운로드"
height={24}
src="/images/download.svg"
width={24}
/>
</styled.button>
{studyId && studentLength ? (
<styled.a download="study.xls" href={url}>
<Image
alt="다운로드"
height={24}
src="/images/download.svg"
width={24}
/>
</styled.a>
) : null}
</Flex>
);
};
Expand Down
15 changes: 11 additions & 4 deletions apps/admin/app/students/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -41,11 +43,16 @@ const StudentsPage = () => {
};

const { studentList, pageInfo } = useFetchStudents(selectedStudy, page);
if (!selectedStudy) return null;
if (!studyList) return <Text>담당한 스터디가 없어요.</Text>;

return (
<Flex direction="column" gap="1.5rem">
<StudentsHeader studyList={studyList} />
<StudentsHeader
studentLength={studentList.length}
studyId={selectedStudy.studyId}
studyList={studyList}
/>
{studentList.length ? <StudentFilter /> : null}
<StudentList studentList={studentList} />
<StudentPagination
Expand Down
1 change: 1 addition & 0 deletions apps/admin/constants/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export const enum tags {
memberList = "memberList",
attendances = "attendances",
students = "students",
studentsExcel = "studentsExcel",
}

0 comments on commit 839f51d

Please sign in to comment.