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 { getDefaultAppHome } from "../lib/adminAccess";
|
||||
import { getNormalizedSessionTeamRole } from "../lib/teamRole";
|
||||
import { AppLayout } from "../layouts/AppLayout";
|
||||
import { DashboardPage } from "../pages/DashboardPage";
|
||||
import { AnalyticsPage } from "../pages/analytics/AnalyticsPage";
|
||||
|
|
@ -91,7 +93,7 @@ export function AppRoutes() {
|
|||
<Route path="/privacy" element={<PrivacyPage />} />
|
||||
<Route path="/account-deletion" element={<AccountDeletionPage />} />
|
||||
<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="/users" element={<UserManagementLayout />}>
|
||||
<Route index element={<Navigate to="list" replace />} />
|
||||
|
|
|
|||
|
|
@ -28,6 +28,10 @@ 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 { isNavEntryAllowedForTeamRole } from "../../lib/adminAccess";
|
||||
|
||||
type NavLinkItem = {
|
||||
kind: "link";
|
||||
|
|
@ -164,6 +168,7 @@ export function Sidebar({
|
|||
loading: permissionsLoading,
|
||||
} = useTeamPermissions();
|
||||
const [unreadCount, setUnreadCount] = useState(0);
|
||||
const sessionTeamRole = getNormalizedSessionTeamRole();
|
||||
|
||||
useEffect(() => {
|
||||
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">
|
||||
{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 (isCollapsed) {
|
||||
return index > 0 ? (
|
||||
|
|
|
|||
|
|
@ -3,6 +3,11 @@ import { Navigate, Outlet, useLocation } from "react-router-dom"
|
|||
import { Sidebar } from "../components/sidebar/Sidebar"
|
||||
import { Topbar } from "../components/topbar/Topbar"
|
||||
import { getAccessToken } from "../lib/teamAuthStorage"
|
||||
import {
|
||||
getDefaultAppHome,
|
||||
isPathAllowedForTeamRole,
|
||||
} from "../lib/adminAccess"
|
||||
import { getNormalizedSessionTeamRole } from "../lib/teamRole"
|
||||
import {
|
||||
connectNotificationsWebSocket,
|
||||
disconnectNotificationsWebSocket,
|
||||
|
|
@ -70,6 +75,11 @@ export function AppLayout() {
|
|||
return <Navigate to="/login" replace />
|
||||
}
|
||||
|
||||
const teamRole = getNormalizedSessionTeamRole()
|
||||
if (!isPathAllowedForTeamRole(location.pathname, teamRole)) {
|
||||
return <Navigate to={getDefaultAppHome(teamRole)} replace />
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex h-dvh overflow-hidden bg-grayScale-100">
|
||||
<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([
|
||||
"SUPER_ADMIN",
|
||||
"ADMIN",
|
||||
"CONTENT_MANAGER",
|
||||
"FINANCE",
|
||||
"HR",
|
||||
"ANALYST",
|
||||
])
|
||||
|
||||
export function getSessionTeamRole(): string {
|
||||
|
|
|
|||
|
|
@ -1,15 +1,7 @@
|
|||
import type { Role } from "../types/rbac.types"
|
||||
import { STAFF_TEAM_ROLE_OPTIONS } from "./adminAccess"
|
||||
|
||||
export const 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 TEAM_ROLE_OPTIONS = [...STAFF_TEAM_ROLE_OPTIONS]
|
||||
|
||||
export const EMPLOYMENT_TYPE_OPTIONS = [
|
||||
{ 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.
|
||||
* Must be a built-in team role (e.g. SUPER_ADMIN) or an exact RBAC role name/id —
|
||||
* never a UI display label like "Super Admin".
|
||||
* Must be one of SUPER_ADMIN, ADMIN, or CONTENT_MANAGER.
|
||||
*/
|
||||
export function teamRoleNameForInvite(teamRole: string, explicitName?: string): string {
|
||||
const raw = (teamRole || explicitName || "").trim()
|
||||
if (!raw) return ""
|
||||
|
||||
// Accidental display labels from built-in options → API keys
|
||||
const byLabel = TEAM_ROLE_OPTIONS.find(
|
||||
(o) => o.label.toLowerCase() === raw.toLowerCase(),
|
||||
)
|
||||
|
|
@ -62,19 +52,17 @@ export function teamRoleNameForInvite(teamRole: string, explicitName?: string):
|
|||
)
|
||||
if (byValue) return byValue.value
|
||||
|
||||
// Custom RBAC roles: keep exact name (spaces allowed); numeric id strings pass through
|
||||
return raw
|
||||
return rbacRoleNameToTeamRole(raw)
|
||||
}
|
||||
|
||||
export type TeamRoleOption = { value: string; label: string }
|
||||
|
||||
export function rbacRolesToTeamRoleOptions(roles: Role[]): TeamRoleOption[] {
|
||||
const names = Array.from(
|
||||
new Set(roles.map((role) => role.name.trim()).filter(Boolean)),
|
||||
).sort((a, b) => a.localeCompare(b))
|
||||
|
||||
return names.map((name) => ({
|
||||
value: name,
|
||||
label: formatTeamRoleLabel(name),
|
||||
}))
|
||||
export function staffTeamRoleOptions(): TeamRoleOption[] {
|
||||
return TEAM_ROLE_OPTIONS.map((opt) => ({ value: opt.value, label: opt.label }))
|
||||
}
|
||||
|
||||
/** @deprecated Custom RBAC team roles are no longer supported; use staffTeamRoleOptions(). */
|
||||
export function rbacRolesToTeamRoleOptions(roles: Role[]): TeamRoleOption[] {
|
||||
void roles
|
||||
return staffTeamRoleOptions()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ import {
|
|||
TrendingDown,
|
||||
CreditCard,
|
||||
Video,
|
||||
Layers,
|
||||
FolderOpen,
|
||||
RefreshCw,
|
||||
ChevronDown,
|
||||
|
|
@ -625,128 +624,46 @@ export function AnalyticsPage() {
|
|||
|
||||
<div className="space-y-5">
|
||||
{activeSummaryTab === "key" && (
|
||||
<>
|
||||
{/* ─── Key Metrics ─── */}
|
||||
<Section title="Key Metrics" icon={TrendingUp} defaultOpen>
|
||||
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
|
||||
<KpiCard
|
||||
icon={Users}
|
||||
label="Total Users"
|
||||
value={formatNumber(users.total_users)}
|
||||
sub={`+${users.new_today} today · +${users.new_week} this week · +${users.new_month} this month`}
|
||||
trend={users.new_month > 0 ? "up" : "neutral"}
|
||||
/>
|
||||
<KpiCard
|
||||
icon={CreditCard}
|
||||
label="Active Learners"
|
||||
value={formatNumber(snapshot?.active_learners ?? subscriptionMetrics.active)}
|
||||
sub={`${formatNumber(snapshot?.active_now ?? subscriptionMetrics.active)} active subs · ${subscriptionMetrics.inactive} inactive`}
|
||||
trend={subscriptions.new_month > 0 ? "up" : "neutral"}
|
||||
/>
|
||||
<KpiCard
|
||||
icon={DollarSign}
|
||||
label="Total Revenue"
|
||||
value={
|
||||
<SensitiveValue>
|
||||
{`ETB ${formatNumber(payments.total_revenue)}`}
|
||||
<Section title="Key Metrics" icon={TrendingUp} defaultOpen>
|
||||
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
|
||||
<KpiCard
|
||||
icon={Users}
|
||||
label="Total Users"
|
||||
value={formatNumber(users.total_users)}
|
||||
sub={`+${users.new_today} today · +${users.new_week} this week · +${users.new_month} this month`}
|
||||
trend={users.new_month > 0 ? "up" : "neutral"}
|
||||
/>
|
||||
<KpiCard
|
||||
icon={CreditCard}
|
||||
label="Active Learners"
|
||||
value={formatNumber(snapshot?.active_learners ?? subscriptionMetrics.active)}
|
||||
sub={`${formatNumber(snapshot?.active_now ?? subscriptionMetrics.active)} active subs · ${subscriptionMetrics.inactive} inactive`}
|
||||
trend={subscriptions.new_month > 0 ? "up" : "neutral"}
|
||||
/>
|
||||
<KpiCard
|
||||
icon={DollarSign}
|
||||
label="Total Revenue"
|
||||
value={
|
||||
<SensitiveValue>
|
||||
{`ETB ${formatNumber(payments.total_revenue)}`}
|
||||
</SensitiveValue>
|
||||
}
|
||||
sub={
|
||||
<>
|
||||
{payments.successful_payments}/{payments.total_payments} successful · Avg{" "}
|
||||
<SensitiveValue showToggle={false}>
|
||||
ETB {payments.avg_transaction_value.toLocaleString()}
|
||||
</SensitiveValue>
|
||||
}
|
||||
sub={
|
||||
<>
|
||||
{payments.successful_payments}/{payments.total_payments} successful · Avg{" "}
|
||||
<SensitiveValue showToggle={false}>
|
||||
ETB {payments.avg_transaction_value.toLocaleString()}
|
||||
</SensitiveValue>
|
||||
</>
|
||||
}
|
||||
trend={payments.total_revenue > 0 ? "up" : "neutral"}
|
||||
/>
|
||||
</div>
|
||||
</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>
|
||||
</>
|
||||
</>
|
||||
}
|
||||
trend={payments.total_revenue > 0 ? "up" : "neutral"}
|
||||
/>
|
||||
</div>
|
||||
</Section>
|
||||
)}
|
||||
|
||||
{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 ─── */}
|
||||
<Section title="User Analytics" icon={Users} count={users.total_users} defaultOpen>
|
||||
<Card className="shadow-none">
|
||||
|
|
@ -1194,9 +1111,53 @@ export function AnalyticsPage() {
|
|||
</div>
|
||||
</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 ─── */}
|
||||
{(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">
|
||||
{lms && (
|
||||
<BreakdownList
|
||||
|
|
@ -1241,7 +1202,7 @@ export function AnalyticsPage() {
|
|||
|
||||
{/* ─── Video Analytics ─── */}
|
||||
{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">
|
||||
<KpiCard
|
||||
icon={PlayCircle}
|
||||
|
|
@ -1393,13 +1354,8 @@ export function AnalyticsPage() {
|
|||
</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>
|
||||
</SensitiveRevealProvider>
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ import { login, loginWithGoogle } from "../../api/auth.api";
|
|||
import type { LoginRequest } from "../../types/auth.types";
|
||||
import type { LoginResult } from "../../api/auth.api";
|
||||
import { saveTeamSessionFromLoginResult, getAccessToken } from "../../lib/teamAuthStorage";
|
||||
import { getDefaultAppHome } from "../../lib/adminAccess";
|
||||
import { getNormalizedSessionTeamRole } from "../../lib/teamRole";
|
||||
import { toast } from "sonner";
|
||||
|
||||
declare global {
|
||||
|
|
@ -111,7 +113,7 @@ export function LoginPage() {
|
|||
toast.success("Welcome back!", {
|
||||
description: "You have signed in successfully.",
|
||||
});
|
||||
navigate("/dashboard");
|
||||
navigate(getDefaultAppHome(getNormalizedSessionTeamRole()));
|
||||
},
|
||||
[navigate]
|
||||
);
|
||||
|
|
@ -183,7 +185,7 @@ export function LoginPage() {
|
|||
}, [googleReady, handleGoogleCallback]);
|
||||
|
||||
if (token) {
|
||||
return <Navigate to="/dashboard" replace />;
|
||||
return <Navigate to={getDefaultAppHome(getNormalizedSessionTeamRole())} replace />;
|
||||
}
|
||||
|
||||
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 { SpinnerIcon } from "../../components/ui/spinner-icon"
|
||||
import { InviteTeamMemberDialog } from "./components/InviteTeamMemberDialog"
|
||||
import { canSendTeamInvitations, STAFF_TEAM_ROLE_OPTIONS } from "../../lib/adminAccess"
|
||||
import { getNormalizedSessionTeamRole } from "../../lib/teamRole"
|
||||
|
||||
export function RolesListPage() {
|
||||
const navigate = useNavigate()
|
||||
const showTeamInviteActions = canSendTeamInvitations(getNormalizedSessionTeamRole())
|
||||
const staffRoleNames = useMemo(
|
||||
() => new Set(STAFF_TEAM_ROLE_OPTIONS.map((o) => o.value)),
|
||||
[],
|
||||
)
|
||||
|
||||
// List state
|
||||
const [roles, setRoles] = useState<Role[]>([])
|
||||
|
|
@ -466,6 +473,7 @@ export function RolesListPage() {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{showTeamInviteActions && staffRoleNames.has(role.name.toUpperCase()) ? (
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
|
|
@ -477,6 +485,7 @@ export function RolesListPage() {
|
|||
<Mail className="h-3.5 w-3.5 shrink-0" />
|
||||
Invite team members
|
||||
</Button>
|
||||
) : null}
|
||||
|
||||
<div className="grid grid-cols-1 gap-2 sm:grid-cols-2">
|
||||
<Button
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { useEffect, useMemo, useState } from "react"
|
||||
import { Mail, Shield } from "lucide-react"
|
||||
import { toast } from "sonner"
|
||||
import { fetchAllRoles } from "../../../api/rbac.api"
|
||||
import { fetchAllTeamMemberEmails, inviteTeamMember } from "../../../api/team.api"
|
||||
import { Button } from "../../../components/ui/button"
|
||||
import {
|
||||
|
|
@ -24,9 +23,8 @@ import {
|
|||
} from "../../../lib/parseInviteEmails"
|
||||
import {
|
||||
formatTeamRoleLabel,
|
||||
rbacRolesToTeamRoleOptions,
|
||||
staffTeamRoleOptions,
|
||||
teamRoleNameForInvite,
|
||||
TEAM_ROLE_OPTIONS,
|
||||
type TeamRoleOption,
|
||||
} from "../../../lib/teamRoles"
|
||||
|
||||
|
|
@ -52,8 +50,6 @@ export function InviteTeamMemberDialog({
|
|||
|
||||
const [emailsText, setEmailsText] = useState("")
|
||||
const [teamRole, setTeamRole] = useState(lockedRole)
|
||||
const [loadedRoleOptions, setLoadedRoleOptions] = useState<TeamRoleOption[]>([])
|
||||
const [rolesLoading, setRolesLoading] = useState(false)
|
||||
const [existingEmails, setExistingEmails] = useState<Set<string>>(new Set())
|
||||
const [existingEmailsLoading, setExistingEmailsLoading] = useState(false)
|
||||
const [existingEmailsError, setExistingEmailsError] = useState(false)
|
||||
|
|
@ -77,38 +73,9 @@ export function InviteTeamMemberDialog({
|
|||
)
|
||||
const hasEmailConflicts = alreadyRegisteredEmails.length > 0
|
||||
|
||||
const fallbackRoleOptions = useMemo<TeamRoleOption[]>(
|
||||
() => TEAM_ROLE_OPTIONS.map((opt) => ({ value: opt.value, label: opt.label })),
|
||||
[],
|
||||
)
|
||||
|
||||
const selectableRoleOptions = roleOptions?.length
|
||||
? roleOptions
|
||||
: loadedRoleOptions.length
|
||||
? 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])
|
||||
: staffTeamRoleOptions()
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return
|
||||
|
|
@ -348,11 +315,9 @@ export function InviteTeamMemberDialog({
|
|||
id="invite-role"
|
||||
value={teamRole}
|
||||
onChange={(e) => setTeamRole(e.target.value)}
|
||||
disabled={submitting || rolesLoading || selectableRoleOptions.length === 0}
|
||||
disabled={submitting || selectableRoleOptions.length === 0}
|
||||
>
|
||||
{rolesLoading ? (
|
||||
<option value="">Loading roles…</option>
|
||||
) : selectableRoleOptions.length === 0 ? (
|
||||
{selectableRoleOptions.length === 0 ? (
|
||||
<option value="">No roles available</option>
|
||||
) : (
|
||||
selectableRoleOptions.map((opt) => (
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ import { InviteTeamMemberDialog } from "../role-management/components/InviteTeam
|
|||
import { EXPORT_PERMISSIONS, EXPORT_ROUTES } from "../../lib/csv-export";
|
||||
import { teamMemberExportQuery } from "../../lib/csvExportFilters";
|
||||
import { UnassignedLabel } from "../../lib/displayValue"
|
||||
import { canSendTeamInvitations } from "../../lib/adminAccess";
|
||||
import { getNormalizedSessionTeamRole } from "../../lib/teamRole";
|
||||
|
||||
function formatDate(dateStr: string): string {
|
||||
return new Date(dateStr).toLocaleDateString("en-US", {
|
||||
|
|
@ -243,6 +245,8 @@ export function TeamManagementPage() {
|
|||
[roleFilter, statusFilter, search],
|
||||
);
|
||||
|
||||
const showInviteActions = canSendTeamInvitations(getNormalizedSessionTeamRole());
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
||||
|
|
@ -260,13 +264,15 @@ export function TeamManagementPage() {
|
|||
disabled={loading}
|
||||
className="w-full sm:w-auto"
|
||||
/>
|
||||
<Button
|
||||
className="bg-brand-600 hover:bg-brand-500 text-white w-full sm:w-auto"
|
||||
onClick={() => setInviteOpen(true)}
|
||||
>
|
||||
<Plus className="h-4 w-4" />
|
||||
Add Team Member
|
||||
</Button>
|
||||
{showInviteActions ? (
|
||||
<Button
|
||||
className="bg-brand-600 hover:bg-brand-500 text-white w-full sm:w-auto"
|
||||
onClick={() => setInviteOpen(true)}
|
||||
>
|
||||
<Plus className="h-4 w-4" />
|
||||
Add Team Member
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -296,11 +302,6 @@ export function TeamManagementPage() {
|
|||
<option value="super_admin">Super Admin</option>
|
||||
<option value="admin">Admin</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>
|
||||
<ChevronDown className="absolute right-2 top-1/2 h-4 w-4 -translate-y-1/2 text-grayScale-400 pointer-events-none" />
|
||||
</div>
|
||||
|
|
@ -502,11 +503,13 @@ export function TeamManagementPage() {
|
|||
</div>
|
||||
|
||||
{/* Status Update Confirmation Modal */}
|
||||
<InviteTeamMemberDialog
|
||||
open={inviteOpen}
|
||||
onOpenChange={setInviteOpen}
|
||||
onInvited={() => void fetchMembers()}
|
||||
/>
|
||||
{showInviteActions ? (
|
||||
<InviteTeamMemberDialog
|
||||
open={inviteOpen}
|
||||
onOpenChange={setInviteOpen}
|
||||
onInvited={() => void fetchMembers()}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{confirmDialog && (
|
||||
<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