forge
Explore
Log in

Don't you dare go Hollow

♻️ role-based portal dashboard with timeline and chart

Browse files at this commit

f18fa6e3e4402ce892eea3e6e95765c116789f9fBurak BoduroğluParent: 50fd345
  • refactor
    • ♻️ role-based portal dashboard with timeline and chart
Show full message
refactor: ♻️ role-based portal dashboard with timeline and chart

- 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.tsxmodified+41 -78
@@ -40,7 +40,7 @@ interface PortalCard {
4040 titleKey: MessageKey;
4141 to: string;
4242 descKey: MessageKey;
43- stat: () => string | number;
43+ stat: string | number;
4444 statSuffix?: MessageKey;
4545 accent: string;
4646 minRole?: Role;
@@ -140,7 +140,7 @@ function DashboardContent() {
140140 const totalExamsCount = createMemo(() => (exams.loading ? null : visibleExams().length));
141141 const totalEventsCount = createMemo(() => (events.loading ? null : events()?.length ?? 0));
142142 const totalNotesCount = createMemo(() => (notes.loading ? null : notes()?.length ?? 0));
143- const displayCount = (count: number | null) => count ?? "...";
143+ const displayCount = (count: number | null) => String(count ?? 0);
144144
145145 const overallAvg = createMemo(() => marks()?.overall_average ?? null);
146146
@@ -171,88 +171,54 @@ function DashboardContent() {
171171 Math.max(1, ...chartData().map((d) => d.value)),
172172 );
173173
174- const cards = createMemo(() => {
174+ const cards = () => {
175175 const roleVal = role();
176+ const cc = displayCount(courseCount());
177+ const ec = displayCount(totalExamsCount());
178+ const evc = displayCount(totalEventsCount());
179+ const nc = displayCount(totalNotesCount());
180+ const avg = overallAvg() == null ? "0" : roundAvg(overallAvg()!);
176181 const list: PortalCard[] = [];
177182
178183 if (roleVal === "student") {
179184 list.push(
180- {
181- icon: <IconSchool class="h-5 w-5" />,
182- titleKey: "nav.courses",
183- to: "/courses",
184- descKey: "dashboard.portal.coursesDesc",
185- stat: () => displayCount(courseCount()),
186- statSuffix: "dashboard.records",
187- accent: "violet",
188- },
189- {
190- icon: <IconExam class="h-5 w-5" />,
191- titleKey: "nav.exams",
192- to: "/exams",
193- descKey: "dashboard.portal.examsDesc",
194- stat: () => displayCount(totalExamsCount()),
195- statSuffix: "dashboard.records",
196- accent: "amber",
197- },
198- {
199- icon: <IconCalendar class="h-5 w-5" />,
200- titleKey: "nav.events",
201- to: "/events",
202- descKey: "dashboard.portal.eventsDesc",
203- stat: () => displayCount(totalEventsCount()),
204- statSuffix: "dashboard.records",
205- accent: "sky",
206- },
207- {
208- icon: <IconReportAnalytics class="h-5 w-5" />,
209- titleKey: "nav.marks",
210- to: "/marks",
211- descKey: "dashboard.portal.marksDesc",
212- stat: () => (overallAvg() == null ? "--" : roundAvg(overallAvg()!)),
213- accent: "mint",
214- },
215- {
216- icon: <IconNote class="h-5 w-5" />,
217- titleKey: "nav.notes",
218- to: "/notes",
219- descKey: "dashboard.portal.notesDesc",
220- stat: () => displayCount(totalNotesCount()),
221- statSuffix: "dashboard.records",
222- accent: "rose",
223- },
185+ { icon: <IconSchool class="h-5 w-5" />, titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: cc, statSuffix: "dashboard.records", accent: "violet" },
186+ { icon: <IconExam class="h-5 w-5" />, titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: ec, statSuffix: "dashboard.records", accent: "amber" },
187+ { icon: <IconCalendar class="h-5 w-5" />, titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: evc, statSuffix: "dashboard.records", accent: "sky" },
188+ { icon: <IconReportAnalytics class="h-5 w-5" />, titleKey: "nav.marks", to: "/marks", descKey: "dashboard.portal.marksDesc", stat: avg, accent: "mint" },
189+ { icon: <IconNote class="h-5 w-5" />, titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: nc, statSuffix: "dashboard.records", accent: "rose" },
224190 );
225191 }
226192
227193 if (roleVal === "teacher") {
228194 list.push(
229- { icon: <IconSchool class="h-5 w-5" />, titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: () => displayCount(courseCount()), statSuffix: "dashboard.records", accent: "violet" },
230- { icon: <IconExam class="h-5 w-5" />, titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: () => displayCount(totalExamsCount()), statSuffix: "dashboard.records", accent: "amber" },
231- { icon: <IconCalendar class="h-5 w-5" />, titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: () => displayCount(totalEventsCount()), statSuffix: "dashboard.records", accent: "sky", minRole: "teacher" },
232- { icon: <IconChart class="h-5 w-5" />, titleKey: "nav.studentMarks", to: "/management/student-marks", descKey: "dashboard.portal.studentMarksDesc", stat: () => "", accent: "mint", minRole: "teacher" },
233- { icon: <IconClipboardCheck class="h-5 w-5" />, titleKey: "nav.studentAttendance", to: "/management/student-attendance", descKey: "dashboard.portal.attendanceDesc", stat: () => "", accent: "rose", minRole: "teacher" },
234- { icon: <IconNote class="h-5 w-5" />, titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: () => displayCount(totalNotesCount()), statSuffix: "dashboard.records", accent: "sky" },
235- { icon: <IconReportAnalytics class="h-5 w-5" />, titleKey: "nav.work", to: "/work", descKey: "dashboard.portal.workDesc", stat: () => "", accent: "amber", minRole: "teacher" },
195+ { icon: <IconSchool class="h-5 w-5" />, titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: cc, statSuffix: "dashboard.records", accent: "violet" },
196+ { icon: <IconExam class="h-5 w-5" />, titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: ec, statSuffix: "dashboard.records", accent: "amber" },
197+ { icon: <IconCalendar class="h-5 w-5" />, titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: evc, statSuffix: "dashboard.records", accent: "sky", minRole: "teacher" },
198+ { icon: <IconChart class="h-5 w-5" />, titleKey: "nav.studentMarks", to: "/management/student-marks", descKey: "dashboard.portal.studentMarksDesc", stat: "", accent: "mint", minRole: "teacher" },
199+ { icon: <IconClipboardCheck class="h-5 w-5" />, titleKey: "nav.studentAttendance", to: "/management/student-attendance", descKey: "dashboard.portal.attendanceDesc", stat: "", accent: "rose", minRole: "teacher" },
200+ { icon: <IconNote class="h-5 w-5" />, titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: nc, statSuffix: "dashboard.records", accent: "sky" },
201+ { icon: <IconReportAnalytics class="h-5 w-5" />, titleKey: "nav.work", to: "/work", descKey: "dashboard.portal.workDesc", stat: "", accent: "amber", minRole: "teacher" },
236202 );
237203 }
238204
239205 if (hasMinRole(roleVal, "manager")) {
240206 list.unshift(
241- { icon: <IconSchool class="h-5 w-5" />, titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: () => displayCount(courseCount()), statSuffix: "dashboard.records", accent: "violet" },
242- { icon: <IconExam class="h-5 w-5" />, titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: () => displayCount(totalExamsCount()), statSuffix: "dashboard.records", accent: "amber" },
243- { icon: <IconCalendar class="h-5 w-5" />, titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: () => displayCount(totalEventsCount()), statSuffix: "dashboard.records", accent: "sky" },
244- { icon: <IconSettings class="h-5 w-5" />, titleKey: "nav.settings", to: "/management/settings", descKey: "dashboard.portal.settingsDesc", stat: () => "", accent: "mint", minRole: "manager" },
245- { icon: <IconBook class="h-5 w-5" />, titleKey: "nav.terms", to: "/management/terms", descKey: "dashboard.portal.termsDesc", stat: () => "", accent: "rose", minRole: "manager" },
207+ { icon: <IconSchool class="h-5 w-5" />, titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: cc, statSuffix: "dashboard.records", accent: "violet" },
208+ { icon: <IconExam class="h-5 w-5" />, titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: ec, statSuffix: "dashboard.records", accent: "amber" },
209+ { icon: <IconCalendar class="h-5 w-5" />, titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: evc, statSuffix: "dashboard.records", accent: "sky" },
210+ { icon: <IconSettings class="h-5 w-5" />, titleKey: "nav.settings", to: "/management/settings", descKey: "dashboard.portal.settingsDesc", stat: "", accent: "mint", minRole: "manager" },
211+ { icon: <IconBook class="h-5 w-5" />, titleKey: "nav.terms", to: "/management/terms", descKey: "dashboard.portal.termsDesc", stat: "", accent: "rose", minRole: "manager" },
246212 );
247213 if (roleVal === "admin") {
248214 list.push(
249- { icon: <IconUsers class="h-5 w-5" />, titleKey: "nav.users", to: "/admin/users", descKey: "dashboard.portal.usersDesc", stat: () => "", accent: "rose", minRole: "admin" },
215+ { icon: <IconUsers class="h-5 w-5" />, titleKey: "nav.users", to: "/admin/users", descKey: "dashboard.portal.usersDesc", stat: "", accent: "rose", minRole: "admin" },
250216 );
251217 }
252218 }
253219
254220 return list;
255- });
221+ };
256222
257223 return (
258224 <div class="space-y-5">
@@ -272,11 +238,11 @@ function DashboardContent() {
272238 </Show>
273239
274240 <Suspense fallback={<PageSpinner />}>
275- <div class="grid gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
241+ <div class="grid gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 auto-rows-fr">
276242 <For each={cards()}>{(card) => <PortalCard card={card} />}</For>
277243 </div>
278244
279- <div class="grid gap-4 lg:grid-cols-2">
245+ <div class="grid gap-4 lg:grid-cols-2 auto-rows-fr">
280246 <UpcomingTimeline timeline={timeline()} locale={locale()} t={t} />
281247 <ActivityChart
282248 label={t("dashboard.activityGraph")}
@@ -291,8 +257,7 @@ function DashboardContent() {
291257
292258 function PortalCard(props: { card: PortalCard }) {
293259 const t = useT();
294- const { icon, titleKey, to, descKey, stat, statSuffix, accent, minRole } = props.card;
295- const statValue = stat();
260+ const { icon, titleKey, to, descKey, stat: statValue, statSuffix, accent, minRole } = props.card;
296261
297262 const iconAccentMap: Record<string, string> = {
298263 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 }) {
314279 <Link
315280 to={to}
316281 class={cn(
317- "group relative overflow-hidden rounded-xl border border-border/60 bg-card p-5 shadow-xs transition-all duration-200 hover:-translate-y-0.5 hover:shadow-md",
282+ "group relative flex flex-col overflow-hidden rounded-xl border border-border/60 bg-card p-5 shadow-xs transition-all duration-200 hover:-translate-y-0.5 hover:shadow-md",
318283 )}
319284 >
320285 <div
@@ -344,7 +309,7 @@ function PortalCard(props: { card: PortalCard }) {
344309 <path d="M5 12l4-4-4-4" />
345310 </svg>
346311 </div>
347- <div class="mt-4 space-y-1">
312+ <div class="mt-4 flex flex-1 flex-col">
348313 <div class="flex items-center gap-2">
349314 <h3 class="font-display text-sm font-semibold">{t(titleKey)}</h3>
350315 <Show when={minRole && minRole !== "student"}>
@@ -358,15 +323,13 @@ function PortalCard(props: { card: PortalCard }) {
358323 </span>
359324 </Show>
360325 </div>
361- <Show when={statValue !== ""}>
362- <p class="flex items-baseline gap-1 font-display text-2xl font-bold tracking-tight">
363- <span>{statValue}</span>
364- <Show when={statSuffix}>
365- {(suffix) => <span class="text-xs font-medium text-muted-foreground">{t(suffix())}</span>}
366- </Show>
367- </p>
368- </Show>
369- <p class="text-xs leading-relaxed text-muted-foreground">{t(descKey)}</p>
326+ <div class="flex min-h-[2rem] items-baseline gap-1 font-display text-2xl font-bold tracking-tight">
327+ <span class={cn(statValue === "" && "invisible")}>{statValue || "—"}</span>
328+ <Show when={statSuffix}>
329+ {(suffix) => <span class="text-xs font-medium text-muted-foreground">{t(suffix())}</span>}
330+ </Show>
331+ </div>
332+ <p class="mt-auto text-xs leading-relaxed text-muted-foreground">{t(descKey)}</p>
370333 </div>
371334 </Link>
372335 );
@@ -378,7 +341,7 @@ function UpcomingTimeline(props: {
378341 t: (key: MessageKey, params?: Record<string, string | number>) => string;
379342 }) {
380343 return (
381- <div class="rounded-xl border border-border/60 bg-card p-5 shadow-xs">
344+ <div class="flex flex-col rounded-xl border border-border/60 bg-card p-5 shadow-xs">
382345 <div class="mb-4 flex items-center gap-2">
383346 <IconCalendar class="h-4 w-4 text-muted-foreground" />
384347 <h2 class="font-display text-sm font-semibold">{props.t("dashboard.upcoming")}</h2>
@@ -431,7 +394,7 @@ function ActivityChart(props: {
431394 maxValue: number;
432395 }) {
433396 return (
434- <div class="rounded-xl border border-border/60 bg-card p-5 shadow-xs">
397+ <div class="flex flex-col rounded-xl border border-border/60 bg-card p-5 shadow-xs">
435398 <div class="mb-4 flex items-center gap-2">
436399 <IconChart class="h-4 w-4 text-muted-foreground" />
437400 <h2 class="font-display text-sm font-semibold">{props.label}</h2>