"use client"; /** * Simple events (§8): title, date and time, place, description, a photo and an optional link (a * sign-up form elsewhere, say). Registrations and payments are Cross Events'. Each publishes on its * own (decision 9). An event can belong to a ministry: its Ministry leader can add and change it, * and an Editor publishes it (§10). Events from Cross Events show on the site by themselves. */ import { useState } from "react"; import { api, canEdit } from "@/admin/api"; import { ImagePicker } from "@/admin/media"; import { Btn, Field, inputClass, Loading, Notice, Panel, Title, useAction, useAdmin, when } from "@/admin/ui"; type Ev = { id: string; slug: string; title: string; startsAt: string; endsAt: string | null; allDay: boolean; location: string | null; description: string | null; imageId: string | null; image: string | null; link: string | null; ministryId: string | null; cancelled: boolean; published: boolean; updatedAt: string; }; type Form = { title: string; date: string; time: string; endDate: string; endTime: string; allDay: boolean; location: string; description: string; imageId: string | null; link: string; ministryId: string | null }; type Me = { user: { role: string; ministryId: string | null } }; /** "2026-12-05" + "18:30" in the browser's time zone (the church's, for its admins) → ISO with offset. */ const iso = (date: string, time: string) => (date ? new Date(`${date}T${time || "00:00"}`).toISOString() : null); const local = (s: string | null) => { if (!s) return { d: "", t: "" }; const x = new Date(s); const p = (n: number) => String(n).padStart(2, "0"); return { d: `${x.getFullYear()}-${p(x.getMonth() + 1)}-${p(x.getDate())}`, t: `${p(x.getHours())}:${p(x.getMinutes())}` }; }; function EventForm({ initial, ministries, fixedMinistry, onSave, onCancel }: { initial: Form; ministries: { id: string; name: string }[]; fixedMinistry: string | null; onSave: (body: object) => Promise; onCancel: () => void }) { const [v, setV] = useState(initial); const { busy, message, fields, run } = useAction(); const set = (k: keyof Form, x: unknown) => setV({ ...v, [k]: x }); return (
set("title", e.target.value)} />
set("date", e.target.value)} /> {!v.allDay && set("time", e.target.value)} />} set("endDate", e.target.value)} /> {!v.allDay && set("endTime", e.target.value)} />}
set("location", e.target.value)} />