diff --git a/components/form/content/spit-convert-form.tsx b/components/form/content/spit-convert-form.tsx index ec3f894e..b7ac6950 100644 --- a/components/form/content/spit-convert-form.tsx +++ b/components/form/content/spit-convert-form.tsx @@ -559,7 +559,6 @@ export default function FormConvertSPIT() { break; } } - return temp; }; @@ -609,7 +608,8 @@ export default function FormConvertSPIT() { icon: "success", confirmButtonColor: "#3085d6", }).then(() => { - router.push("/in/contributor/content/spit"); + // router.push("/in/contributor/content/spit"); + router.replace(`${window.location.pathname}?id=${id}`); }); } catch (error) { console.error("Failed to save:", error); diff --git a/components/landing-page/hero-new-polda.tsx b/components/landing-page/hero-new-polda.tsx index 4ad07e2d..8ab1e9da 100644 --- a/components/landing-page/hero-new-polda.tsx +++ b/components/landing-page/hero-new-polda.tsx @@ -2,7 +2,12 @@ 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 { + getHeroData, + getListContent, + listPopUp, + listStaticBanner, +} from "@/service/landing/landing"; import Link from "next/link"; import { useParams, usePathname, useRouter } from "next/navigation"; import { @@ -29,22 +34,183 @@ type HeroModalProps = { 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 HeroModal = ({ onClose, group, poldaName, satkerName, }: HeroModalProps) => { - const [heroData, setHeroData] = useState(); + 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(); - }, []); - - useEffect(() => { document.body.classList.add("overflow-hidden"); return () => { @@ -53,29 +219,35 @@ const HeroModal = ({ }, []); const initFetch = async () => { - if (group === "polda" && poldaName && String(poldaName).length > 1) { - const response = await listStaticBanner(poldaName, locale == "en"); + 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 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([]); + const handleClickOutside = (event: React.MouseEvent) => { + if (modalRef.current && !modalRef.current.contains(event.target as Node)) { + onClose(); } }; return ( -
-
+
+
{heroData?.length > 0 && ( <> - - {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} -

-
-
-
- )) - ) : ( -
+ {heroData.map((list: any) => ( + +
+ gambar-utama +
+
+ + {list?.categoryName || "Liputan Kegiatan"} + + +

{list?.title}

+ +

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

+
- )} -
- + + ))} +// +//
+//
+// ); +// }; + +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(() => { - async function fetchCategories() { - const url = "https://mediahub.polri.go.id/api/v2/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 () => { @@ -68,80 +208,117 @@ const HeroModal = ({ onClose, group, poldaName, satkerName }: HeroModalProps) => }, []); const initFetch = async () => { - if (group === "satker" && satkerName && String(satkerName).length > 1) { - const response = await listStaticBanner(satkerName, locale == "en"); + 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 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([]); + 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 && 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 + (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} +

+
- )} -
- + + ))}