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