"use client"; import { useState, useEffect } from "react"; import { format } from "date-fns"; import { Calendar } from "@/components/ui/calendar"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { CalendarIcon, ChevronRight } from "lucide-react"; import { cn } from "@/lib/utils"; import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem, } from "@/components/ui/select"; import { Badge } from "@/components/ui/badge"; import { getAllSchedules } from "@/service/landing/landing"; import { getPublicClients } from "@/service/client/public-clients"; export default function Schedule() { const [search, setSearch] = useState(""); const [startDate, setStartDate] = useState(new Date()); const [endDate, setEndDate] = useState(new Date()); const [selectedCategory, setSelectedCategory] = useState("SEMUA"); const [selectedSlug, setSelectedSlug] = useState( undefined ); const [scheduleData, setScheduleData] = useState([]); const [clients, setClients] = useState([]); const [loading, setLoading] = useState(false); // 🔹 Fetch daftar client useEffect(() => { async function fetchClients() { try { const res = await getPublicClients(); if (res?.data?.success && res.data.data) { setClients(res.data.data); } else { setClients([]); } } catch (error) { console.error("Error fetching clients:", error); setClients([]); } } fetchClients(); }, []); // 🔹 Fetch jadwal dari API (termasuk clientSlug) const fetchSchedules = async () => { try { setLoading(true); const params = { title: search || undefined, startDate: startDate ? format(startDate, "yyyy-MM-dd") : undefined, endDate: endDate ? format(endDate, "yyyy-MM-dd") : undefined, clientSlug: selectedSlug, // 🔥 Tambahkan clientSlug untuk filter page: 1, limit: 50, sortBy: "startDate", sort: "asc", }; const res = await getAllSchedules(params); if (!res.error) { const apiData = Array.isArray(res.data) ? res.data : Array.isArray(res.data?.data) ? res.data.data : Array.isArray(res.data?.records) ? res.data.records : []; setScheduleData(apiData); } else { console.error("Gagal memuat jadwal:", res.message); setScheduleData([]); } } catch (error) { console.error("Error fetching schedules:", error); setScheduleData([]); } finally { setLoading(false); } }; // 🔹 Re-fetch setiap kali filter berubah useEffect(() => { fetchSchedules(); }, [startDate, endDate, search, selectedSlug]); return (
{/* Filter Bar */}
setSearch(e.target.value)} /> {/* Tanggal Mulai */}
{/* Tanggal Selesai */}
{/* 🔹 Dynamic Category dari API */}
{clients.map((client) => ( ))}
{/* Schedule Table */}

Semua Jadwal

{loading ? (
Memuat data jadwal...
) : scheduleData.length === 0 ? (
Tidak ada jadwal ditemukan.
) : (
{scheduleData.map((item, index) => (
{item.startDate ? ( <> {format(new Date(item.startDate), "dd MMM yyyy")} {item.endDate && item.endDate !== item.startDate && ` — ${format(new Date(item.endDate), "dd MMM yyyy")}`} ) : ( "-" )}
{item.startTime && item.endTime ? ( <> {item.startTime.slice(0, 5)} – {item.endTime.slice(0, 5)} ) : item.startTime ? ( item.startTime.slice(0, 5) ) : ( "" )}
{/* Client */}
{item.clientName || "-"}
{/* Judul & Lokasi */}
{item.title}
{item.location}
))}
)}
); } // "use client"; // import { useState } from "react"; // import { format } from "date-fns"; // import { Calendar } from "@/components/ui/calendar"; // import { // Popover, // PopoverContent, // PopoverTrigger, // } from "@/components/ui/popover"; // import { Button } from "@/components/ui/button"; // import { Input } from "@/components/ui/input"; // import { CalendarIcon, ChevronRight } from "lucide-react"; // import { cn } from "@/lib/utils"; // import { // Select, // SelectTrigger, // SelectValue, // SelectContent, // SelectItem, // } from "@/components/ui/select"; // import { Badge } from "@/components/ui/badge"; // const scheduleData = [ // { // date: "Jul 1 2025", // type: "POLRI", // title: "HUT Bhayangkara RI - 79", // location: "Mabes Polri, Jakarta, Indonesia", // }, // { // date: "Jul 1 2025", // type: "POLRI", // title: "Hari Lahir Pancasila", // location: "Mabes Polri, Jakarta, Indonesia", // }, // { // date: "Jul 1 2025", // type: "POLRI", // title: "Pers Rilis Kasus", // location: "Mabes Polri, Jakarta, Indonesia", // }, // { // date: "Jul 1 2025", // type: "POLRI", // title: "Rapat Koordinasi HUT Bhayangkara RI - 79", // location: "Mabes Polri, Jakarta, Indonesia", // }, // { // date: "Jul 1 2025", // type: "MPR", // title: "Rapat PIMPINAN MPR RI", // location: "Gedung MPR, Jakarta, Indonesia", // }, // { // date: "Jul 1 2025", // type: "DPR", // title: "Rapat Anggota Komisi I", // location: "Gedung DPR, Jakarta, Indonesia", // }, // { // date: "Jul 1 2025", // type: "MPR", // title: "Sidang Paripurna", // location: "Gedung MPR, Jakarta, Indonesia", // }, // { // date: "Jul 1 2025", // type: "KEJAKSAAN AGUNG", // title: "Hari Lahir Pancasila", // location: "Kejaksaan Agung, Jakarta, Indonesia", // }, // { // date: "Jul 1 2025", // type: "KPU", // title: "Hari Lahir Pancasila", // location: "Kantor KPU, Jakarta Indonesia", // }, // { // date: "Jul 1 2025", // type: "DPR", // title: "Rapat Anggota Komisi II", // location: "Gedung DPR, Jakarta, Indonesia", // }, // { // date: "Jul 1 2025", // type: "MPR", // title: "Rapat DPR dan Basarnas", // location: "Gedung MPR, Jakarta, Indonesia", // }, // { // date: "Jul 1 2025", // type: "BUMN", // title: "Hari Lahir Pancasila", // location: "Kantor BUMN, Jakarta Indonesia", // }, // { // date: "Jul 1 2025", // type: "BUMN", // title: "Focus Group Discussion", // location: "Kantor BUMN, Jakarta Indonesia", // }, // { // date: "Jul 1 2025", // type: "MPR", // title: "Rapat Anggota MPR RI", // location: "Gedung MPR, Jakarta, Indonesia", // }, // { // date: "Jul 1 2025", // type: "BUMN", // title: "Seremoni Sinergi BUMN", // location: "Kantor BUMN, Jakarta Indonesia", // }, // { // date: "Jul 1 2025", // type: "MPR", // title: "Sumpah Janji Anggota MPR RI", // location: "Gedung MPR, Jakarta, Indonesia", // }, // { // date: "Jul 1 2025", // type: "KPK", // title: "Hari Lahir Pancasila", // location: "Kantor KPK, Jakarta Indonesia", // }, // { // date: "Jul 1 2025", // type: "BUMN", // title: "Monitoring dan Evaluasi Keterbukaan Informasi Publik Tahun 2025", // location: "Kantor BUMN, Jakarta Indonesia", // }, // { // date: "Jul 1 2025", // type: "KEJAKSAAN AGUNG", // title: "Hari Lahir Pancasila", // location: "Kejaksaan Agung, Jakarta, Indonesia", // }, // { // date: "Jul 2 2025", // type: "MPR", // title: "Monitoring dan Evaluasi Informasi MPR Tahun 2025", // location: "Gedung MPR, Jakarta, Indonesia", // }, // ]; // const categories = [ // "SEMUA", // "POLRI", // "MAHKAMAH AGUNG", // "DPR", // "MPR", // "KEJAKSAAN AGUNG", // "KPK", // "PUPR", // "BSKDN", // "BUMN", // "KPU", // ]; // export default function Schedule() { // const [search, setSearch] = useState(""); // const [startDate, setStartDate] = useState( // new Date("2025-07-01") // ); // const [endDate, setEndDate] = useState( // new Date("2025-07-30") // ); // const [selectedCategory, setSelectedCategory] = useState("SEMUA"); // const filteredData = scheduleData.filter((item) => { // const matchesCategory = // selectedCategory === "SEMUA" || item.type === selectedCategory; // const matchesSearch = item.title // .toLowerCase() // .includes(search.toLowerCase()); // return matchesCategory && matchesSearch; // }); // return ( //
// {/* Filter Bar */} //
// setSearch(e.target.value)} // /> // {/* Tanggal Mulai */} //
// // // // // // // // // //
// {/* Tanggal Selesai */} //
// // // // // // // // // //
// {/* Publikasi */} //
// // //
//
// {/* Filter Chips */} //
// {categories.map((cat) => ( // // ))} // //
// {/* Schedule Table */} //

// Semua Jadwal //

//
// {filteredData.map((item, index) => ( //
//
// {item.date} //
//
// // {item.type} // //
//
{item.title}
//
// {item.location} //
//
// ))} //
//
// // //
//
// ); // }