"use client";
import { useActionState, useState } from "react";
import { useFormStatus } from "react-dom";
import type { ActionResult } from "@/lib/action-result";
import { cancelByAdvisor, respond, saveNote } from "@/app/admin/(panel)/beratung/actions";
import { Icon } from "../Icon";
function Submit({ label, className = "sm-btn sm-btn--primary sm-btn--sm" }: { label: string; className?: string }) {
const { pending } = useFormStatus();
return ;
}
function Result({ state }: { state: ActionResult }) {
if (!state?.message) return null;
return {state.message};
}
type SlotGroup = { label: string; options: { value: string; label: string }[] };
/** Antwort auf eine Anfrage: bestätigen, andere Zeiten vorschlagen oder ablehnen. */
export function RespondForm({ id, slots }: { id: string; slots: SlotGroup[] }) {
const [state, action] = useActionState(respond, null);
const [mode, setMode] = useState<"" | "propose" | "decline">("");
if (state?.ok) return ;
return (
{mode === "propose" && (
)}
{mode === "decline" && (
)}
{!mode &&
}
);
}
/** Private Notiz der Beraterin zu einem Termin. */
export function NoteForm({ id, note }: { id: string; note: string }) {
const [state, action] = useActionState(saveNote, null);
return (
);
}
/** Absage durch die Beraterin (oder das Team): Kundin bekommt das Geld zurück. */
export function AdvisorCancelForm({ id }: { id: string }) {
const [state, action] = useActionState(cancelByAdvisor, null);
const [open, setOpen] = useState(false);
if (state?.ok) return ;
if (!open) return ;
return (
);
}