diff --git a/src/app/(dashboard)/mockup/page.tsx b/src/app/(dashboard)/mockup/page.tsx index 35ecbf1..202bff5 100644 --- a/src/app/(dashboard)/mockup/page.tsx +++ b/src/app/(dashboard)/mockup/page.tsx @@ -1,19 +1,39 @@ 'use client' -import { useState } from 'react' +import { useState, useEffect, useRef } from 'react' import { Header } from '@/components/layout/Header' import { TemplateLibrary } from '@/components/mockup/TemplateLibrary' import { MockupGenerator } from '@/components/mockup/MockupGenerator' type Tab = 'generate' | 'library' +interface Product { + shopifyId: string + title: string + ref: string +} + export default function MockupPage() { const [tab, setTab] = useState('generate') - const [shopifyId, setShopifyId] = useState('') - const [productName, setProductName] = useState('') + const [products, setProducts] = useState([]) + const [search, setSearch] = useState('') + const [showDropdown, setShowDropdown] = useState(false) + const [selectedProduct, setSelectedProduct] = useState(null) const [family, setFamily] = useState('Menuiserie') const [dimensions, setDimensions] = useState('') const [cutoutB64, setCutoutB64] = useState(null) + const dropdownRef = useRef(null) + + useEffect(() => { + fetch('/api/products/list') + .then(r => r.json()) + .then(data => setProducts(data.products ?? [])) + }, []) + + const filtered = search.length < 2 ? [] : products.filter(p => + p.title.toLowerCase().includes(search.toLowerCase()) || + p.ref.toLowerCase().includes(search.toLowerCase()) + ).slice(0, 20) const handleFile = (e: React.ChangeEvent) => { const file = e.target.files?.[0] @@ -31,12 +51,8 @@ export default function MockupPage() {
{(['generate', 'library'] as Tab[]).map(t => ( - ))} @@ -50,17 +66,49 @@ export default function MockupPage() {

Produit

+ + {/* Product picker */} +
+ + {selectedProduct ? ( +
+ {selectedProduct.title} + {selectedProduct.ref} + +
+ ) : ( + <> + { setSearch(e.target.value); setShowDropdown(true) }} + onFocus={() => setShowDropdown(true)} + placeholder="Nom ou référence du produit…" + className="w-full bg-slate-700 border border-slate-600 rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:ring-1 focus:ring-indigo-500" + /> + {showDropdown && filtered.length > 0 && ( +
+ {filtered.map(p => ( + + ))} +
+ )} + {showDropdown && search.length >= 2 && filtered.length === 0 && ( +
+

Aucun résultat

+
+ )} + + )} +
+
-
- - setProductName(e.target.value)} - className="w-full bg-slate-700 border border-slate-600 rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:ring-1 focus:ring-indigo-500" /> -
-
- - setShopifyId(e.target.value)} - className="w-full bg-slate-700 border border-slate-600 rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:ring-1 focus:ring-indigo-500" /> -
- {cutoutB64 ? ( + {cutoutB64 && selectedProduct ? ( ) : ( -

Sélectionnez une image découpée pour commencer.

+

+ {!selectedProduct ? 'Sélectionnez un produit pour commencer.' : 'Chargez une image PNG découpée.'} +

)}
)}