Support the read-only calendar role, show "Vorstand", fix link buttons
- 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>
This commit is contained in:
16 files changed
+155
-32
No files matched your search
@@ -1,9 +1,9 @@
|
||||
"use client";
|
||||
|
||||
import { CircleAlertIcon, CopyIcon, LoaderCircleIcon, Trash2Icon, XIcon } from "lucide-react";
|
||||
import { CircleAlertIcon, CopyIcon, EyeIcon, LoaderCircleIcon, Trash2Icon, XIcon } from "lucide-react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { useAdminUser } from "@/components/admin/AdminSession";
|
||||
import { useAdminUser, useCanEdit } from "@/components/admin/AdminSession";
|
||||
import { EventForm, fieldId } from "@/components/admin/EventForm";
|
||||
import { useMediaQuery } from "@/components/admin/useMediaQuery";
|
||||
import {
|
||||
@@ -84,6 +84,9 @@ export function EventSheet({
|
||||
onDuplicate: (event: CalendarEvent) => void;
|
||||
}) {
|
||||
const user = useAdminUser();
|
||||
// Read-only role: the sheet becomes a view - same fields, nothing to save, delete or duplicate.
|
||||
// The page never opens it in "new" or "duplicate" mode for such an account.
|
||||
const readOnly = !useCanEdit();
|
||||
const desktop = useMediaQuery("(min-width: 640px)");
|
||||
|
||||
// What "unchanged" means. Moves forward after a partial save (moved, but the
|
||||
@@ -223,13 +226,13 @@ export function EventSheet({
|
||||
noValidate
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
void save();
|
||||
if (!readOnly) void save();
|
||||
}}
|
||||
className="flex min-h-0 flex-1 flex-col"
|
||||
>
|
||||
<SheetHeader className="flex-row items-start justify-between gap-3 border-b p-4">
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<SheetTitle>{TITLES[mode.kind]}</SheetTitle>
|
||||
<SheetTitle>{readOnly ? "Termin ansehen" : TITLES[mode.kind]}</SheetTitle>
|
||||
<SheetDescription className={mode.kind === "edit" ? "line-clamp-1" : undefined}>
|
||||
{mode.kind === "edit"
|
||||
? mode.event.name
|
||||
@@ -244,7 +247,7 @@ export function EventSheet({
|
||||
</SheetHeader>
|
||||
|
||||
<div className="min-h-0 flex-1 overflow-y-auto overscroll-contain px-4 py-5">
|
||||
<EventForm form={form} errors={showErrors ? errors : {}} disabled={busy} onChange={setForm} />
|
||||
<EventForm form={form} errors={showErrors ? errors : {}} disabled={busy || readOnly} onChange={setForm} />
|
||||
{original && <Metadata event={original} />}
|
||||
</div>
|
||||
|
||||
@@ -257,6 +260,17 @@ export function EventSheet({
|
||||
)}
|
||||
{/* Labels follow the footer's own width (container query), not the window's: the
|
||||
side panel is capped, so a wide window says nothing about the room in here. */}
|
||||
{readOnly ? (
|
||||
<div className="flex items-center gap-3">
|
||||
<p className="flex flex-1 items-center gap-2 text-sm text-muted-foreground">
|
||||
<EyeIcon aria-hidden className="size-4 shrink-0" />
|
||||
Du hast für den Kalender nur Lesezugriff.
|
||||
</p>
|
||||
<Button type="button" variant="outline" onClick={requestClose}>
|
||||
Schließen
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="@container flex items-center gap-2">
|
||||
{original && (
|
||||
<>
|
||||
@@ -298,6 +312,7 @@ export function EventSheet({
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user