Skip to content

Commit

Permalink
주말급식 반별 엑셀 출력
Browse files Browse the repository at this point in the history
주말급식 반별 엑셀 출력
  • Loading branch information
phyuna0525 authored Aug 30, 2024
2 parents fdab01d + 79eb8ea commit 0162e16
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
29 changes: 29 additions & 0 deletions src/apis/weekendMeal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,35 @@ export const Printexcel = () => {
return { downloadExcel };
};

export const useClassWeekendMealExcel = () => {
const usedownloadClassExcel = async (grade: number, class_num: number) => {
try {
const { data } = await instance.get(
`/weekend-meal/excel/grade?grade=${grade}&class_num=${class_num}`,
{
responseType: "blob",
}
);

const url = window.URL.createObjectURL(new Blob([data]));
const link = document.createElement("a");
link.href = url;
link.setAttribute(
"download",
`${grade}학년 ${class_num}반 주말급식.xlsx`
);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
} catch (error) {
console.log(error);
alert("잠시후 다시 시도해주세요");
}
};

return { usedownloadClassExcel };
};

export const ChangeState = () => {
const { handleError } = apiError();
return useMutation<void, Error, ChangeStateParams>({
Expand Down
2 changes: 1 addition & 1 deletion src/app/WeekendMeals/all/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const AllWeekendMeal = () => {
DropChildren={
<>
<Button colorType="ghost" onClick={downloadExcel} buttonSize="small">
엑셀로 출력하기
전체 엑셀 출력하기
</Button>
<Button
colorType="primary"
Expand Down
15 changes: 12 additions & 3 deletions src/app/WeekendMeals/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
import React, { useEffect, useState } from "react";
import Dropdown from "@/app/components/common/dropdown";
import Classmeals from "../components/common/list/classmeal/page";
import { MealCheck, NotMealCheck } from "@/apis/weekendMeal";
import {
MealCheck,
NotMealCheck,
useClassWeekendMealExcel,
} from "@/apis/weekendMeal";
import { setStudentNum } from "@/utils/until";
import Button from "../components/common/Button";
import { Printexcel } from "@/apis/weekendMeal";
Expand All @@ -17,6 +21,7 @@ const WeekendMeals: NextPage = () => {
const [effect, setEffect] = useState<number>(0);

const { downloadExcel } = Printexcel();
const { usedownloadClassExcel } = useClassWeekendMealExcel();

const AllMeals = () => {
router.push("/WeekendMeals/all");
Expand Down Expand Up @@ -48,8 +53,12 @@ const WeekendMeals: NextPage = () => {
linkChildren={`주말 급식 신청 현황 > ${selectGrade}학년 ${selectClass}반`}
DropChildren={
<>
<Button colorType="ghost" buttonSize="small" onClick={downloadExcel}>
엑셀로 출력하기
<Button
colorType="ghost"
buttonSize="small"
onClick={() => usedownloadClassExcel(selectGrade, selectClass)}
>
반별 엑셀 출력하기
</Button>
<Button colorType="primary" buttonSize="small" onClick={AllMeals}>
전체 학생 보기
Expand Down

0 comments on commit 0162e16

Please sign in to comment.