From abdd4c0f67e45480157e7892ee7134b7afd98c1f Mon Sep 17 00:00:00 2001 From: Anang Yusman Date: Sun, 25 May 2025 16:03:04 +0800 Subject: [PATCH] [QUDO-96,QUDO-101,QUDO-100]feat:update --- .../agenda-setting/event-modal.tsx | 79 +++++++----------- .../form/communication/collaboration-form.tsx | 3 + components/form/content/image-detail-form.tsx | 2 +- .../landing-page/header-banner-satker.tsx | 80 +++++++++++++++---- components/landing-page/hero-new.tsx | 44 ++++++++-- lib/menus.ts | 12 +-- 6 files changed, 146 insertions(+), 74 deletions(-) diff --git a/app/[locale]/(protected)/contributor/agenda-setting/event-modal.tsx b/app/[locale]/(protected)/contributor/agenda-setting/event-modal.tsx index b65789cb..89b2fb3b 100644 --- a/app/[locale]/(protected)/contributor/agenda-setting/event-modal.tsx +++ b/app/[locale]/(protected)/contributor/agenda-setting/event-modal.tsx @@ -210,45 +210,6 @@ const EventModal = ({ fetchDetailData(); }, [event, setValue]); - // useEffect(() => { - // async function fetchPoldaPolres() { - // setIsLoading(true); - // try { - // const response = await getUserLevelForAssignments(); - // const levelList = response?.data?.data.list; - // let listFiltered = []; - // if (agendaType == "polda") { - // listFiltered = levelList.filter( - // (level: any) => level.name != "SATKER POLRI" - // ); - // } else if (agendaType == "polres") { - // listFiltered = levelList.filter( - // (level: any) => level.name != "SATKER POLRI" - // ); - // } else if (agendaType == "satker") { - // listFiltered = levelList.filter( - // (level: any) => level.name == "SATKER POLRI" - // ); - // } - // setListDest(listFiltered); - // const initialExpandedState = listFiltered.reduce( - // (acc: any, polda: any) => { - // acc[polda.id] = false; - // return acc; - // }, - // {} - // ); - // setExpandedPolda(initialExpandedState); - // } catch (error) { - // console.error("Error fetching Polda/Polres data:", error); - // } finally { - // setIsLoading(false); - // } - // } - - // fetchPoldaPolres(); - // }, [agendaType]); - const handleCheckboxChange = (levelId: number) => { setCheckedLevels((prev) => { const updatedLevels = new Set(prev); @@ -261,6 +222,15 @@ const EventModal = ({ }); }; + const wilayahValueMap: Record = { + semua: "0", + nasional: "1", + polda: "2", + polres: "3", + satker: "4", + international: "5", + }; + const toggleWilayah = (key: string) => { setWilayahPublish((prev: any) => { const newState = { ...prev, [key]: !prev[key] }; @@ -296,20 +266,33 @@ const EventModal = ({ }; const save = async (data: any, publish = false) => { - const publishTo = []; - if (wilayahPublish.semua) publishTo.push("all"); - if (wilayahPublish.nasional) publishTo.push("mabes"); - if (wilayahPublish.polda) publishTo.push(...selectedPolda); - if (wilayahPublish.polres) publishTo.push(...selectedPolres); - if (wilayahPublish.satker) publishTo.push(...selectedSatker); - if (wilayahPublish.international) publishTo.push("international"); + const agendaTypeList: string[] = []; + const assignedToLevelList: string[] = []; + + // Mapping dari checkbox wilayah ke agendaType + Object.keys(wilayahPublish).forEach((key) => { + if (wilayahPublish[key as keyof typeof wilayahPublish]) { + agendaTypeList.push(wilayahValueMap[key]); + } + }); + + // Unit-unit berdasarkan wilayah yang aktif + if (wilayahPublish.polda && selectedPolda.length > 0) { + assignedToLevelList.push(...selectedPolda); + } + if (wilayahPublish.polres && selectedPolres.length > 0) { + assignedToLevelList.push(...selectedPolres); + } + if (wilayahPublish.satker && selectedSatker.length > 0) { + assignedToLevelList.push(...selectedSatker); + } const reqData = { id: detailData?.id, title: data.title, description: data.description, - agendaType, // Include agendaType in request - publishTo, + agendaType: agendaTypeList.join(","), // <-- ubah array jadi string + assignedToLevel: assignedToLevelList.join(","), // <-- ubah array jadi string startDate: format(startDate, "yyyy-MM-dd"), endDate: format(endDate, "yyyy-MM-dd"), }; diff --git a/components/form/communication/collaboration-form.tsx b/components/form/communication/collaboration-form.tsx index 7f1ccbce..bff74be5 100644 --- a/components/form/communication/collaboration-form.tsx +++ b/components/form/communication/collaboration-form.tsx @@ -161,6 +161,9 @@ export default function FormCollaboration() { title: data.title, narration: data.naration, target: selectedTarget, + isCollaboration: true, + isEscalation: true, + isCollaborationWithNoneTicket: true, sendToId: selectedOption?.id, // This should work now without the error }; diff --git a/components/form/content/image-detail-form.tsx b/components/form/content/image-detail-form.tsx index 657fafe6..6380d7f3 100644 --- a/components/form/content/image-detail-form.tsx +++ b/components/form/content/image-detail-form.tsx @@ -711,7 +711,7 @@ export default function FormImageDetail() { )} - + {t("leave-comment")} diff --git a/components/landing-page/header-banner-satker.tsx b/components/landing-page/header-banner-satker.tsx index ca46ffb0..76e3af14 100644 --- a/components/landing-page/header-banner-satker.tsx +++ b/components/landing-page/header-banner-satker.tsx @@ -4,9 +4,19 @@ import { useParams, usePathname, useRouter } from "next/navigation"; import React, { useEffect, useState } from "react"; import Skeleton, { SkeletonTheme } from "react-loading-skeleton"; import { Link } from "@/i18n/routing"; -import { formatDateToIndonesian, getPublicLocaleTimestamp, textEllipsis } from "@/utils/globals"; +import { + formatDateToIndonesian, + getPublicLocaleTimestamp, + textEllipsis, +} from "@/utils/globals"; import { Icon } from "@iconify/react/dist/iconify.js"; -import { Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious } from "@/components/ui/carousel"; +import { + Carousel, + CarouselContent, + CarouselItem, + CarouselNext, + CarouselPrevious, +} from "@/components/ui/carousel"; import Image from "next/image"; const HeaderBannerSatker = () => { @@ -27,7 +37,17 @@ const HeaderBannerSatker = () => { // } async function fetchData() { - const res = await listData("1", "", "", 5, 0, "createdAt", "", "", "satker-" + satkerName); + const res = await listData( + "1", + "", + "", + 5, + 0, + "createdAt", + "", + "", + "satker-" + satkerName + ); var data = res?.data?.data?.content; if (data) { const resStatic = await listStaticBanner(satkerName, false); @@ -96,13 +116,25 @@ const HeaderBannerSatker = () => { {content?.map((row: any) => (
- +
- {row?.categoryName} + + {row?.categoryName} + {

{row.title}

- {getPublicLocaleTimestamp(new Date(row?.createdAt))} WIB {" | "} - {row?.clickCount} + {getPublicLocaleTimestamp(new Date(row?.createdAt))} WIB{" "} + {" | "} + {" "} + {row?.clickCount}

@@ -171,14 +205,24 @@ const HeaderBannerSatker = () => { {content?.map((item: any) => (
  • - {item?.title} + {item?.title}
    - {item?.categoryName} + + {item?.categoryName} + { : `/audio/detail/${item?.slug}` } > -

    {textEllipsis(item?.title, 30)}

    +

    + {textEllipsis(item?.title, 30)} +

    - {formatDateToIndonesian(new Date(item?.createdAt))} {item?.timezone ? item?.timezone : "WIB"} |{" "} - + {formatDateToIndonesian(new Date(item?.createdAt))}{" "} + {item?.timezone ? item?.timezone : "WIB"} |{" "} + void }) => { +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; @@ -79,9 +91,29 @@ const HeroModal = ({ onClose }: { onClose: () => void }) => { }, []); const initFetch = async () => { - const response = await getHeroData(); - console.log(response); - setHeroData(response?.data?.data?.content); + // Ambil data banner dari API listStaticBanner + const response = await listStaticBanner( + group === "mabes" + ? "" + : group === "polda" && poldaName && String(poldaName)?.length > 1 + ? poldaName + : group === "satker" && satkerName && String(satkerName)?.length > 1 + ? "satker-" + satkerName + : "" + ); + + // Ambil dan bersihkan data media dari response + 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); // hanya data dari listStaticBanner }; return (

    @@ -293,7 +325,9 @@ const HeroNew = (props: { group?: string }) => { return (
    - {showModal && setShowModal(false)} />} + {showModal && ( + setShowModal(false)} group="mabes" /> + )} {/* {showFormModal && } */}
    diff --git a/lib/menus.ts b/lib/menus.ts index 75b33f17..9f85a4ea 100644 --- a/lib/menus.ts +++ b/lib/menus.ts @@ -3146,16 +3146,16 @@ export function getMenuList(pathname: string, t: any): Group[] { icon: "material-symbols:map-search-outline", submenus: [ { - href: "/admin/media-tracking/media-online", - label: "Media Online", - active: pathname === "/admin/media-tracking/media-online", + href: "/admin/media-tracking", + label: "Tracking Beritra Hari Ini", + active: pathname === "/admin/media-tracking", icon: "heroicons:arrow-trending-up", children: [], }, { - href: "/admin/media-tracking", - label: "Tracking Beritra Hari Ini", - active: pathname === "/admin/media-tracking", + href: "/admin/media-tracking/media-online", + label: "Media Online", + active: pathname === "/admin/media-tracking/media-online", icon: "heroicons:arrow-trending-up", children: [], },