import { formatDateToIndonesian, shimmer, toBase64 } from "@/utils/globals"; import React, { useEffect, useRef, useState } from "react"; import "swiper/css/bundle"; import "swiper/css/navigation"; import { getHeroData, getListContent, listPopUp, listStaticBanner, } from "@/service/landing/landing"; import { useParams, usePathname, useRouter } from "next/navigation"; import { Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious, } from "@/components/ui/carousel"; import { Skeleton } from "../ui/skeleton"; import Image from "next/image"; import Cookies from "js-cookie"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "../ui/tabs"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "../ui/card"; import { Label } from "../ui/label"; import { Input } from "../ui/input"; import { Button } from "../ui/button"; import { Textarea } from "../ui/textarea"; import { Checkbox } from "../ui/checkbox"; import { Dialog, DialogClose, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "../ui/dialog"; import { Autoplay, Navigation, Pagination } from "swiper/modules"; import { Swiper, SwiperClass, SwiperSlide } from "swiper/react"; import "swiper/css"; import "swiper/css/navigation"; import "swiper/css/pagination"; import { ChevronLeft, ChevronRight } from "lucide-react"; import { Link } from "@/i18n/routing"; import { listBannerHero } from "@/service/settings/settings"; type HeroModalProps = { onClose: () => void; group: string; poldaName?: string; satkerName?: string; }; const HeroModal = ({ onClose, group, poldaName, satkerName, }: HeroModalProps) => { const [heroData, setHeroData] = useState(); const params = useParams(); const locale = params?.locale; const swiperRef = useRef(null); const pathname = usePathname(); if (pathname?.includes("/polda") || pathname?.includes("/satker")) { return null; } let prefixPath = poldaName ? `/polda/${poldaName}` : satkerName ? `/satker/${satkerName}` : ""; useEffect(() => { async function fetchCategories() { const url = "https://netidhub.com/api/csrf"; try { const response = await fetch(url); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); return data; } catch (error) { console.error("Fetch error: ", error); } } fetchCategories(); initFetch(); }, []); useEffect(() => { document.body.classList.add("overflow-hidden"); return () => { document.body.classList.remove("overflow-hidden"); }; }, []); const initFetch = async () => { const response = await listPopUp( group === "mabes" ? "" : group === "polda" && poldaName && String(poldaName)?.length > 1 ? poldaName : group === "satker" && satkerName && String(satkerName)?.length > 1 ? "satker-" + satkerName : "", locale == "en" ); const banners = response?.data?.data || []; console.log("banner Modal", banners); setHeroData(banners); }; return (
{heroData?.length > 0 && ( <> )} (swiperRef.current = swiper)} autoplay={{ delay: 3000 }} className="mySwiper w-full" > {heroData?.map((list: any, index: number) => (
gambar-utama
{list?.categoryName || "Liputan Kegiatan"}

{list?.title}

{formatDateToIndonesian(new Date(list?.createdAt))}{" "} {list?.timezone || "WIB"} |{" "} {list?.clickCount}

))}
); }; const ONE_MONTH = 30 * 24 * 60 * 60 * 1000; const HeroNew = (props: { group?: string }) => { const router = useRouter(); const pathname = usePathname(); const params = useParams(); const locale = params?.locale; const [isLoading, setIsLoading] = useState(true); const [heroData, setHeroData] = useState(); const [content, setContent] = useState(); const [showModal, setShowModal] = useState(false); const [showSurveyModal, setShowSurveyModal] = useState(false); const [showFormModal, setShowFormModal] = useState(false); const poldaName = params?.polda_name; const satkerName = params?.satker_name; const [newContent, setNewContent] = useState(); const [selectedTab, setSelectedTab] = useState("image"); let prefixPath = poldaName ? `/polda/${poldaName}` : satkerName ? `/satker/${satkerName}` : ""; useEffect(() => { fecthNewContent(); }, [selectedTab]); const fecthNewContent = async () => { console.log("Satker Name : ", satkerName); const request = { title: "", page: 0, size: 5, sortBy: "createdAt", contentTypeId: selectedTab == "image" ? "1" : selectedTab == "video" ? "2" : selectedTab == "text" ? "3" : selectedTab == "audio" ? "4" : "", group: props.group == "mabes" ? "" : props.group == "polda" && poldaName && String(poldaName)?.length > 1 ? poldaName : props.group == "satker" && satkerName && String(satkerName)?.length > 1 ? "satker-" + satkerName : "", isInt: locale == "en" ? true : false, }; const response = await getListContent(request); console.log("category", response); setNewContent(response?.data?.data?.content); }; useEffect(() => { const timer = setTimeout(() => { setIsLoading(false); }, 3000); return () => clearTimeout(timer); }, []); // useEffect(() => { // const roleId = Cookies.get("urie"); // if (!roleId) { // setShowModal(true); // } // initFetch(); // }, []); // useEffect(() => { // const roleId = Cookies.get("urie"); // const lastShown = Cookies.get("surveyLastShown"); // const now = new Date().getTime(); // if (roleId && roleId !== "2") { // if (!lastShown || now - parseInt(lastShown) > ONE_MONTH) { // setShowSurveyModal(true); // Cookies.set("surveyLastShown", now.toString(), { expires: 30 }); // } // } // initFetch(); // }, []); useEffect(() => { const roleId = Cookies.get("urie"); const lastShown = Cookies.get("surveyLastShown"); const now = new Date().getTime(); const allowedRoles = ["1", "2", "3"]; if (roleId && allowedRoles.includes(roleId)) { if (!lastShown || now - parseInt(lastShown) > ONE_MONTH) { setShowSurveyModal(true); Cookies.set("surveyLastShown", now.toString(), { expires: 30 }); } } initFetch(); }, []); useEffect(() => { async function fetchCategories() { const url = "https://netidhub.com/api/csrf"; try { const response = await fetch(url); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); return data; } catch (error) { console.error("Fetch error: ", error); } } fetchCategories(); initFetch(); }, []); const initFetch = async () => { const response = await getHeroData(locale == "en"); console.log(response); let data = response?.data?.data?.content; setHeroData(data); if (data) { const resStatic = await listStaticBanner( props.group == "mabes" ? "" : props.group == "polda" && poldaName && String(poldaName)?.length > 1 ? poldaName : props.group == "satker" && satkerName && String(satkerName)?.length > 1 ? "satker-" + satkerName : "", locale == "en" ); for (let i = 0; i < resStatic?.data?.data?.length; i++) { const media = resStatic?.data.data[i]?.mediaUpload; if (!media) continue; media.fileTypeId = media?.fileType?.id ?? null; data = data.filter((item: any) => item.id != media.id); data.splice(0, 0, media); } setContent(data); } }; const shimmer = (w: number, h: number) => ` `; const toBase64 = (str: string) => typeof window === "undefined" ? Buffer.from(str).toString("base64") : window.btoa(str); return (
{showModal && ( setShowModal(false)} group="mabes" /> )}
{isLoading ? (
) : (
{content?.map((list: any) => (
{/* Gambar */} gambar {/* Overlay hitam transparan */}
{/* Konten judul, dll */} {list?.categoryName}

{list?.title}

{formatDateToIndonesian(new Date(list?.createdAt))}{" "} {list?.timezone || "WIB"} | 👁 {list?.clickCount}

{/* Tombol navigasi di atas gambar */}
))}
{content?.slice(0, 3).map((item: any) => (
  • {item?.title}

    {item?.categoryName}

    {item?.title}

    {formatDateToIndonesian(new Date(item?.createdAt))}{" "} {item?.timezone || "WIB"} |{" "} {" "} {item?.clickCount}

  • ))}
    )}
    ); }; export default HeroNew;