import { formatDateToIndonesian, shimmer, toBase64 } from "@/utils/globals"; import React, { useEffect, useState } from "react"; import "swiper/css/bundle"; import "swiper/css/navigation"; import { getHeroData, 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, Pagination } from "swiper/modules"; import { Swiper, SwiperSlide } from "swiper/react"; import "swiper/css"; import "swiper/css/pagination"; import FormSurvey from "./survey"; const HeroModal = ({ onClose }: { onClose: () => void }) => { const [heroData, setHeroData] = useState(); const params = useParams(); const locale = params?.locale; 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 getHeroData(); console.log(response); let data = response?.data?.data?.content; if (data) { const resStatic = await listStaticBanner(); 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); } setHeroData(data); } }; return (
{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 SurveyIntroModal = ({ onNext }: { onNext: () => void }) => { return (
Survey Illustration
); }; const ONE_MONTH = 30 * 24 * 60 * 60 * 1000; const Hero = (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(() => { 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(); console.log(response); let data = response?.data?.data?.content; setHeroData(response?.data?.data?.content); 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 : "" ); 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)} />} {showSurveyModal && !showFormModal && ( { setShowSurveyModal(false); setShowFormModal(true); }} /> )} {/* {showFormModal && } */}
{isLoading ? (
) : ( {content?.map((list: any) => (
gambar-utama
{list?.categoryName || "Liputan Kegiatan"}

{list?.title}

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

))}
)}
{isLoading ? ( <>
) : (
    Nasional Polda Satker {heroData?.map((item: any) => (
  • {item?.title}
    {item?.categoryName}

    {item?.title}

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

  • ))}
    {heroData ?.filter((item: any) => item.isPublishOnPolda === true) .map((item: any, index: any) => (
  • {item?.title}
    {item?.categoryName}

    {item?.title}

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

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

    {item?.title}

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

  • ))}
)}
); }; export default Hero;