45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
"use client";
|
|
|
|
import { useState, useTransition } from "react";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
import type { CalendarActionResult } from "./actions";
|
|
|
|
// Deleting an event also revokes self-service grants on its linked album, so
|
|
// the admin confirms once before the action runs.
|
|
export function DeleteCalendarEventButton({
|
|
action,
|
|
eventId,
|
|
}: Readonly<{
|
|
action: (state: CalendarActionResult, formData: FormData) => Promise<CalendarActionResult>;
|
|
eventId: string;
|
|
}>) {
|
|
const [state, setState] = useState<CalendarActionResult>({ ok: true, message: "" });
|
|
const [pending, startTransition] = useTransition();
|
|
|
|
const handleClick = () => {
|
|
if (!window.confirm("Termin löschen? Selbst freigeschaltete Zugriffe auf das verknüpfte Album werden entzogen.")) {
|
|
return;
|
|
}
|
|
const formData = new FormData();
|
|
formData.set("eventId", eventId);
|
|
startTransition(async () => {
|
|
setState(await action({ ok: true, message: "" }, formData));
|
|
});
|
|
};
|
|
|
|
return (
|
|
<div className="flex flex-col items-end gap-1">
|
|
<Button type="button" variant="outline" size="sm" disabled={pending} onClick={handleClick}>
|
|
{pending ? "…" : "Löschen"}
|
|
</Button>
|
|
{state.ok ? null : (
|
|
<p role="alert" className="text-xs text-destructive">
|
|
{state.message}
|
|
</p>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|