From f18fa6e3e4402ce892eea3e6e95765c116789f9f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?=
<80620802+burakboduroglu@users.noreply.github.com>
Date: Wed, 15 Jul 2026 10:38:13 +0300
Subject: [PATCH] =?UTF-8?q?refactor:=20=E2=99=BB=EF=B8=8F=20role-based=20p?=
=?UTF-8?q?ortal=20dashboard=20with=20timeline=20and=20chart?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- rebuild dashboard as role-based portal card grid (student/teacher/manager/admin)
- each card has accent bar, icon, stat, role badge, links to section
- upcoming timeline panel with dated events and exams
- activity bar chart showing course/exam/event counts
- compute stat values eagerly (fix 0 display for admin)
- show "0" instead of "..." / "--" for empty or loading KPIs
- auto-rows-fr grid with flex-col cards for equal height alignment
- remove all old dashboard sub-components (dead code)
---
src/pages/dashboard-page.tsx | 119 ++++++++++++-----------------------
1 file changed, 41 insertions(+), 78 deletions(-)
diff --git a/src/pages/dashboard-page.tsx b/src/pages/dashboard-page.tsx
index c13361e..0fe789c 100644
--- a/src/pages/dashboard-page.tsx
+++ b/src/pages/dashboard-page.tsx
@@ -40,7 +40,7 @@ interface PortalCard {
titleKey: MessageKey;
to: string;
descKey: MessageKey;
- stat: () => string | number;
+ stat: string | number;
statSuffix?: MessageKey;
accent: string;
minRole?: Role;
@@ -140,7 +140,7 @@ function DashboardContent() {
const totalExamsCount = createMemo(() => (exams.loading ? null : visibleExams().length));
const totalEventsCount = createMemo(() => (events.loading ? null : events()?.length ?? 0));
const totalNotesCount = createMemo(() => (notes.loading ? null : notes()?.length ?? 0));
- const displayCount = (count: number | null) => count ?? "...";
+ const displayCount = (count: number | null) => String(count ?? 0);
const overallAvg = createMemo(() => marks()?.overall_average ?? null);
@@ -171,88 +171,54 @@ function DashboardContent() {
Math.max(1, ...chartData().map((d) => d.value)),
);
- const cards = createMemo(() => {
+ const cards = () => {
const roleVal = role();
+ const cc = displayCount(courseCount());
+ const ec = displayCount(totalExamsCount());
+ const evc = displayCount(totalEventsCount());
+ const nc = displayCount(totalNotesCount());
+ const avg = overallAvg() == null ? "0" : roundAvg(overallAvg()!);
const list: PortalCard[] = [];
if (roleVal === "student") {
list.push(
- {
- icon: ,
- titleKey: "nav.courses",
- to: "/courses",
- descKey: "dashboard.portal.coursesDesc",
- stat: () => displayCount(courseCount()),
- statSuffix: "dashboard.records",
- accent: "violet",
- },
- {
- icon: ,
- titleKey: "nav.exams",
- to: "/exams",
- descKey: "dashboard.portal.examsDesc",
- stat: () => displayCount(totalExamsCount()),
- statSuffix: "dashboard.records",
- accent: "amber",
- },
- {
- icon: ,
- titleKey: "nav.events",
- to: "/events",
- descKey: "dashboard.portal.eventsDesc",
- stat: () => displayCount(totalEventsCount()),
- statSuffix: "dashboard.records",
- accent: "sky",
- },
- {
- icon: ,
- titleKey: "nav.marks",
- to: "/marks",
- descKey: "dashboard.portal.marksDesc",
- stat: () => (overallAvg() == null ? "--" : roundAvg(overallAvg()!)),
- accent: "mint",
- },
- {
- icon: ,
- titleKey: "nav.notes",
- to: "/notes",
- descKey: "dashboard.portal.notesDesc",
- stat: () => displayCount(totalNotesCount()),
- statSuffix: "dashboard.records",
- accent: "rose",
- },
+ { icon: , titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: cc, statSuffix: "dashboard.records", accent: "violet" },
+ { icon: , titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: ec, statSuffix: "dashboard.records", accent: "amber" },
+ { icon: , titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: evc, statSuffix: "dashboard.records", accent: "sky" },
+ { icon: , titleKey: "nav.marks", to: "/marks", descKey: "dashboard.portal.marksDesc", stat: avg, accent: "mint" },
+ { icon: , titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: nc, statSuffix: "dashboard.records", accent: "rose" },
);
}
if (roleVal === "teacher") {
list.push(
- { icon: , titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: () => displayCount(courseCount()), statSuffix: "dashboard.records", accent: "violet" },
- { icon: , titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: () => displayCount(totalExamsCount()), statSuffix: "dashboard.records", accent: "amber" },
- { icon: , titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: () => displayCount(totalEventsCount()), statSuffix: "dashboard.records", accent: "sky", minRole: "teacher" },
- { icon: , titleKey: "nav.studentMarks", to: "/management/student-marks", descKey: "dashboard.portal.studentMarksDesc", stat: () => "", accent: "mint", minRole: "teacher" },
- { icon: , titleKey: "nav.studentAttendance", to: "/management/student-attendance", descKey: "dashboard.portal.attendanceDesc", stat: () => "", accent: "rose", minRole: "teacher" },
- { icon: , titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: () => displayCount(totalNotesCount()), statSuffix: "dashboard.records", accent: "sky" },
- { icon: , titleKey: "nav.work", to: "/work", descKey: "dashboard.portal.workDesc", stat: () => "", accent: "amber", minRole: "teacher" },
+ { icon: , titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: cc, statSuffix: "dashboard.records", accent: "violet" },
+ { icon: , titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: ec, statSuffix: "dashboard.records", accent: "amber" },
+ { icon: , titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: evc, statSuffix: "dashboard.records", accent: "sky", minRole: "teacher" },
+ { icon: , titleKey: "nav.studentMarks", to: "/management/student-marks", descKey: "dashboard.portal.studentMarksDesc", stat: "", accent: "mint", minRole: "teacher" },
+ { icon: , titleKey: "nav.studentAttendance", to: "/management/student-attendance", descKey: "dashboard.portal.attendanceDesc", stat: "", accent: "rose", minRole: "teacher" },
+ { icon: , titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: nc, statSuffix: "dashboard.records", accent: "sky" },
+ { icon: , titleKey: "nav.work", to: "/work", descKey: "dashboard.portal.workDesc", stat: "", accent: "amber", minRole: "teacher" },
);
}
if (hasMinRole(roleVal, "manager")) {
list.unshift(
- { icon: , titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: () => displayCount(courseCount()), statSuffix: "dashboard.records", accent: "violet" },
- { icon: , titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: () => displayCount(totalExamsCount()), statSuffix: "dashboard.records", accent: "amber" },
- { icon: , titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: () => displayCount(totalEventsCount()), statSuffix: "dashboard.records", accent: "sky" },
- { icon: , titleKey: "nav.settings", to: "/management/settings", descKey: "dashboard.portal.settingsDesc", stat: () => "", accent: "mint", minRole: "manager" },
- { icon: , titleKey: "nav.terms", to: "/management/terms", descKey: "dashboard.portal.termsDesc", stat: () => "", accent: "rose", minRole: "manager" },
+ { icon: , titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: cc, statSuffix: "dashboard.records", accent: "violet" },
+ { icon: , titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: ec, statSuffix: "dashboard.records", accent: "amber" },
+ { icon: , titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: evc, statSuffix: "dashboard.records", accent: "sky" },
+ { icon: , titleKey: "nav.settings", to: "/management/settings", descKey: "dashboard.portal.settingsDesc", stat: "", accent: "mint", minRole: "manager" },
+ { icon: , titleKey: "nav.terms", to: "/management/terms", descKey: "dashboard.portal.termsDesc", stat: "", accent: "rose", minRole: "manager" },
);
if (roleVal === "admin") {
list.push(
- { icon: , titleKey: "nav.users", to: "/admin/users", descKey: "dashboard.portal.usersDesc", stat: () => "", accent: "rose", minRole: "admin" },
+ { icon: , titleKey: "nav.users", to: "/admin/users", descKey: "dashboard.portal.usersDesc", stat: "", accent: "rose", minRole: "admin" },
);
}
}
return list;
- });
+ };
return (
@@ -272,11 +238,11 @@ function DashboardContent() {
}>
-
+
-
+
= {
violet: "border-violet-500/30 bg-violet-500/10 text-violet-700 dark:text-violet-300",
@@ -314,7 +279,7 @@ function PortalCard(props: { card: PortalCard }) {
-
+
{t(titleKey)}
@@ -358,15 +323,13 @@ function PortalCard(props: { card: PortalCard }) {
-
-
- {statValue}
-
- {(suffix) => {t(suffix())}}
-
-
-
-
{t(descKey)}
+
+ {statValue || "—"}
+
+ {(suffix) => {t(suffix())}}
+
+
+
{t(descKey)}
);
@@ -378,7 +341,7 @@ function UpcomingTimeline(props: {
t: (key: MessageKey, params?: Record
) => string;
}) {
return (
-
+
{props.t("dashboard.upcoming")}
@@ -431,7 +394,7 @@ function ActivityChart(props: {
maxValue: number;
}) {
return (
-