import { Button } from "@/components/ui"; import { AdminField, AdminFieldset, AdminFormPanel, AdminHint, AdminSelect, AdminSwitch, AdminTextarea, } from "@/components/admin-form"; import { formatPrice } from "@/lib/format"; import type { MedalTier, SponsorshipCycle, SponsorshipOfferKind } from "@/generated/prisma/client"; import type { SponsorshipAdminStrings } from "@/i18n/sponsorship/admin"; import { MEDAL_TIERS, OFFER_CYCLES, OFFER_KINDS, centsToEuroInput } from "../_lib/offer-schema"; export interface OfferFormDefaults { id?: string; kind: SponsorshipOfferKind; name: string; nameEn: string; slug: string; description: string; descriptionEn: string; features: string[]; featuresEn: string[]; priceCents: number; honeyShareCentsPerJar: number; honeyShareCentsPerMonth: number; isActive: boolean; isPhysical: boolean; sortOrder: number; honeyProductId: string | null; honeyJars: number; cycle: SponsorshipCycle | null; maxActiveSubscriptions: number | null; medalTier: MedalTier; } export const EMPTY_OFFER: OfferFormDefaults = { kind: "EINMALIG", name: "", nameEn: "", slug: "", description: "", descriptionEn: "", features: [], featuresEn: [], priceCents: 0, honeyShareCentsPerJar: 0, honeyShareCentsPerMonth: 0, isActive: false, isPhysical: false, sortOrder: 0, honeyProductId: null, honeyJars: 0, cycle: null, maxActiveSubscriptions: null, medalTier: "BRONZE", }; interface OfferFormProps { defaults: OfferFormDefaults; /** Beim Bearbeiten ist die Art fest. */ isNew: boolean; honeyOptions: { id: string; name: string; isActive: boolean }[]; action: (formData: FormData) => void | Promise; t: SponsorshipAdminStrings; } const euroOrEmpty = (cents: number): string => (cents > 0 ? centsToEuroInput(cents) : ""); /** * Ein Formular fuer Einmal- und Abo-Angebote. Felder der jeweils anderen Art * stehen mit "(nur Einmalig)" bzw. "(nur Abo)" da und werden beim Speichern * geleert (offer-schema.ts) — so bleibt das Formular ohne Client-Logik. */ export function OfferForm({ defaults, isNew, honeyOptions, action, t }: OfferFormProps) { const tf = t.offerForm; return ( {isNew ? tf.create : tf.save}}> {defaults.id ? : null}
{isNew ? ( {OFFER_KINDS.map((kind) => ( ))} ) : ( )}
{!isNew && defaults.kind === "EINMALIG" ? ( {tf.carrierPrice(formatPrice(defaults.priceCents - defaults.honeyJars * defaults.honeyShareCentsPerJar))} ) : null}
{honeyOptions.map((product) => ( ))}
{OFFER_CYCLES.map((cycle) => ( ))}
{tf.stripeHint}
{MEDAL_TIERS.map((tier) => ( ))}
); }