"use client"; import { useRef, useState } from "react"; import { useRouter } from "next/navigation"; import { publishPromo } from "../actions"; import { PromoImage } from "@/components/PromoImage"; const STRIPE_WARM = "repeating-linear-gradient(45deg,#efe9da,#efe9da 12px,#e6ddc9 12px,#e6ddc9 24px)"; export function MemberSpaceForm({ memberName, categories, }: { memberName: string; categories: string[]; }) { const CATEGORIES = categories.length > 0 ? categories : ["Autre"]; const router = useRouter(); const [title, setTitle] = useState(""); const [text, setText] = useState(""); const [cat, setCat] = useState(CATEGORIES[0]); const [badge, setBadge] = useState(""); const [imgData, setImgData] = useState(""); const [submitted, setSubmitted] = useState(false); const [pending, setPending] = useState(false); const fileRef = useRef(null); function onFile(e: React.ChangeEvent) { const f = e.target.files?.[0]; if (!f) return; const reader = new FileReader(); reader.onload = () => { setImgData(String(reader.result)); setSubmitted(false); }; reader.readAsDataURL(f); } function reset() { setTitle(""); setText(""); setBadge(""); setImgData(""); setSubmitted(false); if (fileRef.current) fileRef.current.value = ""; } async function submit() { if (!title.trim()) return; setPending(true); const fd = new FormData(); fd.set("title", title); fd.set("text", text); fd.set("category", cat); fd.set("badge", badge); fd.set("imageUrl", imgData); await publishPromo(fd); setPending(false); setSubmitted(true); reset(); setSubmitted(true); router.refresh(); } const hasImg = !!imgData; const hasBadge = !!badge.trim(); return (
{/* FORM */}

Publier une promotion

Ajoutez une image et un texte. Votre promotion sera visible après validation par l'association.

{ setTitle(e.target.value); setSubmitted(false); }} placeholder="ex : Le 13e pain offert" className="field" style={{ marginBottom: 16 }} />
setBadge(e.target.value)} placeholder="ex : -20%" className="field" />