From 9f03be43216991a1dff9130cc3bbbdac4c9c2c6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Sun, 12 Jul 2026 17:43:50 +0300 Subject: [PATCH] =?UTF-8?q?refactor:=20=E2=99=BB=EF=B8=8F=20extract=20role?= =?UTF-8?q?-based=20quick=20actions=20into=20RoleHomePanel=20component?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/dashboard/role-home-panel.tsx | 93 ++++++++++++++ src/pages/dashboard-page.tsx | 122 +------------------ 2 files changed, 95 insertions(+), 120 deletions(-) create mode 100644 src/components/dashboard/role-home-panel.tsx diff --git a/src/components/dashboard/role-home-panel.tsx b/src/components/dashboard/role-home-panel.tsx new file mode 100644 index 0000000..d30affd --- /dev/null +++ b/src/components/dashboard/role-home-panel.tsx @@ -0,0 +1,93 @@ +import { Link } from "@tanstack/solid-router"; +import { For } from "solid-js"; +import type { Role } from "@/api/types"; +import type { MessageKey } from "@/i18n/messages"; +import { useT } from "@/stores/preferences-context"; +import { cn } from "@/lib/cn"; + +type RoleAction = { + to: string; + title: MessageKey; + hint: MessageKey; + marker: string; + tone: "mint" | "sky" | "amber" | "violet" | "rose"; +}; + +const ROLE_KEY: Record = { + student: "role.student", + teacher: "role.teacher", + manager: "role.manager", + admin: "role.admin", +}; + +const ROLE_ACTIONS: Record = { + student: [ + { to: "/marks", title: "dashboard.action.marks", hint: "dashboard.action.marksHint", marker: "▤", tone: "mint" }, + { to: "/exams", title: "dashboard.myExams", hint: "exams.subtitle", marker: "☰", tone: "rose" }, + { to: "/events", title: "dashboard.action.attend", hint: "dashboard.action.attendHint", marker: "◷", tone: "sky" }, + ], + teacher: [ + { to: "/courses", title: "dashboard.action.course", hint: "dashboard.action.courseHint", marker: "▣", tone: "violet" }, + { to: "/courses", title: "dashboard.action.exam", hint: "dashboard.action.examHint", marker: "☰", tone: "rose" }, + { to: "/exams", title: "exams.liveMonitor", hint: "exams.liveMonitorDesc", marker: "◎", tone: "amber" }, + ], + manager: [ + { to: "/courses", title: "nav.courses", hint: "courses.subtitle", marker: "▣", tone: "violet" }, + { to: "/events", title: "nav.events", hint: "events.subtitle", marker: "◷", tone: "sky" }, + { to: "/exams", title: "exams.liveMonitor", hint: "exams.liveMonitorDesc", marker: "◎", tone: "amber" }, + ], + admin: [ + { to: "/admin/users", title: "nav.users", hint: "admin.subtitle", marker: "◉", tone: "amber" }, + { to: "/courses", title: "nav.courses", hint: "courses.subtitle", marker: "▣", tone: "violet" }, + { to: "/events", title: "nav.events", hint: "events.subtitle", marker: "◷", tone: "sky" }, + ], +}; + +export function RoleHomePanel(props: { role: Role }) { + const t = useT(); + const actions = () => ROLE_ACTIONS[props.role]; + const markerTone = { + mint: "bg-emerald-500/10 text-emerald-700 dark:text-emerald-300", + sky: "bg-sky-500/10 text-sky-700 dark:text-sky-300", + amber: "bg-amber-500/10 text-amber-700 dark:text-amber-300", + violet: "bg-violet-500/10 text-violet-700 dark:text-violet-300", + rose: "bg-rose-500/10 text-rose-700 dark:text-rose-300", + }; + + return ( +
+
+
+
+

+ {t("dashboard.overview")} +

+

+ {t("dashboard.stats.role")}: {t(ROLE_KEY[props.role])} +

+
+
+ +
+ + {(action) => ( + + + {action.marker} + + + {t(action.title)} + + {t(action.hint)} + + + + )} + +
+
+ ); +} diff --git a/src/pages/dashboard-page.tsx b/src/pages/dashboard-page.tsx index c2639b4..c704ed7 100644 --- a/src/pages/dashboard-page.tsx +++ b/src/pages/dashboard-page.tsx @@ -7,6 +7,7 @@ import { getNotes } from "@/api/getNotes"; import type { Event, Exam, Note } from "@/api/types"; import { RouteGuard } from "@/components/layout/route-guard"; import { PageHeader } from "@/components/layout/page-header"; +import { RoleHomePanel } from "@/components/dashboard/role-home-panel"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { @@ -21,7 +22,6 @@ import { PageSpinner } from "@/components/ui/page-spinner"; import { useAuth } from "@/stores/auth-context"; import { usePreferences, useT } from "@/stores/preferences-context"; import { examKindLabel } from "@/lib/exam-labels"; -import { hasMinRole } from "@/lib/roles"; import { formatDateTime } from "@/lib/format"; import { cn } from "@/lib/cn"; @@ -75,78 +75,7 @@ function DashboardContent() { } /> - {/* Action CTAs — not sidebar mirrors; 4 verb-style shortcuts */} -
-

- {t("dashboard.quickActions")} -

-
- - - - - - - } - > - - - - - -
-
+ {/* KPIs below actions */} }> @@ -428,53 +357,6 @@ function StatTile(props: { return inner; } -function ActionCard(props: { - to: string; - title: string; - hint: string; - icon: string; - tone: "mint" | "sky" | "amber" | "violet" | "rose"; -}) { - const ring = { - mint: "hover:border-emerald-500/40", - sky: "hover:border-sky-500/40", - amber: "hover:border-amber-500/40", - violet: "hover:border-violet-500/40", - rose: "hover:border-rose-500/40", - }; - const iconBg = { - mint: "bg-emerald-500/10 text-emerald-700 dark:text-emerald-300", - sky: "bg-sky-500/10 text-sky-700 dark:text-sky-300", - amber: "bg-amber-500/10 text-amber-700 dark:text-amber-300", - violet: "bg-violet-500/10 text-violet-700 dark:text-violet-300", - rose: "bg-rose-500/10 text-rose-700 dark:text-rose-300", - }; - - return ( - - - {props.icon} - - - {props.title} - {props.hint} - - - ); -} - function EmptyPanel(props: { icon: any; title: string;