import { formatDateToIndonesian, shimmer, toBase64 } from "@/utils/globals"; import React, { useEffect, useRef, useState } from "react"; import "swiper/css/bundle"; import "swiper/css/navigation"; import { getHeroData, listPopUp, 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 { 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"; 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(() => { // async function fetchCategories() { // const url = "https://new.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 () => { // if (group === "satker" && satkerName && String(satkerName).length > 1) { // const response = await listStaticBanner(satkerName, 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 HeroModal = ({ onClose, group, poldaName, satkerName, }: HeroModalProps) => { const [heroData, setHeroData] = useState([]); const params = useParams(); const locale = params?.locale; const swiperRef = useRef(null); const pathname = usePathname(); const modalRef = useRef(null); let prefixPath = ""; if (group === "polda" && poldaName) { prefixPath = `/polda/${poldaName}`; } else if (group === "satker" && satkerName) { prefixPath = `/satker/${satkerName}`; } useEffect(() => { initFetch(); 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 // ? poldaName // : group === "satker" && satkerName // ? "satker-" + satkerName // : "", // locale == "en" // ); // const interstitial = response?.data?.data || []; // setHeroData(interstitial); // }; const initFetch = async () => { const response = await listStaticBanner( group === "mabes" ? "" : group === "polda" && poldaName ? poldaName : group === "satker" && satkerName ? "satker-" + satkerName : "", locale === "en" ); const banners = response?.data?.data || []; const enrichedData = banners.map((item: any) => ({ ...item, fileTypeId: item?.fileType?.id ?? null, })); setHeroData(enrichedData); }; const handleClickOutside = (event: React.MouseEvent) => { if (modalRef.current && !modalRef.current.contains(event.target as Node)) { onClose(); } }; return (
{heroData?.length > 0 && ( <> )} (swiperRef.current = swiper)} autoplay={{ delay: 3000 }} className="mySwiper w-full" > {heroData.map((list: any) => (
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 HeroNewSatker = (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; 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 response = await getHeroData(locale == "en"); console.log(response); let data = response?.data?.data?.content; setHeroData(data); if ( data && props.group === "satker" && satkerName && String(satkerName)?.length > 1 ) { const resStatic = await listStaticBanner(satkerName, 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); } }; 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="satker" /> )}
{isLoading ? (
) : (
{content?.map((list: any) => (
gambar-utama
{list?.categoryName || "Liputan Kegiatan"}

{list?.title}

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

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

    {item?.title}

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

  • ))}
    )}
    ); }; export default HeroNewSatker;