"use client"; import { useState } from "react"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, DialogClose, } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { UploadCloud, Check } from "lucide-react"; import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; import router from "next/router"; import { useRouter } from "next/navigation"; import withReactContent from "sweetalert2-react-content"; import Swal from "sweetalert2"; interface BannerDialogProps { open: boolean; onOpenChange: (open: boolean) => void; onSubmit?: (data: any) => void; onSuccess?: () => void; } export function BannerDialog({ open, onOpenChange, onSubmit, onSuccess, }: BannerDialogProps) { const [selectedOrder, setSelectedOrder] = useState(1); const [file, setFile] = useState(null); const [title, setTitle] = useState(""); const router = useRouter(); const MySwal = withReactContent(Swal); const handleFileChange = (e: any) => { const selected = e.target.files[0]; if (selected) setFile(selected); }; const successSubmit = () => { MySwal.fire({ title: "Sukses", icon: "success", confirmButtonColor: "#3085d6", confirmButtonText: "OK", }).then((result) => { if (result.isConfirmed) { router.refresh(); } }); }; const handleSubmit = async () => { if (!title || !file || !selectedOrder) return; const formData = new FormData(); formData.append("title", title); formData.append("position", selectedOrder.toString()); formData.append("description", "hardcode description dulu"); formData.append("status", "1"); formData.append("thumbnail_path", "path-hardcode.png"); formData.append("file", file); if (onSubmit) { await onSubmit(formData); successSubmit(); } onOpenChange(false); }; const orderOptions = [ { id: 1, label: "Pertama" }, { id: 2, label: "Kedua" }, { id: 3, label: "Ketiga" }, { id: 4, label: "Keempat" }, { id: 5, label: "Kelima" }, ]; return ( {/* Header */} Tambah Banner {/* Body */}
{/* Judul Banner */}
setTitle(e.target.value)} />
{/* Upload File */}
{/* Urutan Banner */}
{orderOptions.map((opt) => ( ))}
{/* Footer */}
); }