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,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { createContext, useContext } from "react";
|
||||
import { canEditCalendar } from "@/lib/permissions";
|
||||
import type { AdminUser } from "@/lib/types";
|
||||
|
||||
/**
|
||||
@@ -19,3 +20,9 @@ export const useAdminUser = (): AdminUser => {
|
||||
}
|
||||
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());
|
||||
@@ -39,7 +39,7 @@ export function EventList({
|
||||
/** Index into `events` to show the "Heute" marker in front of (`events.length` = after the last); null for none. */
|
||||
todayMarker: number | null;
|
||||
onOpen?: (event: CalendarEvent) => void;
|
||||
onPublish: (event: CalendarEvent) => void;
|
||||
onPublish?: (event: CalendarEvent) => void;
|
||||
onClearQuery: () => void;
|
||||
}) {
|
||||
if (noCalendars) {
|
||||
|
||||
@@ -23,7 +23,8 @@ export function EventListItem({
|
||||
now: Date;
|
||||
publishing: boolean;
|
||||
onOpen?: (event: CalendarEvent) => void;
|
||||
onPublish: (event: CalendarEvent) => void;
|
||||
/** Absent for a read-only account: then drafts show no publish button. */
|
||||
onPublish?: (event: CalendarEvent) => void;
|
||||
}) {
|
||||
const { start } = occurrence(event, now);
|
||||
const block = dateBlock(start);
|
||||
@@ -86,7 +87,7 @@ export function EventListItem({
|
||||
{repeat}
|
||||
</span>
|
||||
)}
|
||||
{event.status === "DRAFT" && (
|
||||
{event.status === "DRAFT" && onPublish && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="xs"
|
||||
|
||||
@@ -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>
|
||||
)}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { CalendarPlusIcon, CheckIcon, CircleAlertIcon, CopyIcon, RefreshCwIcon } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Button, buttonVariants } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
@@ -114,16 +114,19 @@ export function SubscriptionsDialog() {
|
||||
{subscription.icalUrl}
|
||||
</code>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button variant="outline" size="xs" render={<a href={toWebcal(subscription.icalUrl)} />}>
|
||||
{/* Plain links that only look like buttons. Rendering them through Base UI's
|
||||
Button made them role="button" (and warned without nativeButton={false}). */}
|
||||
<a href={toWebcal(subscription.icalUrl)} className={buttonVariants({ variant: "outline", size: "xs" })}>
|
||||
Apple Kalender
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="xs"
|
||||
render={<a href={toGoogleCalendar(subscription.icalUrl)} target="_blank" rel="noopener noreferrer" />}
|
||||
</a>
|
||||
<a
|
||||
href={toGoogleCalendar(subscription.icalUrl)}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className={buttonVariants({ variant: "outline", size: "xs" })}
|
||||
>
|
||||
Google Kalender
|
||||
</Button>
|
||||
</a>
|
||||
<Button variant="outline" size="xs" onClick={() => void copy(subscription)}>
|
||||
{copied === calendar.slug ? <CheckIcon /> : <CopyIcon />}
|
||||
{copied === calendar.slug ? "Kopiert" : "Link kopieren"}
|
||||
|
||||
Reference in new issue
Block a user