Skip to content

Commit 68ead6a

Browse files
committed
Refactoring how we structure required and optional roles. Adding Site
Map
1 parent 386723b commit 68ead6a

84 files changed

Lines changed: 715 additions & 1434 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/lib/components/PageRoleCheck.svelte

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,54 @@
66
77
interface Props {
88
userEntitlements: any[];
9-
requiredRoles: RoleRequirement[];
9+
required: RoleRequirement[];
10+
optional?: RoleRequirement[];
1011
children?: Snippet;
1112
}
1213
13-
let { userEntitlements, requiredRoles, children }: Props = $props();
14+
let { userEntitlements, required, optional, children }: Props = $props();
1415
15-
// Check which roles are missing
16-
let roleCheck = $derived.by(() => {
17-
return checkRoles(userEntitlements || [], requiredRoles);
16+
// Check required roles (OR logic — need at least one)
17+
let requiredCheck = $derived.by(() => {
18+
return checkRoles(userEntitlements || [], required || []);
1819
});
1920
20-
// Get just the first missing role (so request entitlement button can request a single role)
21-
let firstMissingRole = $derived(roleCheck.missingRoles[0] || null);
21+
let firstMissingRequired = $derived(requiredCheck.missingRoles[0] || null);
22+
let showContent = $derived(requiredCheck.hasAllRoles);
2223
23-
// Determine if we should show content or only alerts
24-
let showContent = $derived(roleCheck.hasAllRoles);
24+
// Check optional roles (informational — content still renders)
25+
let optionalCheck = $derived.by(() => {
26+
if (!optional || optional.length === 0) return null;
27+
return checkRoles(userEntitlements || [], optional);
28+
});
29+
30+
let missingOptionalRoles = $derived(
31+
optionalCheck && !optionalCheck.hasAllRoles
32+
? optionalCheck.missingRoles
33+
: [],
34+
);
2535
</script>
2636

27-
{#if firstMissingRole}
37+
{#if firstMissingRequired}
2838
<div class="role-alerts">
2939
<MissingRoleAlert
30-
roles={[firstMissingRole.role]}
31-
bankId={firstMissingRole.bankId || undefined}
32-
message={`You need the following role to ${firstMissingRole.action || "access this page"}: ${firstMissingRole.role}`}
40+
roles={[firstMissingRequired.role]}
41+
bankId={firstMissingRequired.bankId || undefined}
42+
message={`You need the following role to access this page: ${firstMissingRequired.role}`}
3343
/>
3444
</div>
3545
{/if}
3646

3747
{#if showContent && children}
48+
{#if missingOptionalRoles.length > 0}
49+
<div class="optional-role-note">
50+
<span class="note-icon">&#x2139;&#xFE0F;</span>
51+
<span>
52+
Some actions on this page require additional roles:
53+
{missingOptionalRoles.map((r) => r.role).join(", ")}
54+
</span>
55+
</div>
56+
{/if}
3857
{@render children()}
3958
{/if}
4059

@@ -45,4 +64,29 @@
4564
gap: 1rem;
4665
margin-bottom: 1.5rem;
4766
}
67+
68+
.optional-role-note {
69+
display: flex;
70+
align-items: flex-start;
71+
gap: 0.5rem;
72+
padding: 0.75rem 1rem;
73+
margin-bottom: 1rem;
74+
background: #eff6ff;
75+
border: 1px solid #bfdbfe;
76+
border-radius: 0.5rem;
77+
color: #1e40af;
78+
font-size: 0.875rem;
79+
line-height: 1.5;
80+
}
81+
82+
:global([data-mode="dark"]) .optional-role-note {
83+
background: rgba(59, 130, 246, 0.15);
84+
border-color: rgba(59, 130, 246, 0.3);
85+
color: #93c5fd;
86+
}
87+
88+
.note-icon {
89+
flex-shrink: 0;
90+
font-size: 1rem;
91+
}
4892
</style>

src/lib/config/navigation.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
Rocket,
3131
Banknote,
3232
Hash,
33+
Map,
3334
} from "@lucide/svelte";
3435
import { env } from "$env/dynamic/public";
3536

@@ -63,6 +64,7 @@ function buildMyAccountItems(): NavigationItem[] {
6364
label: "My Collections",
6465
iconComponent: FolderOpen,
6566
},
67+
{ href: "/user/site-map", label: "Site Map", iconComponent: Map },
6668
];
6769

6870
// Only add Subscriptions link if PUBLIC_SUBSCRIPTIONS_URL is set

0 commit comments

Comments
 (0)