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 {
40 titleKey: MessageKey;40 titleKey: MessageKey;
41 to: string;41 to: string;
42 descKey: MessageKey;42 descKey: MessageKey;
43- stat: () => string | number;43+ stat: string | number;
44 statSuffix?: MessageKey;44 statSuffix?: MessageKey;
45 accent: string;45 accent: string;
46 minRole?: Role;46 minRole?: Role;
@@ -140,7 +140,7 @@ function DashboardContent() {
140 const totalExamsCount = createMemo(() => (exams.loading ? null : visibleExams().length));140 const totalExamsCount = createMemo(() => (exams.loading ? null : visibleExams().length));
141 const totalEventsCount = createMemo(() => (events.loading ? null : events()?.length ?? 0));141 const totalEventsCount = createMemo(() => (events.loading ? null : events()?.length ?? 0));
142 const totalNotesCount = createMemo(() => (notes.loading ? null : notes()?.length ?? 0));142 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);
144 144
145 const overallAvg = createMemo(() => marks()?.overall_average ?? null);145 const overallAvg = createMemo(() => marks()?.overall_average ?? null);
146 146
@@ -171,88 +171,54 @@ function DashboardContent() {
171 Math.max(1, ...chartData().map((d) => d.value)),171 Math.max(1, ...chartData().map((d) => d.value)),
172 );172 );
173 173
174- const cards = createMemo(() => {174+ const cards = () => {
175 const roleVal = role();175 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()!);
176 const list: PortalCard[] = [];181 const list: PortalCard[] = [];
177 182
178 if (roleVal === "student") {183 if (roleVal === "student") {
179 list.push(184 list.push(
180- {185+ { icon: <IconSchool class="h-5 w-5" />, titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: cc, statSuffix: "dashboard.records", accent: "violet" },
181- icon: <IconSchool class="h-5 w-5" />,186+ { icon: <IconExam class="h-5 w-5" />, titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: ec, statSuffix: "dashboard.records", accent: "amber" },
182- titleKey: "nav.courses",187+ { icon: <IconCalendar class="h-5 w-5" />, titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: evc, statSuffix: "dashboard.records", accent: "sky" },
183- to: "/courses",188+ { icon: <IconReportAnalytics class="h-5 w-5" />, titleKey: "nav.marks", to: "/marks", descKey: "dashboard.portal.marksDesc", stat: avg, accent: "mint" },
184- descKey: "dashboard.portal.coursesDesc",189+ { icon: <IconNote class="h-5 w-5" />, titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: nc, statSuffix: "dashboard.records", accent: "rose" },
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- },
224 );190 );
225 }191 }
226 192
227 if (roleVal === "teacher") {193 if (roleVal === "teacher") {
228 list.push(194 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" },195+ { icon: <IconSchool class="h-5 w-5" />, titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: cc, 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" },196+ { icon: <IconExam class="h-5 w-5" />, titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: ec, 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" },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" },
232- { icon: <IconChart class="h-5 w-5" />, titleKey: "nav.studentMarks", to: "/management/student-marks", descKey: "dashboard.portal.studentMarksDesc", stat: () => "", accent: "mint", 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" },
233- { icon: <IconClipboardCheck class="h-5 w-5" />, titleKey: "nav.studentAttendance", to: "/management/student-attendance", descKey: "dashboard.portal.attendanceDesc", stat: () => "", accent: "rose", 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" },
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" },200+ { icon: <IconNote class="h-5 w-5" />, titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: nc, 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" },201+ { icon: <IconReportAnalytics class="h-5 w-5" />, titleKey: "nav.work", to: "/work", descKey: "dashboard.portal.workDesc", stat: "", accent: "amber", minRole: "teacher" },
236 );202 );
237 }203 }
238 204
239 if (hasMinRole(roleVal, "manager")) {205 if (hasMinRole(roleVal, "manager")) {
240 list.unshift(206 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" },207+ { icon: <IconSchool class="h-5 w-5" />, titleKey: "nav.courses", to: "/courses", descKey: "dashboard.portal.coursesDesc", stat: cc, 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" },208+ { icon: <IconExam class="h-5 w-5" />, titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: ec, 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" },209+ { icon: <IconCalendar class="h-5 w-5" />, titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: evc, 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" },210+ { 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" },211+ { icon: <IconBook class="h-5 w-5" />, titleKey: "nav.terms", to: "/management/terms", descKey: "dashboard.portal.termsDesc", stat: "", accent: "rose", minRole: "manager" },
246 );212 );
247 if (roleVal === "admin") {213 if (roleVal === "admin") {
248 list.push(214 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" },
250 );216 );
251 }217 }
252 }218 }
253 219
254 return list;220 return list;
255- });221+ };
256 222
257 return (223 return (
258 <div class="space-y-5">224 <div class="space-y-5">
@@ -272,11 +238,11 @@ function DashboardContent() {
272 </Show>238 </Show>
273 239
274 <Suspense fallback={<PageSpinner />}>240 <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">
276 <For each={cards()}>{(card) => <PortalCard card={card} />}</For>242 <For each={cards()}>{(card) => <PortalCard card={card} />}</For>
277 </div>243 </div>
278 244
279- <div class="grid gap-4 lg:grid-cols-2">245+ <div class="grid gap-4 lg:grid-cols-2 auto-rows-fr">
280 <UpcomingTimeline timeline={timeline()} locale={locale()} t={t} />246 <UpcomingTimeline timeline={timeline()} locale={locale()} t={t} />
281 <ActivityChart247 <ActivityChart
282 label={t("dashboard.activityGraph")}248 label={t("dashboard.activityGraph")}
@@ -291,8 +257,7 @@ function DashboardContent() {
291 257
292 function PortalCard(props: { card: PortalCard }) {258 function PortalCard(props: { card: PortalCard }) {
293 const t = useT();259 const t = useT();
294- const { icon, titleKey, to, descKey, stat, statSuffix, accent, minRole } = props.card;260+ const { icon, titleKey, to, descKey, stat: statValue, statSuffix, accent, minRole } = props.card;
295- const statValue = stat();
296 261
297 const iconAccentMap: Record<string, string> = {262 const iconAccentMap: Record<string, string> = {
298 violet: "border-violet-500/30 bg-violet-500/10 text-violet-700 dark:text-violet-300",263 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 }) {
314 <Link279 <Link
315 to={to}280 to={to}
316 class={cn(281 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",
318 )}283 )}
319 >284 >
320 <div285 <div
@@ -344,7 +309,7 @@ function PortalCard(props: { card: PortalCard }) {
344 <path d="M5 12l4-4-4-4" />309 <path d="M5 12l4-4-4-4" />
345 </svg>310 </svg>
346 </div>311 </div>
347- <div class="mt-4 space-y-1">312+ <div class="mt-4 flex flex-1 flex-col">
348 <div class="flex items-center gap-2">313 <div class="flex items-center gap-2">
349 <h3 class="font-display text-sm font-semibold">{t(titleKey)}</h3>314 <h3 class="font-display text-sm font-semibold">{t(titleKey)}</h3>
350 <Show when={minRole && minRole !== "student"}>315 <Show when={minRole && minRole !== "student"}>
@@ -358,15 +323,13 @@ function PortalCard(props: { card: PortalCard }) {
358 </span>323 </span>
359 </Show>324 </Show>
360 </div>325 </div>
361- <Show when={statValue !== ""}>326+ <div class="flex min-h-[2rem] items-baseline gap-1 font-display text-2xl font-bold tracking-tight">
362- <p class="flex items-baseline gap-1 font-display text-2xl font-bold tracking-tight">327+ <span class={cn(statValue === "" && "invisible")}>{statValue || "—"}</span>
363- <span>{statValue}</span>328+ <Show when={statSuffix}>
364- <Show when={statSuffix}>329+ {(suffix) => <span class="text-xs font-medium text-muted-foreground">{t(suffix())}</span>}
365- {(suffix) => <span class="text-xs font-medium text-muted-foreground">{t(suffix())}</span>}330+ </Show>
366- </Show>331+ </div>
367- </p>332+ <p class="mt-auto text-xs leading-relaxed text-muted-foreground">{t(descKey)}</p>
368- </Show>
369- <p class="text-xs leading-relaxed text-muted-foreground">{t(descKey)}</p>
370 </div>333 </div>
371 </Link>334 </Link>
372 );335 );
@@ -378,7 +341,7 @@ function UpcomingTimeline(props: {
378 t: (key: MessageKey, params?: Record<string, string | number>) => string;341 t: (key: MessageKey, params?: Record<string, string | number>) => string;
379 }) {342 }) {
380 return (343 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">
382 <div class="mb-4 flex items-center gap-2">345 <div class="mb-4 flex items-center gap-2">
383 <IconCalendar class="h-4 w-4 text-muted-foreground" />346 <IconCalendar class="h-4 w-4 text-muted-foreground" />
384 <h2 class="font-display text-sm font-semibold">{props.t("dashboard.upcoming")}</h2>347 <h2 class="font-display text-sm font-semibold">{props.t("dashboard.upcoming")}</h2>
@@ -431,7 +394,7 @@ function ActivityChart(props: {
431 maxValue: number;394 maxValue: number;
432 }) {395 }) {
433 return (396 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">
435 <div class="mb-4 flex items-center gap-2">398 <div class="mb-4 flex items-center gap-2">
436 <IconChart class="h-4 w-4 text-muted-foreground" />399 <IconChart class="h-4 w-4 text-muted-foreground" />
437 <h2 class="font-display text-sm font-semibold">{props.label}</h2>400 <h2 class="font-display text-sm font-semibold">{props.label}</h2>