Skip to content

Commit 5b20b73

Browse files
feat: make clear why exam cannot be taken
1 parent 9d8804a commit 5b20b73

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/components/exam-card.tsx

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ interface ExamStatus {
3232
| "InProgress"
3333
| "PendingModeration"
3434
| "RetakeLater"
35-
| "Expired";
35+
| "Expired"
36+
| "UnmetPrerequisites";
3637
message?: string;
3738
alertStatus?: "success" | "info" | "warning" | "error";
3839
}
@@ -156,9 +157,18 @@ function getExamStatus(
156157
attempts: Attempts
157158
): ExamStatus {
158159
const latestAttempt = getLatestAttempt(attempts);
160+
const examStatus: ExamStatus = { status: "Available" };
159161

160162
if (!latestAttempt) {
161-
return { status: "Available" };
163+
if (!exam.canTake && exam.prerequisites.length > 0) {
164+
return {
165+
status: "UnmetPrerequisites",
166+
message:
167+
"You must complete the prerequisite courses to take this exam.",
168+
alertStatus: "info",
169+
};
170+
}
171+
return examStatus;
162172
}
163173

164174
switch (latestAttempt.status) {
@@ -186,7 +196,15 @@ function getExamStatus(
186196

187197
const now = new Date();
188198
if (now >= retakeAvailableAt) {
189-
return { status: "Available" };
199+
if (!exam.canTake && exam.prerequisites.length > 0) {
200+
return {
201+
status: "UnmetPrerequisites",
202+
message:
203+
"You must complete the prerequisite courses to take this exam.",
204+
alertStatus: "info",
205+
};
206+
}
207+
return examStatus;
190208
}
191209

192210
return {
@@ -196,7 +214,15 @@ function getExamStatus(
196214
};
197215

198216
default:
199-
return { status: "Available" };
217+
if (!exam.canTake && exam.prerequisites.length > 0) {
218+
return {
219+
status: "UnmetPrerequisites",
220+
message:
221+
"You must complete the prerequisite courses to take this exam.",
222+
alertStatus: "info",
223+
};
224+
}
225+
return examStatus;
200226
}
201227
}
202228

src/utils/fetch.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export async function getExams() {
135135
retakeTimeInS: exam.config.retakeTimeInS,
136136
passingPercent: exam.config.passingPercent,
137137
},
138+
prerequisites: [],
138139
},
139140
];
140141
}

0 commit comments

Comments
 (0)