Restrict admin panel access to three staff team roles.
Content managers see content routes only; Super Admin alone can send team invites. Align team role pickers and analytics layout with staff role model. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
13217ae6b5
commit
cd490c3dd9
|
|
@ -1,4 +1,6 @@
|
||||||
import { Navigate, Route, Routes } from "react-router-dom";
|
import { Navigate, Route, Routes } from "react-router-dom";
|
||||||
|
import { getDefaultAppHome } from "../lib/adminAccess";
|
||||||
|
import { getNormalizedSessionTeamRole } from "../lib/teamRole";
|
||||||
import { AppLayout } from "../layouts/AppLayout";
|
import { AppLayout } from "../layouts/AppLayout";
|
||||||
import { DashboardPage } from "../pages/DashboardPage";
|
import { DashboardPage } from "../pages/DashboardPage";
|
||||||
import { AnalyticsPage } from "../pages/analytics/AnalyticsPage";
|
import { AnalyticsPage } from "../pages/analytics/AnalyticsPage";
|
||||||
|
|
@ -91,7 +93,7 @@ export function AppRoutes() {
|
||||||
<Route path="/privacy" element={<PrivacyPage />} />
|
<Route path="/privacy" element={<PrivacyPage />} />
|
||||||
<Route path="/account-deletion" element={<AccountDeletionPage />} />
|
<Route path="/account-deletion" element={<AccountDeletionPage />} />
|
||||||
<Route element={<AppLayout />}>
|
<Route element={<AppLayout />}>
|
||||||
<Route path="/" element={<Navigate to="/dashboard" replace />} />
|
<Route path="/" element={<Navigate to={getDefaultAppHome(getNormalizedSessionTeamRole())} replace />} />
|
||||||
<Route path="/dashboard" element={<DashboardPage />} />
|
<Route path="/dashboard" element={<DashboardPage />} />
|
||||||
<Route path="/users" element={<UserManagementLayout />}>
|
<Route path="/users" element={<UserManagementLayout />}>
|
||||||
<Route index element={<Navigate to="list" replace />} />
|
<Route index element={<Navigate to="list" replace />} />
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,10 @@ import { hasPersonaPermission } from "../../lib/personasPermissions";
|
||||||
import { hasActivityLogPermission } from "../../lib/activityLogPermissions";
|
import { hasActivityLogPermission } from "../../lib/activityLogPermissions";
|
||||||
import { hasExportPermission } from "../../lib/exportPermissions";
|
import { hasExportPermission } from "../../lib/exportPermissions";
|
||||||
import { SidebarNavGroup } from "./SidebarNavGroup";
|
import { SidebarNavGroup } from "./SidebarNavGroup";
|
||||||
|
import {
|
||||||
|
getNormalizedSessionTeamRole,
|
||||||
|
} from "../../lib/teamRole";
|
||||||
|
import { isNavEntryAllowedForTeamRole } from "../../lib/adminAccess";
|
||||||
|
|
||||||
type NavLinkItem = {
|
type NavLinkItem = {
|
||||||
kind: "link";
|
kind: "link";
|
||||||
|
|
@ -164,6 +168,7 @@ export function Sidebar({
|
||||||
loading: permissionsLoading,
|
loading: permissionsLoading,
|
||||||
} = useTeamPermissions();
|
} = useTeamPermissions();
|
||||||
const [unreadCount, setUnreadCount] = useState(0);
|
const [unreadCount, setUnreadCount] = useState(0);
|
||||||
|
const sessionTeamRole = getNormalizedSessionTeamRole();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchUnread = async () => {
|
const fetchUnread = async () => {
|
||||||
|
|
@ -251,6 +256,27 @@ export function Sidebar({
|
||||||
|
|
||||||
<nav className="mt-6 flex-1 space-y-0.5 overflow-y-auto scrollbar-none">
|
<nav className="mt-6 flex-1 space-y-0.5 overflow-y-auto scrollbar-none">
|
||||||
{navEntries.map((entry, index) => {
|
{navEntries.map((entry, index) => {
|
||||||
|
if (
|
||||||
|
!isNavEntryAllowedForTeamRole(
|
||||||
|
entry.kind === "section"
|
||||||
|
? { kind: "section", label: entry.label }
|
||||||
|
: entry.kind === "group"
|
||||||
|
? {
|
||||||
|
kind: "group",
|
||||||
|
label: entry.label,
|
||||||
|
basePath: entry.basePath,
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
kind: "link",
|
||||||
|
label: entry.label,
|
||||||
|
to: entry.to,
|
||||||
|
},
|
||||||
|
sessionTeamRole,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (entry.kind === "section") {
|
if (entry.kind === "section") {
|
||||||
if (isCollapsed) {
|
if (isCollapsed) {
|
||||||
return index > 0 ? (
|
return index > 0 ? (
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,11 @@ import { Navigate, Outlet, useLocation } from "react-router-dom"
|
||||||
import { Sidebar } from "../components/sidebar/Sidebar"
|
import { Sidebar } from "../components/sidebar/Sidebar"
|
||||||
import { Topbar } from "../components/topbar/Topbar"
|
import { Topbar } from "../components/topbar/Topbar"
|
||||||
import { getAccessToken } from "../lib/teamAuthStorage"
|
import { getAccessToken } from "../lib/teamAuthStorage"
|
||||||
|
import {
|
||||||
|
getDefaultAppHome,
|
||||||
|
isPathAllowedForTeamRole,
|
||||||
|
} from "../lib/adminAccess"
|
||||||
|
import { getNormalizedSessionTeamRole } from "../lib/teamRole"
|
||||||
import {
|
import {
|
||||||
connectNotificationsWebSocket,
|
connectNotificationsWebSocket,
|
||||||
disconnectNotificationsWebSocket,
|
disconnectNotificationsWebSocket,
|
||||||
|
|
@ -70,6 +75,11 @@ export function AppLayout() {
|
||||||
return <Navigate to="/login" replace />
|
return <Navigate to="/login" replace />
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const teamRole = getNormalizedSessionTeamRole()
|
||||||
|
if (!isPathAllowedForTeamRole(location.pathname, teamRole)) {
|
||||||
|
return <Navigate to={getDefaultAppHome(teamRole)} replace />
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-dvh overflow-hidden bg-grayScale-100">
|
<div className="flex h-dvh overflow-hidden bg-grayScale-100">
|
||||||
<Sidebar
|
<Sidebar
|
||||||
|
|
|
||||||
78
src/lib/adminAccess.ts
Normal file
78
src/lib/adminAccess.ts
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
import { getNormalizedSessionTeamRole } from "./teamRole"
|
||||||
|
|
||||||
|
export const FULL_PANEL_TEAM_ROLES = new Set(["SUPER_ADMIN", "ADMIN"])
|
||||||
|
|
||||||
|
/** The three assignable staff roles for the admin panel. */
|
||||||
|
export const STAFF_TEAM_ROLE_OPTIONS = [
|
||||||
|
{ value: "SUPER_ADMIN", label: "Super Admin" },
|
||||||
|
{ value: "ADMIN", label: "Admin" },
|
||||||
|
{ value: "CONTENT_MANAGER", label: "Content Manager" },
|
||||||
|
] as const
|
||||||
|
|
||||||
|
const CONTENT_MANAGER_PATH_PREFIXES = [
|
||||||
|
"/new-content",
|
||||||
|
"/personas",
|
||||||
|
"/profile",
|
||||||
|
"/content",
|
||||||
|
]
|
||||||
|
|
||||||
|
export function hasFullAdminPanelAccess(role?: string): boolean {
|
||||||
|
const r = (role ?? getNormalizedSessionTeamRole()).toUpperCase()
|
||||||
|
return FULL_PANEL_TEAM_ROLES.has(r)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isContentManagerRole(role?: string): boolean {
|
||||||
|
const r = (role ?? getNormalizedSessionTeamRole()).toUpperCase()
|
||||||
|
return r === "CONTENT_MANAGER"
|
||||||
|
}
|
||||||
|
|
||||||
|
export function canSendTeamInvitations(role?: string): boolean {
|
||||||
|
const r = (role ?? getNormalizedSessionTeamRole()).toUpperCase()
|
||||||
|
return r === "SUPER_ADMIN"
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isPathAllowedForTeamRole(pathname: string, role?: string): boolean {
|
||||||
|
const r = (role ?? getNormalizedSessionTeamRole()).toUpperCase()
|
||||||
|
if (!r || hasFullAdminPanelAccess(r)) return true
|
||||||
|
if (isContentManagerRole(r)) {
|
||||||
|
return CONTENT_MANAGER_PATH_PREFIXES.some(
|
||||||
|
(p) => pathname === p || pathname.startsWith(`${p}/`),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return pathname === "/profile" || pathname.startsWith("/profile/")
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getDefaultAppHome(role?: string): string {
|
||||||
|
if (isContentManagerRole(role)) return "/new-content"
|
||||||
|
return "/dashboard"
|
||||||
|
}
|
||||||
|
|
||||||
|
export type NavEntryKind = "section" | "link" | "group"
|
||||||
|
|
||||||
|
export type FilterableNavEntry = {
|
||||||
|
kind: NavEntryKind
|
||||||
|
label: string
|
||||||
|
to?: string
|
||||||
|
basePath?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sidebar entries visible to content managers (learning content + profile). */
|
||||||
|
export function isNavEntryAllowedForTeamRole(
|
||||||
|
entry: FilterableNavEntry,
|
||||||
|
role?: string,
|
||||||
|
): boolean {
|
||||||
|
const r = (role ?? getNormalizedSessionTeamRole()).toUpperCase()
|
||||||
|
if (!r || hasFullAdminPanelAccess(r)) return true
|
||||||
|
if (!isContentManagerRole(r)) return false
|
||||||
|
|
||||||
|
if (entry.kind === "section") {
|
||||||
|
return entry.label === "Learning content" || entry.label === "Account"
|
||||||
|
}
|
||||||
|
if (entry.kind === "group") {
|
||||||
|
return entry.basePath === "/new-content"
|
||||||
|
}
|
||||||
|
if (entry.kind === "link") {
|
||||||
|
return entry.to === "/personas" || entry.to === "/profile"
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
@ -2,10 +2,6 @@
|
||||||
const FAQ_BYPASS_TEAM_ROLES = new Set([
|
const FAQ_BYPASS_TEAM_ROLES = new Set([
|
||||||
"SUPER_ADMIN",
|
"SUPER_ADMIN",
|
||||||
"ADMIN",
|
"ADMIN",
|
||||||
"CONTENT_MANAGER",
|
|
||||||
"FINANCE",
|
|
||||||
"HR",
|
|
||||||
"ANALYST",
|
|
||||||
])
|
])
|
||||||
|
|
||||||
export function getSessionTeamRole(): string {
|
export function getSessionTeamRole(): string {
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,7 @@
|
||||||
import type { Role } from "../types/rbac.types"
|
import type { Role } from "../types/rbac.types"
|
||||||
|
import { STAFF_TEAM_ROLE_OPTIONS } from "./adminAccess"
|
||||||
|
|
||||||
export const TEAM_ROLE_OPTIONS = [
|
export const TEAM_ROLE_OPTIONS = [...STAFF_TEAM_ROLE_OPTIONS]
|
||||||
{ value: "SUPER_ADMIN", label: "Super Admin" },
|
|
||||||
{ value: "ADMIN", label: "Admin" },
|
|
||||||
{ value: "CONTENT_MANAGER", label: "Content Manager" },
|
|
||||||
{ value: "SUPPORT_AGENT", label: "Support Agent" },
|
|
||||||
{ value: "INSTRUCTOR", label: "Instructor" },
|
|
||||||
{ value: "FINANCE", label: "Finance" },
|
|
||||||
{ value: "HR", label: "HR" },
|
|
||||||
{ value: "ANALYST", label: "Analyst" },
|
|
||||||
] as const
|
|
||||||
|
|
||||||
export const EMPLOYMENT_TYPE_OPTIONS = [
|
export const EMPLOYMENT_TYPE_OPTIONS = [
|
||||||
{ value: "full_time", label: "Full-time" },
|
{ value: "full_time", label: "Full-time" },
|
||||||
|
|
@ -44,14 +36,12 @@ export function formatTeamRoleLabel(teamRole: string): string {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Role key/name sent to POST /team/members/invite.
|
* Role key/name sent to POST /team/members/invite.
|
||||||
* Must be a built-in team role (e.g. SUPER_ADMIN) or an exact RBAC role name/id —
|
* Must be one of SUPER_ADMIN, ADMIN, or CONTENT_MANAGER.
|
||||||
* never a UI display label like "Super Admin".
|
|
||||||
*/
|
*/
|
||||||
export function teamRoleNameForInvite(teamRole: string, explicitName?: string): string {
|
export function teamRoleNameForInvite(teamRole: string, explicitName?: string): string {
|
||||||
const raw = (teamRole || explicitName || "").trim()
|
const raw = (teamRole || explicitName || "").trim()
|
||||||
if (!raw) return ""
|
if (!raw) return ""
|
||||||
|
|
||||||
// Accidental display labels from built-in options → API keys
|
|
||||||
const byLabel = TEAM_ROLE_OPTIONS.find(
|
const byLabel = TEAM_ROLE_OPTIONS.find(
|
||||||
(o) => o.label.toLowerCase() === raw.toLowerCase(),
|
(o) => o.label.toLowerCase() === raw.toLowerCase(),
|
||||||
)
|
)
|
||||||
|
|
@ -62,19 +52,17 @@ export function teamRoleNameForInvite(teamRole: string, explicitName?: string):
|
||||||
)
|
)
|
||||||
if (byValue) return byValue.value
|
if (byValue) return byValue.value
|
||||||
|
|
||||||
// Custom RBAC roles: keep exact name (spaces allowed); numeric id strings pass through
|
return rbacRoleNameToTeamRole(raw)
|
||||||
return raw
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TeamRoleOption = { value: string; label: string }
|
export type TeamRoleOption = { value: string; label: string }
|
||||||
|
|
||||||
export function rbacRolesToTeamRoleOptions(roles: Role[]): TeamRoleOption[] {
|
export function staffTeamRoleOptions(): TeamRoleOption[] {
|
||||||
const names = Array.from(
|
return TEAM_ROLE_OPTIONS.map((opt) => ({ value: opt.value, label: opt.label }))
|
||||||
new Set(roles.map((role) => role.name.trim()).filter(Boolean)),
|
}
|
||||||
).sort((a, b) => a.localeCompare(b))
|
|
||||||
|
/** @deprecated Custom RBAC team roles are no longer supported; use staffTeamRoleOptions(). */
|
||||||
return names.map((name) => ({
|
export function rbacRolesToTeamRoleOptions(roles: Role[]): TeamRoleOption[] {
|
||||||
value: name,
|
void roles
|
||||||
label: formatTeamRoleLabel(name),
|
return staffTeamRoleOptions()
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ import {
|
||||||
TrendingDown,
|
TrendingDown,
|
||||||
CreditCard,
|
CreditCard,
|
||||||
Video,
|
Video,
|
||||||
Layers,
|
|
||||||
FolderOpen,
|
FolderOpen,
|
||||||
RefreshCw,
|
RefreshCw,
|
||||||
ChevronDown,
|
ChevronDown,
|
||||||
|
|
@ -625,8 +624,6 @@ export function AnalyticsPage() {
|
||||||
|
|
||||||
<div className="space-y-5">
|
<div className="space-y-5">
|
||||||
{activeSummaryTab === "key" && (
|
{activeSummaryTab === "key" && (
|
||||||
<>
|
|
||||||
{/* ─── Key Metrics ─── */}
|
|
||||||
<Section title="Key Metrics" icon={TrendingUp} defaultOpen>
|
<Section title="Key Metrics" icon={TrendingUp} defaultOpen>
|
||||||
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
|
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
|
||||||
<KpiCard
|
<KpiCard
|
||||||
|
|
@ -663,90 +660,10 @@ export function AnalyticsPage() {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Section>
|
</Section>
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{activeSummaryTab === "content" && (
|
|
||||||
<>
|
|
||||||
{/* ─── Content & Platform ─── */}
|
|
||||||
<Section
|
|
||||||
title="Content & Platform"
|
|
||||||
icon={BookOpen}
|
|
||||||
count={courses.total_videos + content.total_questions}
|
|
||||||
defaultOpen
|
|
||||||
>
|
|
||||||
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
|
|
||||||
<KpiCard
|
|
||||||
icon={FolderOpen}
|
|
||||||
label="Categories"
|
|
||||||
value={courses.total_categories.toLocaleString()}
|
|
||||||
sub={`${courses.total_courses} courses · ${courses.total_sub_courses} modules`}
|
|
||||||
trend="neutral"
|
|
||||||
/>
|
|
||||||
<KpiCard
|
|
||||||
icon={BookOpen}
|
|
||||||
label="LMS Programs"
|
|
||||||
value={(lms?.programs ?? 0).toLocaleString()}
|
|
||||||
sub={`${lms?.courses ?? 0} courses · ${lms?.practices ?? 0} practices`}
|
|
||||||
trend="neutral"
|
|
||||||
/>
|
|
||||||
<KpiCard
|
|
||||||
icon={Video}
|
|
||||||
label="Videos"
|
|
||||||
value={courses.total_videos.toLocaleString()}
|
|
||||||
sub={getVideoLessonsSummary(lms?.lessons_with_video, examPrep?.lessons_with_video)}
|
|
||||||
trend={courses.total_videos > 0 ? "up" : "neutral"}
|
|
||||||
/>
|
|
||||||
<KpiCard
|
|
||||||
icon={HelpCircle}
|
|
||||||
label="Questions"
|
|
||||||
value={content.total_questions.toLocaleString()}
|
|
||||||
sub={getPrimaryQuestionTypeSummary(content.questions_by_type)}
|
|
||||||
trend={content.total_questions > 0 ? "up" : "neutral"}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</Section>
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{activeSummaryTab === "operations" && (
|
{activeSummaryTab === "operations" && (
|
||||||
<>
|
<>
|
||||||
{/* ─── Operations ─── */}
|
|
||||||
<Section title="Operations" icon={Bell} defaultOpen>
|
|
||||||
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
|
|
||||||
<KpiCard
|
|
||||||
icon={Bell}
|
|
||||||
label="Notifications Sent"
|
|
||||||
value={formatNumber(notifications.total_sent)}
|
|
||||||
sub={`${notifications.read_count} read · ${notifications.unread_count} unread`}
|
|
||||||
trend={notifications.unread_count === 0 ? "up" : "neutral"}
|
|
||||||
/>
|
|
||||||
<KpiCard
|
|
||||||
icon={UsersRound}
|
|
||||||
label="Team Members"
|
|
||||||
value={team.total_members.toLocaleString()}
|
|
||||||
sub={`${team.by_role.length} roles`}
|
|
||||||
trend="neutral"
|
|
||||||
/>
|
|
||||||
<KpiCard
|
|
||||||
icon={CreditCard}
|
|
||||||
label="Payments"
|
|
||||||
value={payments.total_payments.toLocaleString()}
|
|
||||||
sub={`${payments.successful_payments} successful`}
|
|
||||||
trend={payments.successful_payments > 0 ? "up" : "neutral"}
|
|
||||||
/>
|
|
||||||
<KpiCard
|
|
||||||
icon={Layers}
|
|
||||||
label="Question Sets"
|
|
||||||
value={content.total_question_sets.toLocaleString()}
|
|
||||||
sub={content.question_sets_by_type.map((q) => `${q.count} ${q.label.toLowerCase()}`).join(" · ")}
|
|
||||||
trend="neutral"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</Section>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* ─── User Analytics ─── */}
|
{/* ─── User Analytics ─── */}
|
||||||
<Section title="User Analytics" icon={Users} count={users.total_users} defaultOpen>
|
<Section title="User Analytics" icon={Users} count={users.total_users} defaultOpen>
|
||||||
<Card className="shadow-none">
|
<Card className="shadow-none">
|
||||||
|
|
@ -1194,9 +1111,53 @@ export function AnalyticsPage() {
|
||||||
</div>
|
</div>
|
||||||
</Section>
|
</Section>
|
||||||
|
|
||||||
|
{/* ─── Team ─── */}
|
||||||
|
<Section title="Team" icon={UsersRound} count={team.total_members} defaultOpen={false}>
|
||||||
|
<div className="grid items-start gap-4 sm:grid-cols-2">
|
||||||
|
<BreakdownList title="Team by Role" data={team.by_role} total={team.total_members} />
|
||||||
|
<BreakdownList title="Team by Status" data={team.by_status} total={team.total_members} />
|
||||||
|
</div>
|
||||||
|
</Section>
|
||||||
|
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{activeSummaryTab === "content" && (
|
||||||
|
<>
|
||||||
|
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
|
||||||
|
<KpiCard
|
||||||
|
icon={FolderOpen}
|
||||||
|
label="Categories"
|
||||||
|
value={courses.total_categories.toLocaleString()}
|
||||||
|
sub={`${courses.total_courses} courses · ${courses.total_sub_courses} modules`}
|
||||||
|
trend="neutral"
|
||||||
|
/>
|
||||||
|
<KpiCard
|
||||||
|
icon={BookOpen}
|
||||||
|
label="LMS Programs"
|
||||||
|
value={(lms?.programs ?? 0).toLocaleString()}
|
||||||
|
sub={`${lms?.courses ?? 0} courses · ${lms?.practices ?? 0} practices`}
|
||||||
|
trend="neutral"
|
||||||
|
/>
|
||||||
|
<KpiCard
|
||||||
|
icon={Video}
|
||||||
|
label="Videos"
|
||||||
|
value={courses.total_videos.toLocaleString()}
|
||||||
|
sub={getVideoLessonsSummary(lms?.lessons_with_video, examPrep?.lessons_with_video)}
|
||||||
|
trend={courses.total_videos > 0 ? "up" : "neutral"}
|
||||||
|
/>
|
||||||
|
<KpiCard
|
||||||
|
icon={HelpCircle}
|
||||||
|
label="Questions"
|
||||||
|
value={content.total_questions.toLocaleString()}
|
||||||
|
sub={getPrimaryQuestionTypeSummary(content.questions_by_type)}
|
||||||
|
trend={content.total_questions > 0 ? "up" : "neutral"}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* ─── Course Management ─── */}
|
{/* ─── Course Management ─── */}
|
||||||
{(lms || examPrep) && (
|
{(lms || examPrep) && (
|
||||||
<Section title="Course Management" icon={BookOpen} count={courses.total_videos} defaultOpen={false}>
|
<Section title="Course Management" icon={BookOpen} count={courses.total_videos} defaultOpen>
|
||||||
<div className="grid items-start gap-4 lg:grid-cols-2">
|
<div className="grid items-start gap-4 lg:grid-cols-2">
|
||||||
{lms && (
|
{lms && (
|
||||||
<BreakdownList
|
<BreakdownList
|
||||||
|
|
@ -1241,7 +1202,7 @@ export function AnalyticsPage() {
|
||||||
|
|
||||||
{/* ─── Video Analytics ─── */}
|
{/* ─── Video Analytics ─── */}
|
||||||
{videos && (
|
{videos && (
|
||||||
<Section title="Video Analytics" icon={PlayCircle} count={videos.total_watch_sessions} defaultOpen>
|
<Section title="Video Analytics" icon={PlayCircle} count={videos.total_watch_sessions} defaultOpen={false}>
|
||||||
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
|
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
|
||||||
<KpiCard
|
<KpiCard
|
||||||
icon={PlayCircle}
|
icon={PlayCircle}
|
||||||
|
|
@ -1393,13 +1354,8 @@ export function AnalyticsPage() {
|
||||||
</Section>
|
</Section>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* ─── Team ─── */}
|
</>
|
||||||
<Section title="Team" icon={UsersRound} count={team.total_members} defaultOpen={false}>
|
)}
|
||||||
<div className="grid items-start gap-4 sm:grid-cols-2">
|
|
||||||
<BreakdownList title="Team by Role" data={team.by_role} total={team.total_members} />
|
|
||||||
<BreakdownList title="Team by Status" data={team.by_status} total={team.total_members} />
|
|
||||||
</div>
|
|
||||||
</Section>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</SensitiveRevealProvider>
|
</SensitiveRevealProvider>
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ import { login, loginWithGoogle } from "../../api/auth.api";
|
||||||
import type { LoginRequest } from "../../types/auth.types";
|
import type { LoginRequest } from "../../types/auth.types";
|
||||||
import type { LoginResult } from "../../api/auth.api";
|
import type { LoginResult } from "../../api/auth.api";
|
||||||
import { saveTeamSessionFromLoginResult, getAccessToken } from "../../lib/teamAuthStorage";
|
import { saveTeamSessionFromLoginResult, getAccessToken } from "../../lib/teamAuthStorage";
|
||||||
|
import { getDefaultAppHome } from "../../lib/adminAccess";
|
||||||
|
import { getNormalizedSessionTeamRole } from "../../lib/teamRole";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|
@ -111,7 +113,7 @@ export function LoginPage() {
|
||||||
toast.success("Welcome back!", {
|
toast.success("Welcome back!", {
|
||||||
description: "You have signed in successfully.",
|
description: "You have signed in successfully.",
|
||||||
});
|
});
|
||||||
navigate("/dashboard");
|
navigate(getDefaultAppHome(getNormalizedSessionTeamRole()));
|
||||||
},
|
},
|
||||||
[navigate]
|
[navigate]
|
||||||
);
|
);
|
||||||
|
|
@ -183,7 +185,7 @@ export function LoginPage() {
|
||||||
}, [googleReady, handleGoogleCallback]);
|
}, [googleReady, handleGoogleCallback]);
|
||||||
|
|
||||||
if (token) {
|
if (token) {
|
||||||
return <Navigate to="/dashboard" replace />;
|
return <Navigate to={getDefaultAppHome(getNormalizedSessionTeamRole())} replace />;
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
|
|
|
||||||
|
|
@ -43,9 +43,16 @@ import { DEFAULT_TABLE_PAGE_SIZE, TABLE_PAGE_SIZE_OPTIONS } from "../../lib/tabl
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
import { SpinnerIcon } from "../../components/ui/spinner-icon"
|
import { SpinnerIcon } from "../../components/ui/spinner-icon"
|
||||||
import { InviteTeamMemberDialog } from "./components/InviteTeamMemberDialog"
|
import { InviteTeamMemberDialog } from "./components/InviteTeamMemberDialog"
|
||||||
|
import { canSendTeamInvitations, STAFF_TEAM_ROLE_OPTIONS } from "../../lib/adminAccess"
|
||||||
|
import { getNormalizedSessionTeamRole } from "../../lib/teamRole"
|
||||||
|
|
||||||
export function RolesListPage() {
|
export function RolesListPage() {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
const showTeamInviteActions = canSendTeamInvitations(getNormalizedSessionTeamRole())
|
||||||
|
const staffRoleNames = useMemo(
|
||||||
|
() => new Set(STAFF_TEAM_ROLE_OPTIONS.map((o) => o.value)),
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
|
||||||
// List state
|
// List state
|
||||||
const [roles, setRoles] = useState<Role[]>([])
|
const [roles, setRoles] = useState<Role[]>([])
|
||||||
|
|
@ -466,6 +473,7 @@ export function RolesListPage() {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{showTeamInviteActions && staffRoleNames.has(role.name.toUpperCase()) ? (
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
|
|
@ -477,6 +485,7 @@ export function RolesListPage() {
|
||||||
<Mail className="h-3.5 w-3.5 shrink-0" />
|
<Mail className="h-3.5 w-3.5 shrink-0" />
|
||||||
Invite team members
|
Invite team members
|
||||||
</Button>
|
</Button>
|
||||||
|
) : null}
|
||||||
|
|
||||||
<div className="grid grid-cols-1 gap-2 sm:grid-cols-2">
|
<div className="grid grid-cols-1 gap-2 sm:grid-cols-2">
|
||||||
<Button
|
<Button
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { useEffect, useMemo, useState } from "react"
|
import { useEffect, useMemo, useState } from "react"
|
||||||
import { Mail, Shield } from "lucide-react"
|
import { Mail, Shield } from "lucide-react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
import { fetchAllRoles } from "../../../api/rbac.api"
|
|
||||||
import { fetchAllTeamMemberEmails, inviteTeamMember } from "../../../api/team.api"
|
import { fetchAllTeamMemberEmails, inviteTeamMember } from "../../../api/team.api"
|
||||||
import { Button } from "../../../components/ui/button"
|
import { Button } from "../../../components/ui/button"
|
||||||
import {
|
import {
|
||||||
|
|
@ -24,9 +23,8 @@ import {
|
||||||
} from "../../../lib/parseInviteEmails"
|
} from "../../../lib/parseInviteEmails"
|
||||||
import {
|
import {
|
||||||
formatTeamRoleLabel,
|
formatTeamRoleLabel,
|
||||||
rbacRolesToTeamRoleOptions,
|
staffTeamRoleOptions,
|
||||||
teamRoleNameForInvite,
|
teamRoleNameForInvite,
|
||||||
TEAM_ROLE_OPTIONS,
|
|
||||||
type TeamRoleOption,
|
type TeamRoleOption,
|
||||||
} from "../../../lib/teamRoles"
|
} from "../../../lib/teamRoles"
|
||||||
|
|
||||||
|
|
@ -52,8 +50,6 @@ export function InviteTeamMemberDialog({
|
||||||
|
|
||||||
const [emailsText, setEmailsText] = useState("")
|
const [emailsText, setEmailsText] = useState("")
|
||||||
const [teamRole, setTeamRole] = useState(lockedRole)
|
const [teamRole, setTeamRole] = useState(lockedRole)
|
||||||
const [loadedRoleOptions, setLoadedRoleOptions] = useState<TeamRoleOption[]>([])
|
|
||||||
const [rolesLoading, setRolesLoading] = useState(false)
|
|
||||||
const [existingEmails, setExistingEmails] = useState<Set<string>>(new Set())
|
const [existingEmails, setExistingEmails] = useState<Set<string>>(new Set())
|
||||||
const [existingEmailsLoading, setExistingEmailsLoading] = useState(false)
|
const [existingEmailsLoading, setExistingEmailsLoading] = useState(false)
|
||||||
const [existingEmailsError, setExistingEmailsError] = useState(false)
|
const [existingEmailsError, setExistingEmailsError] = useState(false)
|
||||||
|
|
@ -77,38 +73,9 @@ export function InviteTeamMemberDialog({
|
||||||
)
|
)
|
||||||
const hasEmailConflicts = alreadyRegisteredEmails.length > 0
|
const hasEmailConflicts = alreadyRegisteredEmails.length > 0
|
||||||
|
|
||||||
const fallbackRoleOptions = useMemo<TeamRoleOption[]>(
|
|
||||||
() => TEAM_ROLE_OPTIONS.map((opt) => ({ value: opt.value, label: opt.label })),
|
|
||||||
[],
|
|
||||||
)
|
|
||||||
|
|
||||||
const selectableRoleOptions = roleOptions?.length
|
const selectableRoleOptions = roleOptions?.length
|
||||||
? roleOptions
|
? roleOptions
|
||||||
: loadedRoleOptions.length
|
: staffTeamRoleOptions()
|
||||||
? loadedRoleOptions
|
|
||||||
: fallbackRoleOptions
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!open || roleLocked || roleOptions?.length) return
|
|
||||||
|
|
||||||
let cancelled = false
|
|
||||||
setRolesLoading(true)
|
|
||||||
void fetchAllRoles()
|
|
||||||
.then((roles) => {
|
|
||||||
if (cancelled) return
|
|
||||||
setLoadedRoleOptions(rbacRolesToTeamRoleOptions(roles))
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
if (!cancelled) setLoadedRoleOptions([])
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
if (!cancelled) setRolesLoading(false)
|
|
||||||
})
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
cancelled = true
|
|
||||||
}
|
|
||||||
}, [open, roleLocked, roleOptions])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!open) return
|
if (!open) return
|
||||||
|
|
@ -348,11 +315,9 @@ export function InviteTeamMemberDialog({
|
||||||
id="invite-role"
|
id="invite-role"
|
||||||
value={teamRole}
|
value={teamRole}
|
||||||
onChange={(e) => setTeamRole(e.target.value)}
|
onChange={(e) => setTeamRole(e.target.value)}
|
||||||
disabled={submitting || rolesLoading || selectableRoleOptions.length === 0}
|
disabled={submitting || selectableRoleOptions.length === 0}
|
||||||
>
|
>
|
||||||
{rolesLoading ? (
|
{selectableRoleOptions.length === 0 ? (
|
||||||
<option value="">Loading roles…</option>
|
|
||||||
) : selectableRoleOptions.length === 0 ? (
|
|
||||||
<option value="">No roles available</option>
|
<option value="">No roles available</option>
|
||||||
) : (
|
) : (
|
||||||
selectableRoleOptions.map((opt) => (
|
selectableRoleOptions.map((opt) => (
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,8 @@ import { InviteTeamMemberDialog } from "../role-management/components/InviteTeam
|
||||||
import { EXPORT_PERMISSIONS, EXPORT_ROUTES } from "../../lib/csv-export";
|
import { EXPORT_PERMISSIONS, EXPORT_ROUTES } from "../../lib/csv-export";
|
||||||
import { teamMemberExportQuery } from "../../lib/csvExportFilters";
|
import { teamMemberExportQuery } from "../../lib/csvExportFilters";
|
||||||
import { UnassignedLabel } from "../../lib/displayValue"
|
import { UnassignedLabel } from "../../lib/displayValue"
|
||||||
|
import { canSendTeamInvitations } from "../../lib/adminAccess";
|
||||||
|
import { getNormalizedSessionTeamRole } from "../../lib/teamRole";
|
||||||
|
|
||||||
function formatDate(dateStr: string): string {
|
function formatDate(dateStr: string): string {
|
||||||
return new Date(dateStr).toLocaleDateString("en-US", {
|
return new Date(dateStr).toLocaleDateString("en-US", {
|
||||||
|
|
@ -243,6 +245,8 @@ export function TeamManagementPage() {
|
||||||
[roleFilter, statusFilter, search],
|
[roleFilter, statusFilter, search],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const showInviteActions = canSendTeamInvitations(getNormalizedSessionTeamRole());
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
<div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
||||||
|
|
@ -260,6 +264,7 @@ export function TeamManagementPage() {
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
className="w-full sm:w-auto"
|
className="w-full sm:w-auto"
|
||||||
/>
|
/>
|
||||||
|
{showInviteActions ? (
|
||||||
<Button
|
<Button
|
||||||
className="bg-brand-600 hover:bg-brand-500 text-white w-full sm:w-auto"
|
className="bg-brand-600 hover:bg-brand-500 text-white w-full sm:w-auto"
|
||||||
onClick={() => setInviteOpen(true)}
|
onClick={() => setInviteOpen(true)}
|
||||||
|
|
@ -267,6 +272,7 @@ export function TeamManagementPage() {
|
||||||
<Plus className="h-4 w-4" />
|
<Plus className="h-4 w-4" />
|
||||||
Add Team Member
|
Add Team Member
|
||||||
</Button>
|
</Button>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -296,11 +302,6 @@ export function TeamManagementPage() {
|
||||||
<option value="super_admin">Super Admin</option>
|
<option value="super_admin">Super Admin</option>
|
||||||
<option value="admin">Admin</option>
|
<option value="admin">Admin</option>
|
||||||
<option value="content_manager">Content Manager</option>
|
<option value="content_manager">Content Manager</option>
|
||||||
<option value="instructor">Instructor</option>
|
|
||||||
<option value="support_agent">Support Agent</option>
|
|
||||||
<option value="finance">Finance</option>
|
|
||||||
<option value="hr">HR</option>
|
|
||||||
<option value="analyst">Analyst</option>
|
|
||||||
</select>
|
</select>
|
||||||
<ChevronDown className="absolute right-2 top-1/2 h-4 w-4 -translate-y-1/2 text-grayScale-400 pointer-events-none" />
|
<ChevronDown className="absolute right-2 top-1/2 h-4 w-4 -translate-y-1/2 text-grayScale-400 pointer-events-none" />
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -502,11 +503,13 @@ export function TeamManagementPage() {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Status Update Confirmation Modal */}
|
{/* Status Update Confirmation Modal */}
|
||||||
|
{showInviteActions ? (
|
||||||
<InviteTeamMemberDialog
|
<InviteTeamMemberDialog
|
||||||
open={inviteOpen}
|
open={inviteOpen}
|
||||||
onOpenChange={setInviteOpen}
|
onOpenChange={setInviteOpen}
|
||||||
onInvited={() => void fetchMembers()}
|
onInvited={() => void fetchMembers()}
|
||||||
/>
|
/>
|
||||||
|
) : null}
|
||||||
|
|
||||||
{confirmDialog && (
|
{confirmDialog && (
|
||||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm">
|
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user