jaecoo-cihampelas/app/(admin)/admin/galery/page.tsx

64 lines
1.9 KiB
TypeScript

"use client";
import { useEffect, useState } from "react";
import Link from "next/link";
import { Button } from "@/components/ui/button";
import { Plus } from "lucide-react";
import Galery from "@/components/table/galery";
import { GaleriDialog } from "@/components/dialog/galery-dialog";
import { useRouter } from "next/navigation";
import withReactContent from "sweetalert2-react-content";
import Swal from "sweetalert2";
import Cookies from "js-cookie";
export default function GaleryPage() {
const [openDialog, setOpenDialog] = useState(false);
const [userLevelId, setUserLevelId] = useState<string | null>(null);
const router = useRouter();
const MySwal = withReactContent(Swal);
// 🔹 Ambil userlevelId dari cookies
useEffect(() => {
const ulne = Cookies.get("ulne"); // contoh: "3"
setUserLevelId(ulne ?? null);
}, []);
const handleSubmitGaleri = () => {
console.log("Submit galeri...");
setOpenDialog(false);
};
return (
<div>
<div className="overflow-x-hidden overflow-y-scroll w-full">
<div className="px-2 md:px-4 md:py-4 w-full">
<div className="pl-3">
<h1 className="text-[#1F6779] text-2xl font-semibold">Galeri</h1>
<p>Kelola Galeri JAECOO</p>
</div>
<div className="dark:bg-[#18181b] rounded-xl p-3">
{userLevelId !== "3" && (
<Button
className="bg-[#1F6779] text-white w-full lg:w-fit hover:bg-[#1a9bb5] flex items-center gap-2"
onClick={() => setOpenDialog(true)}
>
<Plus className="h-4 w-4" />
Tambah Galeri Baru
</Button>
)}
<Galery />
</div>
</div>
</div>
<GaleriDialog
open={openDialog}
onClose={() => setOpenDialog(false)}
onSubmit={handleSubmitGaleri}
/>
</div>
);
}