import { Plus, X } from 'lucide-react'; import { useState } from 'react'; import InputError from '@/components/input-error'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; type Row = { title: string; body: string }; const MAX_ROWS = 5; const fieldClass = 'w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-xs outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 md:text-sm'; /** * Extra sections that fold open on the product page, such as "How to use" or "Care". * The inputs carry the names the server reads: details[i][title] and details[i][body]. */ export default function DetailsEditor({ initial, errors, }: { initial: Row[]; errors: Record; }) { const [rows, setRows] = useState(initial); function update(index: number, field: keyof Row, value: string) { setRows((current) => current.map((row, i) => i === index ? { ...row, [field]: value } : row, ), ); } const listError = errors.details ?? Object.entries(errors).find(([key]) => key.startsWith('details.'))?.[1]; return (

More information

Sections shoppers can open on the product page, such as "How to use" or "Care". Shipping is added by itself.

{rows.map((row, index) => (
update(index, 'title', event.target.value) } placeholder="How to use" />