"use client"; import { useState } from "react"; import { Upload, Plus, Settings } from "lucide-react"; import Image from "next/image"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Button } from "@/components/ui/button"; import { Card, CardHeader, CardContent, CardTitle } from "@/components/ui/card"; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; export default function UpdateProductForm() { const [specs, setSpecs] = useState([ { id: 1, title: "Jaecoo 7 SHS Teknologi dan Exterior", images: ["/spec1.jpg", "/spec2.jpg", "/spec3.jpg", "/spec4.jpg"], }, ]); type ColorType = { id: number; name: string; preview: string; colorSelected: string | null; }; const [colors, setColors] = useState([ { id: 1, name: "", preview: "/car-1.png", colorSelected: null, }, { id: 2, name: "", preview: "/car-2.png", colorSelected: null, }, ]); const palette = [ "#1E4E52", "#597E8D", "#6B6B6B", "#BEBEBE", "#E2E2E2", "#F4F4F4", "#FFFFFF", "#F9360A", "#9A2A00", "#7A1400", "#4B0200", "#B48B84", "#FFA598", ]; const handleAddSpec = () => { setSpecs((prev) => [ ...prev, { id: prev.length + 1, title: "", images: [], }, ]); }; const handleAddColor = () => { setColors((p) => [ ...p, { id: p.length + 1, name: "", preview: "/car-default.png", colorSelected: null, }, ]); }; const [isUploadDialogOpen, setIsUploadDialogOpen] = useState(false); const [uploadTarget, setUploadTarget] = useState<{ type: "spec" | "color"; index: number; } | null>(null); const fileInputId = "file-upload-input"; const handleFileSelected = (event: React.ChangeEvent) => { const file = event.target.files?.[0]; if (!file || !uploadTarget) return; const reader = new FileReader(); reader.onload = () => { const fileUrl = reader.result as string; if (uploadTarget.type === "spec") { setSpecs((prev) => { const updated = [...prev]; updated[uploadTarget.index].images.push(fileUrl); return updated; }); } if (uploadTarget.type === "color") { setColors((prev) => { const updated = [...prev]; updated[uploadTarget.index].preview = fileUrl; return updated; }); } }; reader.readAsDataURL(file); setIsUploadDialogOpen(false); }; return ( <> Edit Produk
{colors.map((item, index) => (
{palette.map((colorCode) => (
car color
))}
{specs.map((spec, index) => (
{spec.images.map((img, i) => ( spec ))}
))}
Upload File
document.getElementById(fileInputId)?.click()} >

Klik untuk upload atau drag & drop

PNG, JPG (max 2 MB)

); }