Skip to content

Commit

Permalink
chore :: 출석체크 귀가 상태 추가
Browse files Browse the repository at this point in the history
chore :: 출석체크 귀가 상태 추가
  • Loading branch information
phyuna0525 authored Aug 24, 2024
2 parents 8b4292f + 693fb9b commit 3e3e46d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 20 deletions.
16 changes: 8 additions & 8 deletions src/app/afterManage/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ const AfterManage = () => {
const [modal, setModal] = useState<boolean>(false);
const [change, setChange] = useState<boolean>(false);
const [clubList, setClubList] = useState<ClubList[]>([]);
const [dataList, setDataList] = useState<AfterStudent[]>();
const [saveModal, setSaveModal] = useState<boolean>(false);
const [dataList, setDataList] = useState<AfterStudent[]>();
const [selectClub, setSelectClub] = useState<string>("대동여지도");
const { selectedStudents, selectedStudentName, handleAcceptListClick } =
useAcceptListSelection();
const { data: getAfter } = GetAfterStudent();
const { data: getClub } = GetClubList(selectClub);
const { data: getAfter, refetch: ReGetAfter } = GetAfterStudent();
const { data: getClub, refetch: ReGetClub } = GetClubList(selectClub);
const { mutate: Post } = PostStudent();

const { mutate: CheckClub } = CheckStatus();
Expand Down Expand Up @@ -148,11 +148,11 @@ const AfterManage = () => {
};
updatedData.push(studentData);
}
FixStatusMutate(updatedData, {
onSuccess: () => {
location.reload();
},
});
});
FixStatusMutate(updatedData, {
onSuccess: () => {
ReGetAfter();
},
});
setSaveModal(false);
};
Expand Down
4 changes: 3 additions & 1 deletion src/app/components/common/list/after/check/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";
import React, { useEffect, useState } from "react";
import AfterCheck from "../page";
import useAttendanceStore from "@/stores/useChangeStatus";

interface State {
state1: string;
Expand Down Expand Up @@ -41,6 +42,8 @@ const CheckList: React.FC<State> = ({
return "현체";
case "EMPLOYMENT":
return "취업";
case "GO_HOME":
return "귀가";
default:
return "";
}
Expand All @@ -55,7 +58,6 @@ const CheckList: React.FC<State> = ({
useEffect(() => {
localStorage.setItem(id, JSON.stringify(statusList));
}, [id, statusList]);

const handleChange = (index: number, newState: string) => {
const newStatusList = [...statusList];
for (let i = index; i < newStatusList.length; i++) {
Expand Down
10 changes: 10 additions & 0 deletions src/app/components/common/list/after/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ const AfterCheck: React.FC<AfterCheckProp> = ({ state, onChange, type }) => {
return "#414BA2";
case "출석":
return "#475467";
case "귀가":
"#475467";
default:
return undefined;
}
Expand All @@ -80,6 +82,8 @@ const AfterCheck: React.FC<AfterCheckProp> = ({ state, onChange, type }) => {
return "MOVEMENT";
case "출석":
return "ATTENDANCE";
case "귀가":
return "GO_HOME";
default:
return "";
}
Expand Down Expand Up @@ -131,6 +135,12 @@ const AfterCheck: React.FC<AfterCheckProp> = ({ state, onChange, type }) => {
>
외출
</div>
<div
className={`${commonStyle} text-neutral-50`}
onClick={() => handleOptionClick("귀가")}
>
귀가
</div>
<div
className={`${commonStyle} text-error-400`}
onClick={() => handleOptionClick("무단")}
Expand Down
7 changes: 5 additions & 2 deletions src/app/selfStudyCheck/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ const SelfStudyCheck = () => {
const [edit, setEdit] = useState<boolean>(false);
const [saveModal, setSaveModal] = useState<boolean>(false);
const { mutate: ChangeMutate } = CheckStatus();
const { data: CheckMutate } = ClassStudentCheck(selectedGrade, selectedClass);
const { data: CheckMutate, refetch: ReCheckData } = ClassStudentCheck(
selectedGrade,
selectedClass
);
const { selectedStudentName, handleAcceptListClick } =
useAcceptListSelection();
const { addStudent, updateStatus, getStatus, students } =
Expand Down Expand Up @@ -63,7 +66,7 @@ const SelfStudyCheck = () => {
try {
await ChangeMutate(updatedData, {
onSuccess: () => {
location.reload();
ReCheckData();
},
onError: (error) => {
alert(error.name);
Expand Down
18 changes: 9 additions & 9 deletions src/stores/useChangeStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@ import create from "zustand";

interface Student {
user_id: string;
status: string;
status_list: string[];
}

interface AttendanceStore {
students: Student[];
addStudent: (user_id: string, status?: string) => void;
updateStatus: (user_id: string, status: string) => void;
getStatus: (user_id: string) => string | undefined;
addStudent: (user_id: string, status_list?: string[]) => void;
updateStatus: (user_id: string, status_list: string[]) => void;
getStatus: (user_id: string) => string[] | undefined;
}

const useAttendanceStore = create<AttendanceStore>((set, get) => ({
students: [],

addStudent: (user_id, status = "ATTENDANCE") => {
addStudent: (user_id, status_list = ["ATTENDANCE"]) => {
set((state) => ({
students: [...state.students, { user_id, status }],
students: [...state.students, { user_id, status_list }],
}));
},

updateStatus: (user_id, status) => {
updateStatus: (user_id, status_list) => {
set((state) => ({
students: state.students.map((student) =>
student.user_id === user_id ? { ...student, status } : student
student.user_id === user_id ? { ...student, status_list } : student
),
}));
},

getStatus: (user_id) => {
return get().students.find((student) => student.user_id === user_id)
?.status;
?.status_list;
},
}));

Expand Down

0 comments on commit 3e3e46d

Please sign in to comment.