"use client"; import { useState, useTransition } from "react"; import { FormField, inputCls, selectCls } from "@/components/admin/FormField"; import { savePlatformSettingsAction, saveStripeSettingsAction, saveThemeSettingsAction, } from "../actions"; type Action = (fd: FormData) => Promise<{ ok: false; error: string } | { ok: true } | undefined>; function FormWrapper({ action, children, submitLabel = "Enregistrer", }: { action: Action; children: React.ReactNode; submitLabel?: string; }) { const [pending, startTransition] = useTransition(); const [error, setError] = useState(null); const [success, setSuccess] = useState(null); function onSubmit(fd: FormData) { setError(null); setSuccess(null); startTransition(async () => { const res = await action(fd); if (res && res.ok === false) setError(res.error); else if (res && res.ok === true) setSuccess("Enregistré."); }); } return (
{children} {error ? (
{error}
) : null} {success ? (
{success}
) : null}
); } export function PlatformForm({ initial, }: { initial: { name: string; defaultLang: string; activeLangs: string[]; currency: string; commissionPercent: number }; }) { return (
); } export function ThemeForm({ initial }: { initial: { active: string } }) { return ( ); } export function StripeForm({ initial, }: { initial: { currency: string; commissionMode: string; perBookingFeePercent: number }; }) { return (
); }