"use client"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Upload } from "lucide-react"; import { useState, useRef } from "react"; import { createGalery } from "@/service/galery"; export function GaleriDialog({ open, onClose, onSubmit }: any) { const [title, setTitle] = useState(""); const [desc, setDesc] = useState(""); const [file, setFile] = useState(null); const fileRef = useRef(null); const handleSubmit = async () => { if (!file) { alert("File wajib diupload!"); return; } const form = new FormData(); form.append("gallery_id", "1"); // nilai default (bisa dinamis) form.append("title", title); form.append("desc", desc); form.append("file", file); try { const res = await createGalery(form); console.log("Upload Success:", res?.data); onSubmit(); // tutup dialog } catch (error: any) { console.error("Upload failed:", error); alert("Gagal mengupload file"); } }; const handleFileChange = (e: any) => { const selected = e.target.files[0]; if (selected) setFile(selected); }; return ( {/* Header */}
Tambah Galeri
{/* Judul */}
setTitle(e.target.value)} />
{/* Deskripsi */}
setDesc(e.target.value)} />
{/* Upload */}
fileRef.current?.click()} >

Klik untuk upload atau drag & drop

PNG, JPG (max 2MB)

{file && (

File dipilih: {file.name}

)}
{/* Footer */}
); }