Skip to content

Commit 8d962a0

Browse files
committed
feat: update Authorized component to use rules for group-based access control; enhance CategoryGroup to return null if no availability; improve EventEditor layout and button labels; fix NavItem active state check
1 parent 1517ab6 commit 8d962a0

4 files changed

Lines changed: 19 additions & 9 deletions

File tree

src/Components/Auth/With.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import { useAuth } from "react-oidc-context";
66
* @since 1.0.0
77
* @version 0.2.0
88
*/
9-
export function Authorized({ children, role }: { children: ReactNode, role?: string }): ReactNode {
9+
export function Authorized({ children, rules }: { children: ReactNode, rules?: (groups: string[]) => boolean }): ReactNode {
1010
const auth = useAuth();
1111

1212
if (auth.isAuthenticated || process.env.NODE_ENV === "development") {
13-
if (role && !((auth.user?.profile as any)?.groups as string[])?.includes(role)) {
13+
if (rules && !rules((auth.user?.profile as any)?.groups as string[])) {
1414
return null;
1515
}
1616
return children;

src/Components/Availability/CategoryGroup.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Models } from "~/Services/Status.Models";
55
/**
66
* @author Aloento
77
* @since 1.0.0
8-
* @version 0.1.0
8+
* @version 0.2.0
99
*/
1010
export function CategoryGroup({ Category }: { Category: Models.ICategory }) {
1111
const { Availa, Region } = useAvailability();
@@ -26,6 +26,10 @@ export function CategoryGroup({ Category }: { Category: Models.ICategory }) {
2626
return `bg-${color}-100 hover:bg-${color}-200`;
2727
}
2828

29+
if (!avas.length) {
30+
return null;
31+
}
32+
2933
return <>
3034
<tr>
3135
<td rowSpan={avas.length} className="text-lg">

src/Components/Event/EventEditor.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,20 @@ export function EventEditor({ Event }: { Event: Models.IEvent }) {
146146
helperText={Validation.update}
147147
/>
148148

149-
<div className="flex gap-x-3 self-end">
149+
<div className="flex justify-between">
150150
<ScaleButton onClick={setFalse} variant="secondary" type="button">
151-
Cancel
151+
Delete
152152
</ScaleButton>
153153

154-
<ScaleButton type="submit" disabled={Loading}>
155-
Submit
156-
</ScaleButton>
154+
<div className="flex gap-x-3">
155+
<ScaleButton onClick={setFalse} variant="secondary" type="button">
156+
Cancel
157+
</ScaleButton>
158+
159+
<ScaleButton type="submit" disabled={Loading}>
160+
Submit
161+
</ScaleButton>
162+
</div>
157163
</div>
158164
</form>
159165
</ScaleModal>

src/Components/Layout/NavItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function NavItem({ Href, Label }: INavItem) {
1616
const path = Paths.at(0);
1717

1818
return (
19-
<ScaleTelekomNavItem aria-label={Label} {...Href.includes(path!) ? { active: true } : {}}>
19+
<ScaleTelekomNavItem aria-label={Label} {...Href.startsWith(`/${path}`) ? { active: true } : {}}>
2020
<a href={Href}>{Label}</a>
2121
</ScaleTelekomNavItem>
2222
);

0 commit comments

Comments
 (0)