Files
Calendar_Frontend/lib/calendars.ts
T
PaddyandClaude Opus 5.5 61e0393f01
Test and deploy / test (pull_request) Successful in 2m18s
Test and deploy / deploy (pull_request) Skipped
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>
2026-11-08 22:15:31 +01:00

84 lines
2.5 KiB
TypeScript

/**
* The calendars, in one place.
*
* The Angular app kept this mapping three times - a switch in the admin page,
* an index-into-array in the move popup (which only worked because ids 3 and 4
* happen to sit in that order) and `calendarId === 5` checks in the API service
* and the filter - and the copies had drifted: the move popup could not move an
* event to Birthdays.
*
* Ids and slugs mirror `calendarNames` in the API's events.router.ts; the API
* has no endpoint that lists them (docs/api-wishlist.md), so a new calendar
* needs an entry here too.
*
* Class names are written out in full so Tailwind's source scan finds them.
*/
export type CalendarSlug = "public" | "members" | "choir" | "management" | "birthdays";
export interface Calendar {
id: number;
slug: CalendarSlug;
label: string;
/** Shown by default in the admin list. Birthdays would flood it. */
defaultVisible: boolean;
/**
* A recurrence every event in this calendar gets, whatever the form says.
* Replaces the old `calendarId === 5` special case in api.service.ts.
*/
forcedRepeatFrequency?: string;
dotClass: string;
badgeClass: string;
}
export const CALENDARS: readonly Calendar[] = [
{
id: 1,
slug: "public",
label: "Öffentlich",
defaultVisible: true,
dotClass: "bg-sky-500",
badgeClass: "bg-sky-50 text-sky-800 ring-sky-200",
},
{
id: 2,
slug: "members",
label: "Mitglieder",
defaultVisible: true,
dotClass: "bg-emerald-500",
badgeClass: "bg-emerald-50 text-emerald-800 ring-emerald-200",
},
{
id: 4,
slug: "choir",
label: "Chor",
defaultVisible: true,
dotClass: "bg-violet-500",
badgeClass: "bg-violet-50 text-violet-800 ring-violet-200",
},
{
id: 3,
slug: "management",
// Shown as "Vorstand" (user's wording, 2026-11-08); the slug stays "management" - it's the API's name.
label: "Vorstand",
defaultVisible: true,
dotClass: "bg-amber-500",
badgeClass: "bg-amber-50 text-amber-900 ring-amber-200",
},
{
id: 5,
slug: "birthdays",
label: "Geburtstage",
defaultVisible: false,
forcedRepeatFrequency: "YEARLY",
dotClass: "bg-rose-500",
badgeClass: "bg-rose-50 text-rose-800 ring-rose-200",
},
];
export const calendarById = (id: number): Calendar | undefined => CALENDARS.find((c) => c.id === id);
export const calendarBySlug = (slug: string): Calendar | undefined => CALENDARS.find((c) => c.slug === slug);
export const DEFAULT_VISIBLE_CALENDAR_IDS: readonly number[] = CALENDARS.filter((c) => c.defaultVisible).map((c) => c.id);