From 962e026afe15118f1568e8c557ac5030bcbe8085 Mon Sep 17 00:00:00 2001 From: hyuna Date: Fri, 30 Aug 2024 09:11:12 +0900 Subject: [PATCH 1/3] =?UTF-8?q?add=20::=20=EB=B0=98=EB=B3=84=20=EC=97=91?= =?UTF-8?q?=EC=85=80=EC=B6=9C=EB=A0=A5=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/weekendMeal/index.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/apis/weekendMeal/index.ts b/src/apis/weekendMeal/index.ts index 634b176..6a13bc2 100644 --- a/src/apis/weekendMeal/index.ts +++ b/src/apis/weekendMeal/index.ts @@ -1,6 +1,7 @@ import apiError from "@/hook/apiError"; import { instance } from ".."; import { useMutation, useQuery } from "@tanstack/react-query"; +import { link } from "fs"; interface ChangeStateParams { status: "OK" | "NO"; @@ -48,6 +49,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({ From dc77454c74577a502c231d4a83904a9ea7fcd547 Mon Sep 17 00:00:00 2001 From: hyuna Date: Fri, 30 Aug 2024 09:12:23 +0900 Subject: [PATCH 2/3] =?UTF-8?q?add=20::=20api=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/WeekendMeals/page.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/app/WeekendMeals/page.tsx b/src/app/WeekendMeals/page.tsx index 5a6d426..9882a8a 100644 --- a/src/app/WeekendMeals/page.tsx +++ b/src/app/WeekendMeals/page.tsx @@ -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"; @@ -17,6 +21,7 @@ const WeekendMeals: NextPage = () => { const [effect, setEffect] = useState(0); const { downloadExcel } = Printexcel(); + const { usedownloadClassExcel } = useClassWeekendMealExcel(); const AllMeals = () => { router.push("/WeekendMeals/all"); @@ -48,7 +53,11 @@ const WeekendMeals: NextPage = () => { linkChildren={`주말 급식 신청 현황 > ${selectGrade}학년 ${selectClass}반`} DropChildren={ <> -