diff --git a/src/api/analytics.api.ts b/src/api/analytics.api.ts index abdbbc8..2927e09 100644 --- a/src/api/analytics.api.ts +++ b/src/api/analytics.api.ts @@ -139,6 +139,7 @@ function normalizeDashboardUsers(raw: unknown, root?: Record): by_role: asLabelCounts(pickField(u, "by_role", "byRole", "ByRole")), by_status: asLabelCounts(pickField(u, "by_status", "byStatus", "ByStatus")), by_age_group: asLabelCounts(pickField(u, "by_age_group", "byAgeGroup", "ByAgeGroup")), + by_gender: asLabelCounts(pickField(u, "by_gender", "byGender", "ByGender")), by_education_level: asLabelCounts( pickField(u, ...EDUCATION_LEVEL_KEYS) ?? pickField(scope, ...EDUCATION_LEVEL_KEYS), ), diff --git a/src/app/AppRoutes.tsx b/src/app/AppRoutes.tsx index b87bccc..d8b9b6f 100644 --- a/src/app/AppRoutes.tsx +++ b/src/app/AppRoutes.tsx @@ -1,6 +1,7 @@ import { Navigate, Route, Routes } from "react-router-dom"; import { getDefaultAppHome } from "../lib/adminAccess"; import { getNormalizedSessionTeamRole } from "../lib/teamRole"; +import { FullPanelGuard } from "../components/access/AdminAccessGates"; import { AppLayout } from "../layouts/AppLayout"; import { DashboardPage } from "../pages/DashboardPage"; import { AnalyticsPage } from "../pages/analytics/AnalyticsPage"; @@ -94,6 +95,8 @@ export function AppRoutes() { } /> }> } /> + + }> } /> }> } /> @@ -107,6 +110,7 @@ export function AppRoutes() { } /> } /> + }> } /> @@ -323,7 +327,12 @@ export function AppRoutes() { element={} /> + } /> + } /> + } /> } /> + + }> } @@ -354,15 +363,13 @@ export function AppRoutes() { } /> } /> } /> - } /> - } /> } /> } /> } /> } /> - } /> } /> + } /> diff --git a/src/components/access/AdminAccessGates.tsx b/src/components/access/AdminAccessGates.tsx new file mode 100644 index 0000000..561954d --- /dev/null +++ b/src/components/access/AdminAccessGates.tsx @@ -0,0 +1,31 @@ +import type { ReactNode } from "react" +import { Navigate, Outlet } from "react-router-dom" +import { useAdminAccess } from "../../hooks/useAdminAccess" + +type GateProps = { + children: ReactNode + fallback?: ReactNode +} + +/** Renders children only for Admin and Super Admin (not Content Manager). */ +export function FullPanelOnly({ children, fallback = null }: GateProps) { + const { hasFullPanel } = useAdminAccess() + if (!hasFullPanel) return <>{fallback} + return <>{children} +} + +/** Renders children only for Super Admin (e.g. team email invites). */ +export function SuperAdminOnly({ children, fallback = null }: GateProps) { + const { canInviteTeam } = useAdminAccess() + if (!canInviteTeam) return <>{fallback} + return <>{children} +} + +/** Route layout: redirects Content Manager to their home route. */ +export function FullPanelGuard() { + const { hasFullPanel, defaultHome } = useAdminAccess() + if (!hasFullPanel) { + return + } + return +} diff --git a/src/components/sidebar/Sidebar.tsx b/src/components/sidebar/Sidebar.tsx index 2d8d62f..ba8001d 100644 --- a/src/components/sidebar/Sidebar.tsx +++ b/src/components/sidebar/Sidebar.tsx @@ -28,9 +28,7 @@ import { hasPersonaPermission } from "../../lib/personasPermissions"; import { hasActivityLogPermission } from "../../lib/activityLogPermissions"; import { hasExportPermission } from "../../lib/exportPermissions"; import { SidebarNavGroup } from "./SidebarNavGroup"; -import { - getNormalizedSessionTeamRole, -} from "../../lib/teamRole"; +import { useAdminAccess } from "../../hooks/useAdminAccess"; import { isNavEntryAllowedForTeamRole } from "../../lib/adminAccess"; type NavLinkItem = { @@ -168,7 +166,7 @@ export function Sidebar({ loading: permissionsLoading, } = useTeamPermissions(); const [unreadCount, setUnreadCount] = useState(0); - const sessionTeamRole = getNormalizedSessionTeamRole(); + const { teamRole: sessionTeamRole } = useAdminAccess(); useEffect(() => { const fetchUnread = async () => { @@ -352,6 +350,15 @@ export function Sidebar({ if (entry.kind === "group") { const isNotifications = entry.basePath === "/notifications"; + const visibleChildren = entry.children.filter((child) => + isNavEntryAllowedForTeamRole( + { kind: "link", label: child.label, to: child.to }, + sessionTeamRole, + ), + ); + if (visibleChildren.length === 0) { + return null; + } return ( void @@ -57,10 +58,8 @@ export function Topbar({ onSidebarToggle }: TopbarProps) {
- {/* Notifications */} - {/* Separator */}
{/* Avatar + Radix Dropdown */} @@ -92,6 +91,7 @@ export function Topbar({ onSidebarToggle }: TopbarProps) { Profile + Settings + ({ + teamRole, + isContentManager: isContentManagerPanelRole(teamRole), + hasFullPanel: hasFullAdminPanelAccess(teamRole), + canInviteTeam: canSendTeamInvitations(teamRole), + defaultHome: getDefaultAppHome(teamRole), + isPathAllowed: (pathname: string) => + isPathAllowedForTeamRole(pathname, teamRole), + }), + [teamRole], + ) +} diff --git a/src/lib/adminAccess.ts b/src/lib/adminAccess.ts index 7d08acd..638b148 100644 --- a/src/lib/adminAccess.ts +++ b/src/lib/adminAccess.ts @@ -34,11 +34,17 @@ export function canSendTeamInvitations(role?: string): boolean { export function isPathAllowedForTeamRole(pathname: string, role?: string): boolean { if (!isContentManagerPanelRole(role)) return true + if (pathname === "/notifications") return true return CONTENT_MANAGER_PATH_PREFIXES.some( (p) => pathname === p || pathname.startsWith(`${p}/`), ) } +/** Content managers may open the personal notification inbox only (not admin broadcast tools). */ +export function isContentManagerNotificationInboxPath(pathname: string): boolean { + return pathname === "/notifications" +} + export function getDefaultAppHome(role?: string): string { if (isContentManagerPanelRole(role)) return "/new-content" return "/dashboard" @@ -61,13 +67,26 @@ export function isNavEntryAllowedForTeamRole( if (!isContentManagerPanelRole(role)) return true if (entry.kind === "section") { - return entry.label === "Learning content" || entry.label === "Account" + return ( + entry.label === "Learning content" || + entry.label === "Account" || + entry.label === "Communications" + ) } if (entry.kind === "group") { - return entry.basePath === "/new-content" + return entry.basePath === "/new-content" || entry.basePath === "/notifications" } if (entry.kind === "link") { - return entry.to === "/personas" || entry.to === "/profile" + const to = entry.to ?? "" + if (to === "/personas" || to === "/profile") return true + if (to === "/notifications") return true + if (to.startsWith("/notifications/")) return false + return ( + to === "/new-content" || + to.startsWith("/new-content/") || + to === "/content" || + to.startsWith("/content/") + ) } return false } diff --git a/src/pages/analytics/AnalyticsPage.tsx b/src/pages/analytics/AnalyticsPage.tsx index 497042e..affed77 100644 --- a/src/pages/analytics/AnalyticsPage.tsx +++ b/src/pages/analytics/AnalyticsPage.tsx @@ -734,6 +734,16 @@ export function AnalyticsPage() { data={users.by_age_group ?? []} total={users.total_users} /> + + + + {notifications.length > 0 && ( <> {globalUnread > 0 ? ( diff --git a/src/pages/role-management/RolesListPage.tsx b/src/pages/role-management/RolesListPage.tsx index 64ae146..81c2f69 100644 --- a/src/pages/role-management/RolesListPage.tsx +++ b/src/pages/role-management/RolesListPage.tsx @@ -43,13 +43,11 @@ import { DEFAULT_TABLE_PAGE_SIZE, TABLE_PAGE_SIZE_OPTIONS } from "../../lib/tabl import { toast } from "sonner" import { SpinnerIcon } from "../../components/ui/spinner-icon" import { InviteTeamMemberDialog } from "./components/InviteTeamMemberDialog" -import { canSendTeamInvitations } from "../../lib/adminAccess" -import { getNormalizedSessionTeamRole } from "../../lib/teamRole" +import { SuperAdminOnly } from "../../components/access/AdminAccessGates" import { STAFF_TEAM_ROLE_OPTIONS } from "../../lib/teamRoles" export function RolesListPage() { const navigate = useNavigate() - const showTeamInviteActions = canSendTeamInvitations(getNormalizedSessionTeamRole()) const staffRoleNames = useMemo( () => new Set(STAFF_TEAM_ROLE_OPTIONS.map((o) => o.value)), [], @@ -474,7 +472,8 @@ export function RolesListPage() {
- {showTeamInviteActions && staffRoleNames.has(role.name.toUpperCase()) ? ( + + {staffRoleNames.has(role.name.toUpperCase()) ? ( - ) : null} + @@ -503,13 +502,13 @@ export function TeamManagementPage() { {/* Status Update Confirmation Modal */} - {showInviteActions ? ( + void fetchMembers()} /> - ) : null} + {confirmDialog && (
diff --git a/src/types/analytics.types.ts b/src/types/analytics.types.ts index b9da6b7..9a903a6 100644 --- a/src/types/analytics.types.ts +++ b/src/types/analytics.types.ts @@ -26,6 +26,7 @@ export interface DashboardUsers { by_role: LabelCount[] by_status: LabelCount[] by_age_group: LabelCount[] + by_gender: LabelCount[] by_education_level: LabelCount[] by_occupation: LabelCount[] by_learning_goal: LabelCount[]