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, listStaticBanner } from "@/service/landing/landing"; import Link from "next/link"; 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 { 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"; 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); useEffect(() => { initFetch(); }, []); useEffect(() => { document.body.classList.add("overflow-hidden"); return () => { document.body.classList.remove("overflow-hidden"); }; }, []); const initFetch = async () => { if (group === "polda" && poldaName && String(poldaName).length > 1) { const response = await listStaticBanner(poldaName, locale == "en"); const banners = response?.data?.data?.map((item: any) => { const media = item?.mediaUpload; if (media?.fileType) { media.fileTypeId = media.fileType.id; } return media; }) || []; console.log("banner Modal", banners); setHeroData(banners); } else { console.log("Test"); setHeroData([]); } }; return (
{heroData?.length > 0 && ( <> )} (swiperRef.current = swiper)} autoplay={{ delay: 3000 }} className="mySwiper w-full" >
{heroData && heroData.length > 0 ? ( heroData.map((list: any, index: number) => (
gambar-utama
{list?.categoryName || "Liputan Kegiatan"}

{list?.title}

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

)) ) : (
empty
)}
); }; const ONE_MONTH = 30 * 24 * 60 * 60 * 1000; const HeroNewPolda = (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"); 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(() => { initFetch(); }, []); const initFetch = async () => { 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); let data = response?.data?.data?.content; if ( data && props.group === "polda" && poldaName && String(poldaName)?.length > 1 ) { const resStatic = await listStaticBanner(poldaName, locale == "en"); for (let i = 0; i < resStatic?.data?.data?.length; i++) { const media = resStatic?.data.data[i]?.mediaUpload; media.fileTypeId = media.fileType?.id; data = data.filter((item: any) => item.id != media.id); data.splice(0, 0, media); } setContent(data); } }; 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); setNewContent(response?.data?.data?.content); }; 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="polda" /> )}
{isLoading ? (
) : (
{content?.map((list: any) => (
gambar-utama
{list?.categoryName || "Liputan Kegiatan"}

{list?.title}

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

))}
{newContent?.slice(0, 3).map((item: any) => (
  • {item?.title}
    {item?.categoryName}

    {item?.title}

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

  • ))}
    )}
    ); }; export default HeroNewPolda;