Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
hyuna committed Jun 25, 2024
2 parents 89e6b7e + 1724955 commit bceb65e
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 67 deletions.
11 changes: 7 additions & 4 deletions src/app/afterManage/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>(false);
Expand All @@ -28,7 +28,7 @@ const AfterManage = () => {
const [saveModal, setSaveModal] = useState<boolean>(false);
const [selectClub, setSelectClub] = useState<string>("대동여지도");
const { selectedStudents, selectedStudentName, handleAcceptListClick } =
useAcceptListSelection();
useAcceptListSelection();
const { data: getAfter } = GetAfterStudent();
const { data: getClub } = GetClubList(selectClub);
const { mutate: Post } = PostStudent();
Expand All @@ -38,7 +38,6 @@ const AfterManage = () => {

const day = getWeekDay();


useEffect(() => {
if (getClub) {
setClubList([]);
Expand Down Expand Up @@ -91,7 +90,11 @@ const AfterManage = () => {
student_num: studentNum,
};
});
Post(updatedData);
Post(updatedData, {
onSuccess: () => {
location.reload();
},
});
setModal(false);
};

Expand Down
64 changes: 23 additions & 41 deletions src/app/classManage/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>(false);
const [edit, setEdit] = useState<boolean>(false);
const [selectedGrade, setSelectedGrade] = useState<number>(1);
const [selectedClass, setSelectedClass] = useState<number>(1);
const [data, setData] = useState<StudentData>();
const { selectedStudentName, handleManageListClick } =
useManageListSelection();
const [modifiedStudents, setModifiedStudents] = useState<ChangeStatusData[]>(
[]
);
const {
selectedStudents,
selectedStudentNames,
modifiedStudents,
handleManageListClick,
} = useManageListSelection();
const { mutate: getStudentDataMutate } = GetStudentData();
const { mutate: changestatusMutate } = ChangeStatus();

Expand Down Expand Up @@ -151,47 +146,34 @@ const ClassManage: React.FC = () => {
상태 수정하기
</Button>
)}
<div className=" flex gap-5">
<div className="flex gap-5">
<Dropdown type="grade" onChange={handleGradeChange} />
<Dropdown type="class" onChange={handleClassChange} />
</div>
</>
}
>
{edit &&
data?.students.map((student, index) => (
<ManageList
key={index}
student={`${setStudentNum(student)} ${student.name}`}
state={changeStatusName(student.status)}
edit={false}
onChange={(status) =>
handleManageListClick(student.user_id, status, student.name)
}
/>
))}
{!edit &&
data?.students.map((student, index) => (
<ManageList
key={index}
student={`${setStudentNum(student)} ${student.name}`}
state={changeStatusName(student.status)}
edit={true}
onChange={(status) =>
handleManageListClick(student.user_id, status, student.name)
}
/>
))}
{data?.students.map((student, index) => (
<ManageList
key={index}
student={`${setStudentNum(student)} ${student.name}`}
state={changeStatusName(student.status)}
edit={!edit}
onChange={(status) =>
handleManageListClick(student.user_id, status, student.name)
}
/>
))}
{modal && (
<Modal
type="button"
heading1={`${
selectedStudentName.length > 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="변경된 상태를 저장하시겠습니까?"
Expand Down
66 changes: 44 additions & 22 deletions src/hook/useManageListSelection.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -12,37 +18,53 @@ interface ManageListSelectionHook {

const useManageListSelection = (): ManageListSelectionHook => {
const [selectedStudents, setSelectedStudents] = useState<string[]>([]);
const [selectedStudentName, setSelectedStudentName] = useState<string[]>([]);
const [selectedStudentNames, setSelectedStudentNames] = useState<string[]>(
[]
);
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;

0 comments on commit bceb65e

Please sign in to comment.