forge
Explore
Log in

Don't you dare go Hollow

♻️ extract role-based quick actions into RoleHomePanel component

Browse files at this commit

9f03be43216991a1dff9130cc3bbbdac4c9c2c6fBurak BoduroğluParent: 8d5749e
  • refactor
    • ♻️ extract role-based quick actions into RoleHomePanel component
Show full message
refactor: ♻️ extract role-based quick actions into RoleHomePanel component
src/components/dashboard/role-home-panel.tsxadded+93 -0
@@ -0,0 +1,93 @@
1+import { Link } from "@tanstack/solid-router";
2+import { For } from "solid-js";
3+import type { Role } from "@/api/types";
4+import type { MessageKey } from "@/i18n/messages";
5+import { useT } from "@/stores/preferences-context";
6+import { cn } from "@/lib/cn";
7+
8+type RoleAction = {
9+ to: string;
10+ title: MessageKey;
11+ hint: MessageKey;
12+ marker: string;
13+ tone: "mint" | "sky" | "amber" | "violet" | "rose";
14+};
15+
16+const ROLE_KEY: Record<Role, MessageKey> = {
17+ student: "role.student",
18+ teacher: "role.teacher",
19+ manager: "role.manager",
20+ admin: "role.admin",
21+};
22+
23+const ROLE_ACTIONS: Record<Role, RoleAction[]> = {
24+ student: [
25+ { to: "/marks", title: "dashboard.action.marks", hint: "dashboard.action.marksHint", marker: "▤", tone: "mint" },
26+ { to: "/exams", title: "dashboard.myExams", hint: "exams.subtitle", marker: "☰", tone: "rose" },
27+ { to: "/events", title: "dashboard.action.attend", hint: "dashboard.action.attendHint", marker: "◷", tone: "sky" },
28+ ],
29+ teacher: [
30+ { to: "/courses", title: "dashboard.action.course", hint: "dashboard.action.courseHint", marker: "▣", tone: "violet" },
31+ { to: "/courses", title: "dashboard.action.exam", hint: "dashboard.action.examHint", marker: "☰", tone: "rose" },
32+ { to: "/exams", title: "exams.liveMonitor", hint: "exams.liveMonitorDesc", marker: "◎", tone: "amber" },
33+ ],
34+ manager: [
35+ { to: "/courses", title: "nav.courses", hint: "courses.subtitle", marker: "▣", tone: "violet" },
36+ { to: "/events", title: "nav.events", hint: "events.subtitle", marker: "◷", tone: "sky" },
37+ { to: "/exams", title: "exams.liveMonitor", hint: "exams.liveMonitorDesc", marker: "◎", tone: "amber" },
38+ ],
39+ admin: [
40+ { to: "/admin/users", title: "nav.users", hint: "admin.subtitle", marker: "◉", tone: "amber" },
41+ { to: "/courses", title: "nav.courses", hint: "courses.subtitle", marker: "▣", tone: "violet" },
42+ { to: "/events", title: "nav.events", hint: "events.subtitle", marker: "◷", tone: "sky" },
43+ ],
44+};
45+
46+export function RoleHomePanel(props: { role: Role }) {
47+ const t = useT();
48+ const actions = () => ROLE_ACTIONS[props.role];
49+ const markerTone = {
50+ mint: "bg-emerald-500/10 text-emerald-700 dark:text-emerald-300",
51+ sky: "bg-sky-500/10 text-sky-700 dark:text-sky-300",
52+ amber: "bg-amber-500/10 text-amber-700 dark:text-amber-300",
53+ violet: "bg-violet-500/10 text-violet-700 dark:text-violet-300",
54+ rose: "bg-rose-500/10 text-rose-700 dark:text-rose-300",
55+ };
56+
57+ return (
58+ <section class="surface-card relative overflow-hidden p-4 sm:p-5">
59+ <div class="pointer-events-none absolute inset-x-0 top-0 h-px bg-gradient-to-r from-transparent via-primary/30 to-transparent" />
60+ <div class="mb-4">
61+ <div>
62+ <p class="text-xs font-semibold uppercase tracking-[0.18em] text-muted-foreground">
63+ {t("dashboard.overview")}
64+ </p>
65+ <h2 class="mt-1 font-display text-lg font-semibold">
66+ {t("dashboard.stats.role")}: {t(ROLE_KEY[props.role])}
67+ </h2>
68+ </div>
69+ </div>
70+
71+ <div class="grid gap-3 md:grid-cols-3">
72+ <For each={actions()}>
73+ {(action) => (
74+ <Link
75+ to={action.to}
76+ class="group flex min-h-24 items-center gap-3 rounded-lg border border-border/80 bg-gradient-to-br from-card to-muted/20 px-4 py-3 shadow-sm transition-all hover:-translate-y-0.5 hover:border-primary/30 hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
77+ >
78+ <span class={cn("flex h-11 w-11 shrink-0 items-center justify-center rounded-lg text-lg", markerTone[action.tone])}>
79+ {action.marker}
80+ </span>
81+ <span class="min-w-0">
82+ <span class="block truncate text-sm font-semibold group-hover:text-primary">{t(action.title)}</span>
83+ <span class="mt-0.5 block line-clamp-2 text-xs leading-relaxed text-muted-foreground">
84+ {t(action.hint)}
85+ </span>
86+ </span>
87+ </Link>
88+ )}
89+ </For>
90+ </div>
91+ </section>
92+ );
93+}
src/pages/dashboard-page.tsxmodified+2 -120
@@ -7,6 +7,7 @@ import { getNotes } from "@/api/getNotes";
7 import type { Event, Exam, Note } from "@/api/types";7 import type { Event, Exam, Note } from "@/api/types";
8 import { RouteGuard } from "@/components/layout/route-guard";8 import { RouteGuard } from "@/components/layout/route-guard";
9 import { PageHeader } from "@/components/layout/page-header";9 import { PageHeader } from "@/components/layout/page-header";
10+import { RoleHomePanel } from "@/components/dashboard/role-home-panel";
10 import { Badge } from "@/components/ui/badge";11 import { Badge } from "@/components/ui/badge";
11 import { Button } from "@/components/ui/button";12 import { Button } from "@/components/ui/button";
12 import {13 import {
@@ -21,7 +22,6 @@ import { PageSpinner } from "@/components/ui/page-spinner";
21 import { useAuth } from "@/stores/auth-context";22 import { useAuth } from "@/stores/auth-context";
22 import { usePreferences, useT } from "@/stores/preferences-context";23 import { usePreferences, useT } from "@/stores/preferences-context";
23 import { examKindLabel } from "@/lib/exam-labels";24 import { examKindLabel } from "@/lib/exam-labels";
24-import { hasMinRole } from "@/lib/roles";
25 import { formatDateTime } from "@/lib/format";25 import { formatDateTime } from "@/lib/format";
26 import { cn } from "@/lib/cn";26 import { cn } from "@/lib/cn";
27 27
@@ -75,78 +75,7 @@ function DashboardContent() {
75 }75 }
76 />76 />
77 77
78- {/* Action CTAs — not sidebar mirrors; 4 verb-style shortcuts */}78+ <RoleHomePanel role={user().role} />
79- <section>
80- <h2 class="mb-2.5 text-xs font-semibold uppercase tracking-wider text-muted-foreground">
81- {t("dashboard.quickActions")}
82- </h2>
83- <div class="grid gap-3 sm:grid-cols-2 xl:grid-cols-4">
84- <Show
85- when={hasMinRole(user().role, "teacher")}
86- fallback={
87- <>
88- <ActionCard
89- to="/notes"
90- title={t("dashboard.action.note")}
91- hint={t("dashboard.action.noteHint")}
92- icon="✎"
93- tone="amber"
94- />
95- <ActionCard
96- to="/events"
97- title={t("dashboard.action.attend")}
98- hint={t("dashboard.action.attendHint")}
99- icon="◷"
100- tone="sky"
101- />
102- <ActionCard
103- to="/courses"
104- title={t("nav.courses")}
105- hint={t("courses.subtitle")}
106- icon="▣"
107- tone="violet"
108- />
109- <ActionCard
110- to="/marks"
111- title={t("dashboard.action.marks")}
112- hint={t("dashboard.action.marksHint")}
113- icon="▤"
114- tone="mint"
115- />
116- </>
117- }
118- >
119- <ActionCard
120- to="/notes"
121- title={t("dashboard.action.note")}
122- hint={t("dashboard.action.noteHint")}
123- icon="✎"
124- tone="amber"
125- />
126- <ActionCard
127- to="/events"
128- title={t("dashboard.action.event")}
129- hint={t("dashboard.action.eventHint")}
130- icon="◷"
131- tone="sky"
132- />
133- <ActionCard
134- to="/courses"
135- title={t("dashboard.action.course")}
136- hint={t("dashboard.action.courseHint")}
137- icon="▣"
138- tone="violet"
139- />
140- <ActionCard
141- to="/courses"
142- title={t("dashboard.action.exam")}
143- hint={t("dashboard.action.examHint")}
144- icon="☰"
145- tone="rose"
146- />
147- </Show>
148- </div>
149- </section>
150 79
151 {/* KPIs below actions */}80 {/* KPIs below actions */}
152 <Suspense fallback={<PageSpinner />}>81 <Suspense fallback={<PageSpinner />}>
@@ -428,53 +357,6 @@ function StatTile(props: {
428 return inner;357 return inner;
429 }358 }
430 359
431-function ActionCard(props: {
432- to: string;
433- title: string;
434- hint: string;
435- icon: string;
436- tone: "mint" | "sky" | "amber" | "violet" | "rose";
437-}) {
438- const ring = {
439- mint: "hover:border-emerald-500/40",
440- sky: "hover:border-sky-500/40",
441- amber: "hover:border-amber-500/40",
442- violet: "hover:border-violet-500/40",
443- rose: "hover:border-rose-500/40",
444- };
445- const iconBg = {
446- mint: "bg-emerald-500/10 text-emerald-700 dark:text-emerald-300",
447- sky: "bg-sky-500/10 text-sky-700 dark:text-sky-300",
448- amber: "bg-amber-500/10 text-amber-700 dark:text-amber-300",
449- violet: "bg-violet-500/10 text-violet-700 dark:text-violet-300",
450- rose: "bg-rose-500/10 text-rose-700 dark:text-rose-300",
451- };
452-
453- return (
454- <Link
455- to={props.to}
456- class={cn(
457- "flex items-center gap-3 rounded-md border border-border bg-card px-3.5 py-3 shadow-sm transition-all",
458- "hover:-translate-y-0.5 hover:shadow-md",
459- ring[props.tone],
460- )}
461- >
462- <span
463- class={cn(
464- "flex h-10 w-10 shrink-0 items-center justify-center rounded-md text-base",
465- iconBg[props.tone],
466- )}
467- >
468- {props.icon}
469- </span>
470- <span class="min-w-0">
471- <span class="block truncate text-sm font-semibold">{props.title}</span>
472- <span class="block truncate text-xs text-muted-foreground">{props.hint}</span>
473- </span>
474- </Link>
475- );
476-}
477-
478 function EmptyPanel(props: {360 function EmptyPanel(props: {
479 icon: any;361 icon: any;
480 title: string;362 title: string;