From f003116e210c1aed744bb74b447b5e4e2bc0d581 Mon Sep 17 00:00:00 2001 From: hyuna Date: Wed, 26 Jun 2024 09:59:32 +0900 Subject: [PATCH 1/2] =?UTF-8?q?chore=20:=20=EB=AA=85=EC=84=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EC=99=B8=EC=B6=9C?= =?UTF-8?q?=EC=9E=90=20=EB=B3=B5=EA=B7=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/outList/index.ts | 15 +-- src/app/outList/page.tsx | 123 +++++++++++++++------- src/components/list/application/index.tsx | 54 ---------- 3 files changed, 94 insertions(+), 98 deletions(-) diff --git a/src/api/outList/index.ts b/src/api/outList/index.ts index a64a1e9..72392bb 100644 --- a/src/api/outList/index.ts +++ b/src/api/outList/index.ts @@ -25,13 +25,16 @@ export const EarlyReturn = () => { export const ReturnSchool = () => { const { handleError } = apiError(); - return useMutation({ - mutationFn: async (param) => { + return useMutation({ + mutationFn: async (...param) => { try { - const response = await instance.patch( - `/application/change/${param.id}` - ); - return response.data; + console.log(param); + const { data } = await instance.patch(`/application/return`, ...param, { + headers: { + "Content-Type": "application/json", + }, + }); + return data; } catch (error) { handleError(error); } diff --git a/src/app/outList/page.tsx b/src/app/outList/page.tsx index 9a41ee2..48da14f 100644 --- a/src/app/outList/page.tsx +++ b/src/app/outList/page.tsx @@ -1,34 +1,40 @@ "use client"; -import { Application, EarlyReturn } from "@/api/outList"; -import { applicationOK, earlyReturnHome } from "@/api/type"; +import { Application, EarlyReturn, ReturnSchool } from "@/api/outList"; import BackGround from "@/components/background"; +import Button from "@/components/button"; import NonReturn from "@/components/list/application"; +import Modal from "@/components/modal"; +import useAcceptListSelection from "@/hook/handleAcceptListClick"; import { getFullToday } from "@/util/date"; import { getStudentString } from "@/util/util"; import React, { useEffect, useState } from "react"; const OutList = () => { const [selectedTab, setSelectedTab] = useState(true); - const [applicationData, setApplicationData] = useState([]); - const [earlyData, setEarlyData] = useState(); + const { selectedStudents, selectedStudentName, handleAcceptListClick } = + useAcceptListSelection(); + const [modal, setModal] = useState(false); const { data: applicationOKData } = Application(); const { data: earlyReturnData } = EarlyReturn(); - - useEffect(() => { - if (applicationOKData) { - setApplicationData(applicationOKData); - } - }, [applicationOKData]); - - useEffect(() => { - setEarlyData(earlyReturnData); - }, [earlyReturnData]); + const { mutate: ReturnApplication } = ReturnSchool(); const onClickTab = (tab: boolean) => { setSelectedTab(tab); }; + const Return = () => { + ReturnApplication(selectedStudents, { + onSuccess: () => { + location.reload(); + }, + onError: () => { + console.log("에러가 발생했습니다"); + setModal(false); + }, + }); + }; + return ( { leftTab="외출" rightTab="조기귀가" TabOnclick={onClickTab} + Dropdown={ + selectedTab && ( +
+
+
+ +
+
+ ) + } >
- {selectedTab - ? Array.isArray(applicationData) && ( - <> - {applicationData.map((item, index) => ( - - ))} - - ) - : earlyData?.map((item, index) => ( - - ))} + {selectedTab ? ( + <> + {applicationOKData && + applicationOKData?.map((item, index) => ( + { + handleAcceptListClick(item.id, item.username); + }} + id={item.id} + type="application" + key={index} + returnTime={item.end_time} + name={getStudentString(item)} + reason={item.reason} + /> + ))} + + ) : ( + earlyReturnData?.map((item, index) => ( + + )) + )}
+ {modal && ( + 1 + ? `${selectedStudentName[0]} 학생 외 ${ + selectedStudentName.length - 1 + }명을 복귀시키겠습니까?` + : selectedStudentName.length === 1 + ? `${selectedStudentName[0]} 학생을 복귀시키겠습니까?` + : "" + }`} + onCancel={() => { + setModal(false); + }} + onConfirm={Return} + /> + )}
); }; diff --git a/src/components/list/application/index.tsx b/src/components/list/application/index.tsx index 416e4df..4bc6dc5 100644 --- a/src/components/list/application/index.tsx +++ b/src/components/list/application/index.tsx @@ -1,8 +1,5 @@ "use client"; -import { ReturnSchool } from "@/api/outList"; -import Button from "@/components/button"; import StatusDrop from "@/components/dropdown/status"; -import Modal from "@/components/modal"; import React, { useState } from "react"; interface NonReturnProp { @@ -18,41 +15,10 @@ export const NonReturn: React.FC = ({ name, returnTime, type, - id, onClick, reason, }) => { - const { mutate: ReturnStudent } = ReturnSchool(); const [click, setClick] = useState(false); - const [modal, setModal] = useState(false); - - const onClickModal = () => { - setModal(true); - }; - - const onCancelModal = () => { - setModal(false); - }; - - const confirmReturn = async () => { - try { - await ReturnStudent( - { id: id }, - { - onSuccess: () => { - location.reload(); - alert("복귀에 성공하셨습니다"); - }, - onError: () => { - console.log("에러발생"); - }, - } - ); - } catch (error) { - console.error(error); - } - setModal(false); - }; return (
@@ -69,29 +35,9 @@ export const NonReturn: React.FC = ({
{returnTime} 복귀 예정
-
-
- -
-
)} {type === "after" && {}} state="출석" />} - {modal && ( - - )} {type === "accept" && (
{returnTime}
)} From f001aa6285a7834f304b54d469f275c8485f5ce1 Mon Sep 17 00:00:00 2001 From: hyuna Date: Wed, 26 Jun 2024 10:26:27 +0900 Subject: [PATCH 2/2] =?UTF-8?q?chore=20:=20=EB=AA=85=EC=84=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EC=99=B8=EC=B6=9C?= =?UTF-8?q?=EC=9E=90=20=EB=B3=B5=EA=B7=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/outList/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/outList/page.tsx b/src/app/outList/page.tsx index 48da14f..a9aa402 100644 --- a/src/app/outList/page.tsx +++ b/src/app/outList/page.tsx @@ -65,7 +65,7 @@ const OutList = () => {
{selectedTab ? ( <> - {applicationOKData && + {Array.isArray(applicationOKData) && applicationOKData?.map((item, index) => ( {