fix: StudentReport Page 리포트카드 안나오는거 수정 시험 한번도 안 본 상태에서 접근 시 에러 안나게 변경

This commit is contained in:
minwucho 2024-08-09 16:35:08 +09:00
parent 8b82681089
commit 7b972cf4f8

View File

@ -9,11 +9,10 @@ export default function StudentReportPage() {
const { lectureId } = useParams();
const { data } = useStudentReports(lectureId);
const reports = data?.data;
console.log(reports);
const totalCounts = reports.reduce?.(
(acc, report) => {
if (acc.allCount > 0) {
if (report.allCount > 0) {
acc.correctCount += report.correctCount;
acc.allCount += report.allCount;
}
@ -27,24 +26,26 @@ export default function StudentReportPage() {
title="퀴즈 성적"
canCreate={false}
>
<div className={styles.wrapper}>
<div className={styles.LinksContainer}>
{reports.map?.((report) => (
<ArticleLink
key={`${report.reportId}`}
title={report.title}
sub={report.allCount === 0 ? '미응시' : `${Math.round((report.correctCount / report.allCount) * 100)}%`}
to={`${report.reportId}`}
{totalCounts && (
<div className={styles.wrapper}>
<div className={styles.LinksContainer}>
{reports.map?.((report) => (
<ArticleLink
key={`${report.reportId}`}
title={report.title}
sub={report.allCount === 0 ? '미응시' : `${Math.round((report.correctCount / report.allCount) * 100)}%`}
to={`${report.reportId}`}
/>
))}
</div>
<div className={styles.reportCardContainer}>
<ReportCard
correctCount={totalCounts.correctCount}
allCount={totalCounts.allCount}
/>
))}
</div>
</div>
<div className={styles.reportCardContainer}>
<ReportCard
correctCount={totalCounts.correctCount}
allCount={totalCounts.allCount}
/>
</div>
</div>
)}
</ArticleBoard>
);
}