feat: admin hints with auto-expiry shown in album overview
This commit is contained in:
1 parent
2a5a2f3815
commit
abe072b2d1
15 files changed
+2946
-1
No files matched your search
@@ -0,0 +1,91 @@
|
||||
"use client";
|
||||
|
||||
import { useId, useState, useTransition } from "react";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
|
||||
import type { AnnouncementActionResult } from "./actions";
|
||||
|
||||
// Same direct-call-in-transition pattern as the album bulk grant form so the
|
||||
// message box clears after a successful publish without an effect.
|
||||
export function AnnouncementForm({
|
||||
action,
|
||||
defaultEventDate,
|
||||
}: Readonly<{
|
||||
action: (
|
||||
state: AnnouncementActionResult,
|
||||
formData: FormData,
|
||||
) => Promise<AnnouncementActionResult>;
|
||||
defaultEventDate: string;
|
||||
}>) {
|
||||
const messageId = useId();
|
||||
const dateId = useId();
|
||||
const [state, setState] = useState<AnnouncementActionResult>({ ok: true, message: "" });
|
||||
const [pending, startTransition] = useTransition();
|
||||
const [message, setMessage] = useState("");
|
||||
|
||||
const handleSubmit = (formData: FormData) => {
|
||||
startTransition(async () => {
|
||||
const result = await action({ ok: true, message: "" }, formData);
|
||||
setState(result);
|
||||
if (result.ok) {
|
||||
setMessage("");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<form
|
||||
action={handleSubmit}
|
||||
className="bg-card p-4 rounded-xl border border-border shadow-sm space-y-4"
|
||||
>
|
||||
<div className="space-y-2">
|
||||
<label htmlFor={messageId} className="text-sm font-medium">
|
||||
Nachricht
|
||||
</label>
|
||||
<textarea
|
||||
id={messageId}
|
||||
name="message"
|
||||
rows={3}
|
||||
maxLength={500}
|
||||
required
|
||||
value={message}
|
||||
onChange={(event) => setMessage(event.target.value)}
|
||||
placeholder="z. B. Liebl ist heute beim HSV-Spiel — Freigaben und Downloads sind trotzdem verfügbar, Antworten dauern etwas länger."
|
||||
className="flex w-full rounded-md border border-border bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-500 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">{message.length}/500 Zeichen</p>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<label htmlFor={dateId} className="text-sm font-medium">
|
||||
Datum des Ereignisses (z. B. Spieltag)
|
||||
</label>
|
||||
<Input
|
||||
id={dateId}
|
||||
type="date"
|
||||
name="eventDate"
|
||||
defaultValue={defaultEventDate}
|
||||
required
|
||||
className="sm:w-48"
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Der Hinweis wird sofort sichtbar und verschwindet automatisch drei Tage nach diesem
|
||||
Datum.
|
||||
</p>
|
||||
</div>
|
||||
<Button type="submit" disabled={pending}>
|
||||
{pending ? "Wird veröffentlicht…" : "Hinweis veröffentlichen"}
|
||||
</Button>
|
||||
{state.message ? (
|
||||
<p
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
className={state.ok ? "text-sm text-green-600 dark:text-green-400" : "text-sm text-destructive"}
|
||||
>
|
||||
{state.message}
|
||||
</p>
|
||||
) : null}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user