{
+ const result = confirm(
+ "Are you sure you want to mark this course as not completed? You will lose corresponding badges."
+ );
+
+ if (!result) return;
try {
const response = await fetch("/api/courses/uncomplete-course", {
method: "POST",
@@ -110,6 +115,29 @@ export default function CourseCard({
body: JSON.stringify({ courseId: course.id }),
});
if (!res.ok) throw new Error("Failed to complete course");
+
+ const data = await res.json();
+ const { specificBadges = [], earnedBadges = [] } = data;
+
+ const msgs: string[] = [];
+ if (specificBadges.length) {
+ msgs.push(
+ `Course badge earned: ${specificBadges
+ .map((b: any) => b.name)
+ .join(", ")}`
+ );
+ }
+ if (earnedBadges.length) {
+ msgs.push(
+ `Milestone badge earned: ${earnedBadges
+ .map((b: any) => b.name)
+ .join(", ")}`
+ );
+ }
+ if (msgs.length) {
+ alert(msgs.join("\n"));
+ }
+
window.location.reload();
} catch (err) {
console.error(err);
diff --git a/components/reports/AdminBasicReport.tsx b/components/reports/AdminBasicReport.tsx
index 85715c1..1d577b3 100644
--- a/components/reports/AdminBasicReport.tsx
+++ b/components/reports/AdminBasicReport.tsx
@@ -53,6 +53,13 @@ interface TagPerf {
pct: number;
}
+interface UserBadge {
+ id: number;
+ name: string;
+ description: string;
+ awarded_at: string;
+}
+
interface EmployeeProgress {
id: number;
firstname: string;
@@ -63,6 +70,16 @@ interface EmployeeProgress {
quizResults: QuizResult[];
strengths: TagPerf[];
weaknesses: TagPerf[];
+ badges: UserBadge[];
+}
+
+interface OrganisationBadges {
+ id: number;
+ name: string;
+ description: string;
+ course_id: number | null;
+ milestone: number | null;
+ earned_count: number;
}
interface OverviewData {
@@ -71,6 +88,7 @@ interface OverviewData {
total: number;
list: EmployeeProgress[];
};
+ badges: OrganisationBadges[];
}
export default function AdminBasicReport() {
@@ -152,6 +170,33 @@ export default function AdminBasicReport() {
+
+ All Badges
+ {data.badges.length ? (
+
+ {data.badges.map((b) => (
+
+
{b.name}
+ {b.description && (
+
+ {b.description}
+
+ )}
+
+ Earned by {b.earned_count}{" "}
+ {b.earned_count === 1 ? "employee" : "employees"}
+
+
+ ))}
+
+ ) : (
+ No badges defined yet.
+ )}
+
+
Employees Progress ({data.employees.total})
@@ -200,12 +245,10 @@ export default function AdminBasicReport() {
None yet
)}