diff --git a/src/app/WeekendMeals/page.tsx b/src/app/WeekendMeals/page.tsx index 25d7a92..db09d9a 100644 --- a/src/app/WeekendMeals/page.tsx +++ b/src/app/WeekendMeals/page.tsx @@ -3,13 +3,12 @@ import React, { useEffect, useState } from "react"; import Dropdown from "@/app/components/common/dropdown"; import Classmeals from "../components/common/list/classmeal/page"; import { + ChangeState, MealCheck, - NotMealCheck, useClassWeekendMealExcel, } from "@/apis/weekendMeal"; import { setStudentNum } from "@/utils/until"; import Button from "../components/common/Button"; -import { Printexcel } from "@/apis/weekendMeal"; import { BackGround } from "../components/common/background"; import { useRouter } from "next/navigation"; import { NextPage } from "next"; @@ -18,16 +17,38 @@ const WeekendMeals: NextPage = () => { const router = useRouter(); const [selectGrade, setSelectGrade] = useState(1); const [selectClass, setSelectClass] = useState(1); - const [effect, setEffect] = useState(0); - const { downloadExcel } = Printexcel(); const { usedownloadClassExcel } = useClassWeekendMealExcel(); const AllMeals = () => { router.push("/WeekendMeals/all"); }; - const { data: checkMealMutate } = MealCheck(selectGrade, selectClass); + const { data: checkMealMutate, refetch: ReCheckMealMutate } = MealCheck( + selectGrade, + selectClass + ); + const { mutate: ChangeMealMutate } = ChangeState(); + + const Change = async (selectedOption: "신청" | "미신청", id: string) => { + const status = selectedOption === "미신청" ? "NO" : "OK"; + try { + await ChangeMealMutate( + { status, id }, + { + onSuccess: () => { + ReCheckMealMutate(); + }, + onError: (error) => { + alert(`${error.message} : 에러가 발생하였습니다`); + }, + } + ); + } catch (error) { + alert(`상태변경중 에러가 발생했습니다`); + console.log(error); + } + }; useEffect(() => { const grade = parseInt(localStorage.getItem("grade") || "1", 10); @@ -92,8 +113,10 @@ const WeekendMeals: NextPage = () => { number={setStudentNum(item)} name={item.name} state={item.status || "NO"} - onclick={() => {}} - id="" + onclick={(selectedOption) => + Change(selectedOption, item.id) + } + id={item.id} /> ) )} @@ -104,18 +127,6 @@ const WeekendMeals: NextPage = () => {
미신청자
- {/* {notCheckMealMutate?.map((item, index) => ( - { - setEffect(effect + 1); - }} - /> - ))} */} {checkMealMutate?.map( (item, index) => item.status === "NO" && ( @@ -124,8 +135,10 @@ const WeekendMeals: NextPage = () => { number={setStudentNum(item)} name={item.name} state={item.status || "NO"} - onclick={() => {}} - id="" + onclick={(selectedOption) => + Change(selectedOption, item.id) + } + id={item.id} /> ) )} diff --git a/src/app/components/common/dropdown/state/class/page.tsx b/src/app/components/common/dropdown/state/class/page.tsx index 75f88b5..34988e1 100644 --- a/src/app/components/common/dropdown/state/class/page.tsx +++ b/src/app/components/common/dropdown/state/class/page.tsx @@ -1,56 +1,28 @@ "use client"; -import { ChangeState } from "@/apis/weekendMeal"; import React, { useState, useRef, useEffect } from "react"; interface StateDropProps { - option: "신청" | "미신청" | "미응답"; + option: "신청" | "미신청"; id: string; - onclick: () => void; + onclick: (selectedOption: "신청" | "미신청") => void; } const ClassmealDrop = ({ option, id, onclick }: StateDropProps) => { - const { mutate: ChangeMealMutate } = ChangeState(); const dropdownRef = useRef(null); const [isDropdownVisible, setIsDropdownVisible] = useState(false); - - const Change = async (selectedOption: "신청" | "미신청") => { - const status = selectedOption === "미신청" ? "NO" : "OK"; - try { - await ChangeMealMutate( - { status, id: id || "" }, - { - onSuccess: () => {}, - onError: (error) => { - alert(`${error.message} : 에러가 발생하였습니다`); - }, - } - ); - } catch (error) { - alert(`상태변경중 에러가 발생했습니다`); - console.log(error); - } - }; - - const change = () => { - return option; - }; + const [grade, setGrade] = useState(0); const toggleDropdown = () => { - if (option === "미응답") { - setIsDropdownVisible(!isDropdownVisible); - } + setIsDropdownVisible(!isDropdownVisible); }; const handleOptionClick = (selectedOption: "신청" | "미신청") => { setIsDropdownVisible(false); - Change(selectedOption); - onclick(); + onclick(selectedOption); }; const dropStyle = () => { switch (option) { - case "미응답": - return "group border bg-white py-1 px-3 focus:border-primary-200 rounded-lg cursor-pointer flex items-center justify-center"; case "미신청": return "bg-white py-1 border px-3 rounded-lg flex justify-center items-center border-primary-500 text-neutral-500"; case "신청": @@ -58,7 +30,8 @@ const ClassmealDrop = ({ option, id, onclick }: StateDropProps) => { } }; - const commonStyle = "py-4 px-2 rounded hover:bg-primary-200 hover:text-white"; + const commonStyle = + "py-4 px-2 rounded hover:bg-primary-200 hover:text-white cursor-pointer"; useEffect(() => { const handleClickOutside = (event: MouseEvent) => { @@ -75,13 +48,17 @@ const ClassmealDrop = ({ option, id, onclick }: StateDropProps) => { }; }, []); + useEffect(() => { + setGrade(parseInt(localStorage.getItem("grade") || "1", 10)); + }, []); + return ( -
+
- {change()} + {option}
- {option === "미응답" && isDropdownVisible && ( -
+ {grade !== 0 && isDropdownVisible && ( +
{ handleOptionClick("신청"); diff --git a/src/app/components/common/list/classmeal/page.tsx b/src/app/components/common/list/classmeal/page.tsx index cce7b18..620bce3 100644 --- a/src/app/components/common/list/classmeal/page.tsx +++ b/src/app/components/common/list/classmeal/page.tsx @@ -5,9 +5,9 @@ import ClassmealDrop from "../../dropdown/state/class/page"; interface allmealsProps { number: string; name: string; - state: "OK" | "NO" | "QUIET"; + state: "OK" | "NO"; id: string; - onclick: () => void; + onclick: (selectedOption: "신청" | "미신청") => void; } const Classmeals = ({ number, name, state, id, onclick }: allmealsProps) => { @@ -17,8 +17,6 @@ const Classmeals = ({ number, name, state, id, onclick }: allmealsProps) => { return "미신청"; case "OK": return "신청"; - case "QUIET": - return "미응답"; } };