Skip to content

Commit c8ec758

Browse files
committed
[Fix] attendance update
1 parent 8feea8f commit c8ec758

File tree

1 file changed

+35
-42
lines changed

1 file changed

+35
-42
lines changed

frontend/src/pages/admin/AdminStudentAttendance.jsx

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -72,59 +72,52 @@ const processWeeklyAttendance = (rawData) => {
7272
const diffDays = Math.floor((d - startDate) / (1000 * 60 * 60 * 24));
7373
return Math.floor(diffDays / 7) + 1;
7474
};
75+
76+
const dateMap = new Map();
77+
78+
rawData.forEach(({ date, status }) => {
79+
const week = getWeekFromDate(date);
80+
const dayKey = `${week}-${date}`;
81+
if (!dateMap.has(dayKey)) dateMap.set(dayKey, []);
82+
dateMap.get(dayKey).push(status);
83+
});
84+
/*
7585
const getDateForClass = (week, classIdx) => {
7686
const base = new Date(startDate);
7787
base.setDate(base.getDate() + (week - 1) * 7 + offsetDays[classIdx]);
7888
return base.toISOString().split("T")[0]; // 'YYYY-MM-DD' 형식
7989
};
80-
90+
*/
8191
// 주차별 출석 정보 묶기
82-
const weekMap = new Map();
8392

84-
rawData.forEach(({ date, order, status }) => {
85-
const week = getWeekFromDate(date);
86-
const entry = { date, order, status: status ? "SUCCESS" : "FAILURE" };
93+
dateMap.forEach((statusList, key) => {
94+
const [week, date] = key.split("-");
95+
const trueCount = statusList.filter(Boolean).length;
96+
97+
let status = "EMPTY";
98+
switch (trueCount) {
99+
case 3:
100+
status = "SUCCESS";
101+
break;
102+
case 2:
103+
status = "INSUFFICIENT";
104+
break;
105+
case 1:
106+
status = "FAILURE";
107+
break;
108+
default:
109+
status = "EMPTY";
110+
}
87111

88112
if (!weekMap.has(week)) weekMap.set(week, []);
89-
weekMap.get(week).push(entry);
113+
weekMap.get(week).push({ date, status });
90114
});
91-
92115
return Array.from({ length: 5 }, (_, i) => {
93116
const week = i + 1;
94-
const entries = (weekMap.get(week) || []).sort((a, b) => a.order - b.order);
95-
96-
const classes = [0, 1, 2].map((classIdx) => {
97-
const order = classIdx + 1;
98-
const slice = entries.slice(classIdx * 3, classIdx * 3 + 3);
99-
const entry = entries.find((e) => e.order === order);
100-
const fallbackDate = getDateForClass(week, classIdx);
101-
102-
103-
const trueCount = slice.filter((e) => e.status === "SUCCESS").length;
104-
105-
let status;
106-
switch (trueCount) {
107-
case 3:
108-
status = "SUCCESS";
109-
break;
110-
case 2:
111-
status = "INSUFFICIENT";
112-
break;
113-
case 1:
114-
status = "FAILURE";
115-
break;
116-
default:
117-
status = "EMPTY";
118-
}
119-
120-
return {
121-
order,
122-
status: entry?.status ?? "EMPTY",
123-
date: entry?.date ?? fallbackDate,
124-
};
125-
});
126-
127-
return { week, classes };
117+
const days = (weekMap.get(String(week)) || []).sort((a, b) =>
118+
a.date.localeCompare(b.date)
119+
);
120+
return { week, days };
128121
});
129122
};
130123

@@ -156,7 +149,7 @@ const processWeeklyAttendance = (rawData) => {
156149
<AdminDailyAttendanceCard
157150
studentId={studentId}
158151
date={selectedDate.date}
159-
order={selectedDate.order}
152+
//order={selectedDate.order}
160153
onClose={() => setSelectedDate(null)}
161154
onRefresh={fetchData}
162155
/>

0 commit comments

Comments
 (0)