Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
hyuna committed Aug 31, 2024
2 parents ec6fe16 + ee9a6d9 commit 31c5c65
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 63 deletions.
55 changes: 34 additions & 21 deletions src/app/WeekendMeals/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -18,16 +17,38 @@ const WeekendMeals: NextPage = () => {
const router = useRouter();
const [selectGrade, setSelectGrade] = useState<number>(1);
const [selectClass, setSelectClass] = useState<number>(1);
const [effect, setEffect] = useState<number>(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);
Expand Down Expand Up @@ -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}
/>
)
)}
Expand All @@ -104,18 +127,6 @@ const WeekendMeals: NextPage = () => {
<div className=" text-heading6-M text-gray-900">미신청자</div>
</div>
<div className="flex flex-col gap-3 h-full">
{/* {notCheckMealMutate?.map((item, index) => (
<Classmeals
id={item.id}
key={index}
number={setStudentNum(item)}
name={item.name}
state={item.status || "QUIET"}
onclick={() => {
setEffect(effect + 1);
}}
/>
))} */}
{checkMealMutate?.map(
(item, index) =>
item.status === "NO" && (
Expand All @@ -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}
/>
)
)}
Expand Down
53 changes: 15 additions & 38 deletions src/app/components/common/dropdown/state/class/page.tsx
Original file line number Diff line number Diff line change
@@ -1,64 +1,37 @@
"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<HTMLDivElement>(null);
const [isDropdownVisible, setIsDropdownVisible] = useState<boolean>(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<number>(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 "신청":
return "bg-primary-300 py-1 px-3 rounded-lg flex justify-center items-center text-white";
}
};

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) => {
Expand All @@ -75,13 +48,17 @@ const ClassmealDrop = ({ option, id, onclick }: StateDropProps) => {
};
}, []);

useEffect(() => {
setGrade(parseInt(localStorage.getItem("grade") || "1", 10));
}, []);

return (
<div className="relative w-24" ref={dropdownRef}>
<div className="relative w-24 " ref={dropdownRef}>
<div className={dropStyle()} onClick={toggleDropdown}>
{change()}
{option}
</div>
{option === "미응답" && isDropdownVisible && (
<div className="absolute z-10 bg-white border rounded-lg w-full text-Button-S">
{grade !== 0 && isDropdownVisible && (
<div className="absolute z-10 bg-white border rounded-lg w-full text-Button-S ">
<div
onClick={() => {
handleOptionClick("신청");
Expand Down
6 changes: 2 additions & 4 deletions src/app/components/common/list/classmeal/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -17,8 +17,6 @@ const Classmeals = ({ number, name, state, id, onclick }: allmealsProps) => {
return "미신청";
case "OK":
return "신청";
case "QUIET":
return "미응답";
}
};

Expand Down

0 comments on commit 31c5c65

Please sign in to comment.