diff --git a/src/app/afterManage/page.tsx b/src/app/afterManage/page.tsx index 6367a24..35d6c3f 100644 --- a/src/app/afterManage/page.tsx +++ b/src/app/afterManage/page.tsx @@ -17,7 +17,7 @@ import { CheckStatus } from "@/apis/selfStudy"; import { getStudentString, setStudentNum } from "@/utils/until"; import { getWeekDay } from "@/utils/date"; import { AfterStudent, ChangeClub, ChangeStatus, ClubList } from "@/apis/type"; -import useAcceptListSelection from '@/hook/hook'; +import useAcceptListSelection from "@/hook/hook"; const AfterManage = () => { const [edit, setEdit] = useState(false); @@ -28,7 +28,7 @@ const AfterManage = () => { const [saveModal, setSaveModal] = useState(false); const [selectClub, setSelectClub] = useState("대동여지도"); const { selectedStudents, selectedStudentName, handleAcceptListClick } = - useAcceptListSelection(); + useAcceptListSelection(); const { data: getAfter } = GetAfterStudent(); const { data: getClub } = GetClubList(selectClub); const { mutate: Post } = PostStudent(); @@ -38,7 +38,6 @@ const AfterManage = () => { const day = getWeekDay(); - useEffect(() => { if (getClub) { setClubList([]); @@ -91,7 +90,11 @@ const AfterManage = () => { student_num: studentNum, }; }); - Post(updatedData); + Post(updatedData, { + onSuccess: () => { + location.reload(); + }, + }); setModal(false); }; diff --git a/src/app/classManage/page.tsx b/src/app/classManage/page.tsx index 80d7ce0..8a1a3ab 100644 --- a/src/app/classManage/page.tsx +++ b/src/app/classManage/page.tsx @@ -18,28 +18,23 @@ interface Student { num: number; status: string; } - interface StudentData { teacher: string; students: Student[]; } -interface ChangeStatusData { - user_id: string; - status_type: string; -} - const ClassManage: React.FC = () => { const [modal, setModal] = useState(false); const [edit, setEdit] = useState(false); const [selectedGrade, setSelectedGrade] = useState(1); const [selectedClass, setSelectedClass] = useState(1); const [data, setData] = useState(); - const { selectedStudentName, handleManageListClick } = - useManageListSelection(); - const [modifiedStudents, setModifiedStudents] = useState( - [] - ); + const { + selectedStudents, + selectedStudentNames, + modifiedStudents, + handleManageListClick, + } = useManageListSelection(); const { mutate: getStudentDataMutate } = GetStudentData(); const { mutate: changestatusMutate } = ChangeStatus(); @@ -151,47 +146,34 @@ const ClassManage: React.FC = () => { 상태 수정하기 )} -
+
} > - {edit && - data?.students.map((student, index) => ( - - handleManageListClick(student.user_id, status, student.name) - } - /> - ))} - {!edit && - data?.students.map((student, index) => ( - - handleManageListClick(student.user_id, status, student.name) - } - /> - ))} + {data?.students.map((student, index) => ( + + handleManageListClick(student.user_id, status, student.name) + } + /> + ))} {modal && ( 1 - ? `${selectedStudentName[0]} 학생 외 ${ - selectedStudentName.length - 1 + selectedStudentNames.length > 1 + ? `${selectedStudentNames[0]} 학생 외 ${ + selectedStudentNames.length - 1 }명` - : selectedStudentName.length === 1 - ? `${selectedStudentName[0]} 학생` + : selectedStudentNames.length === 1 + ? `${selectedStudentNames[0]} 학생` : "" }`} heading2="변경된 상태를 저장하시겠습니까?" diff --git a/src/hook/useManageListSelection.ts b/src/hook/useManageListSelection.ts index 2164bc3..b6f5e87 100644 --- a/src/hook/useManageListSelection.ts +++ b/src/hook/useManageListSelection.ts @@ -1,8 +1,14 @@ import { useState } from "react"; +interface Student { + user_id: string; + name: string; +} + interface ManageListSelectionHook { selectedStudents: string[]; - selectedStudentName: string[]; + selectedStudentNames: string[]; + modifiedStudents: { user_id: string; status_type: string }[]; handleManageListClick: ( user_id: string, status_type: string, @@ -12,37 +18,53 @@ interface ManageListSelectionHook { const useManageListSelection = (): ManageListSelectionHook => { const [selectedStudents, setSelectedStudents] = useState([]); - const [selectedStudentName, setSelectedStudentName] = useState([]); + const [selectedStudentNames, setSelectedStudentNames] = useState( + [] + ); + const [modifiedStudents, setModifiedStudents] = useState< + { user_id: string; status_type: string }[] + >([]); const handleManageListClick = ( user_id: string, status_type: string, name: string ) => { - setSelectedStudents((prevSelectedStudents) => { - const isStudentSelected = prevSelectedStudents.includes(user_id); - if (isStudentSelected) { - return prevSelectedStudents.filter( - (selectedStudent) => selectedStudent !== user_id - ); - } else { - return [...prevSelectedStudents, user_id]; - } - }); + setModifiedStudents((prevModifiedStudents) => [ + ...prevModifiedStudents, + { user_id, status_type }, + ]); - setSelectedStudentName((prevSelectedStudentName) => { - const isStudentSelected = prevSelectedStudentName.includes(name); - if (isStudentSelected) { - return prevSelectedStudentName.filter( + const isStudentSelected = selectedStudents.includes(user_id); + if (isStudentSelected) { + setSelectedStudents((prevSelectedStudents) => + prevSelectedStudents.filter( + (selectedStudent) => selectedStudent !== user_id + ) + ); + setSelectedStudentNames((prevSelectedStudentNames) => + prevSelectedStudentNames.filter( (selectedStudentName) => selectedStudentName !== name - ); - } else { - return [...prevSelectedStudentName, name]; - } - }); + ) + ); + } else { + setSelectedStudents((prevSelectedStudents) => [ + ...prevSelectedStudents, + user_id, + ]); + setSelectedStudentNames((prevSelectedStudentNames) => [ + ...prevSelectedStudentNames, + name, + ]); + } }; - return { selectedStudents, selectedStudentName, handleManageListClick }; + return { + selectedStudents, + selectedStudentNames, + modifiedStudents, + handleManageListClick, + }; }; export default useManageListSelection;