"use client"; import { useState } from "react"; export default function PrintfulAdminPage() { const [name, setName] = useState(""); const [externalId, setExternalId] = useState(""); const [thumbnail, setThumbnail] = useState(""); const [variantId, setVariantId] = useState(""); const [retailPrice, setRetailPrice] = useState(""); const [fileUrl, setFileUrl] = useState(""); const [message, setMessage] = useState(""); const [loading, setLoading] = useState(false); async function handleCreate(e: React.FormEvent) { e.preventDefault(); setLoading(true); setMessage(""); try { const payload = { sync_product: { name, external_id: externalId || undefined, thumbnail: thumbnail || undefined, }, sync_variants: [ { variant_id: Number(variantId), retail_price: retailPrice, files: fileUrl ? [{ type: "default", url: fileUrl }] : [], }, ], }; const res = await fetch("/api/printful/sync-products", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload), }); const data = await res.json(); if (!res.ok) throw new Error(data.error || "Failed to create product."); setMessage(`Created sync product: ${data.result?.id || "ok"}`); } catch (err: any) { setMessage(err.message || "Failed to create product."); } finally { setLoading(false); } } return (

Printful Admin

setName(e.target.value)} required /> setExternalId(e.target.value)} /> setThumbnail(e.target.value)} /> setVariantId(e.target.value)} required /> setRetailPrice(e.target.value)} required /> setFileUrl(e.target.value)} /> {message ?
{message}
: null}
); }