- Read-only role: /admin/me's permissions decide via canEditCalendar (lib/permissions.ts, mirrors the API's canWrite: only `access` writes). Read-only accounts see everything but get no "Neuer Termin", no "+", no "Veröffentlichen"; an event opens as "Termin ansehen" with locked fields. A "Nur lesen" badge in the header explains why. The API refuses their writes regardless. - The management calendar is labelled "Vorstand"; the slug stays `management` for the API, URLs and iCal links. - The subscription dialog's Apple/Google links are plain anchors styled with buttonVariants instead of Base UI Buttons rendering an <a>, which warned in dev and would have given them role="button". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
29 lines
913 B
TypeScript
29 lines
913 B
TypeScript
"use client";
|
|
|
|
import { createContext, useContext } from "react";
|
|
import { canEditCalendar } from "@/lib/permissions";
|
|
import type { AdminUser } from "@/lib/types";
|
|
|
|
/**
|
|
* The signed-in account, for components below the admin layout. The layout
|
|
* renders its children only once /me has answered, so inside the admin area
|
|
* this is never null.
|
|
*/
|
|
const AdminSessionContext = createContext<AdminUser | null>(null);
|
|
|
|
export const AdminSessionProvider = AdminSessionContext.Provider;
|
|
|
|
export const useAdminUser = (): AdminUser => {
|
|
const user = useContext(AdminSessionContext);
|
|
if (!user) {
|
|
throw new Error("useAdminUser() used outside the admin layout");
|
|
}
|
|
return user;
|
|
};
|
|
|
|
/**
|
|
* Whether the account may change events. False for the read-only role: then
|
|
* the admin area shows everything but offers no way to change it.
|
|
*/
|
|
export const useCanEdit = (): boolean => canEditCalendar(useAdminUser());
|