diff --git a/app/[locale]/(protected)/dashboard/page.tsx b/app/[locale]/(protected)/dashboard/page.tsx index 0f4d71f2..8770d2db 100644 --- a/app/[locale]/(protected)/dashboard/page.tsx +++ b/app/[locale]/(protected)/dashboard/page.tsx @@ -24,7 +24,7 @@ import ReportTable from "../contributor/report/components/report-table"; const DashboardPage = () => { const t = useTranslations("AnalyticsDashboard"); const roleId = getCookiesDecrypt("urie"); - const levelNumber = Number(getCookiesDecrypt("ulne")); + const levelNumber = getCookiesDecrypt("ulne"); return Number(roleId) == 2 || Number(roleId) == 11 || Number(roleId) == 12 ? (
@@ -55,7 +55,7 @@ const DashboardPage = () => { > {t("schedule", { defaultValue: "Schedule" })} - {levelNumber !== 3 && ( + {levelNumber !== "2" && ( <> { )} - + {t("report", { defaultValue: "Report" })} + + )} + {/* {t("report", { defaultValue: "Report" })} - + */} diff --git a/app/[locale]/(protected)/shared/curated-content/giat-routine/audio/audio.tsx b/app/[locale]/(protected)/shared/curated-content/giat-routine/audio/audio.tsx index 2aa076e5..afc763a9 100644 --- a/app/[locale]/(protected)/shared/curated-content/giat-routine/audio/audio.tsx +++ b/app/[locale]/(protected)/shared/curated-content/giat-routine/audio/audio.tsx @@ -19,6 +19,8 @@ import { Icon } from "@iconify/react/dist/iconify.js"; import { hasData } from "jquery"; import { useParams, usePathname, useRouter } from "next/navigation"; import React, { Component, useEffect, useState } from "react"; +import { listDataTracking } from "@/service/media-tracking/media-tracking"; // sesuaikan path +import { getCookiesDecrypt } from "@/lib/utils"; const AudioSliderPage = () => { const [audioData, setAudioData] = useState(); @@ -31,14 +33,47 @@ const AudioSliderPage = () => { initFetch(); }, [page, limit, search]); - const initFetch = async () => { - const response = await listCuratedContent(search, limit, page - 1, 4, "1"); - // console.log(response); + // const initFetch = async () => { + // const response = await listCuratedContent(search, limit, page - 1, 4, "1"); + // // console.log(response); - const data = response?.data?.data; - const contentData = data?.content; - setHasData(displayAudio && displayAudio.length > 0); - setDisplayAudio(contentData); + // const data = response?.data?.data; + // const contentData = data?.content; + // setHasData(displayAudio && displayAudio.length > 0); + // setDisplayAudio(contentData); + // }; + + const initFetch = async () => { + try { + const levelName = (getCookiesDecrypt("levelName") || "").toUpperCase(); + + const res = await listDataTracking( + limit, + page - 1, + search, + "", // category + "", // status + levelName, + "4", // ✅ AUDIO + ); + + const data = res?.data?.data?.content || []; + + console.log("AUDIO DATA:", data); + + const mapped = data.map((item: any) => ({ + id: item.id, + title: item.title, + createdAt: item.createdAt, + timezone: item.timezone, + clickCount: item.clickCount || 0, + })); + + setDisplayAudio(mapped); + setHasData(mapped.length > 0); + } catch (error) { + console.error("Error fetching audio:", error); + } }; const shuffleArray = (array: any[]) => { diff --git a/app/[locale]/(protected)/shared/curated-content/giat-routine/document/teks.tsx b/app/[locale]/(protected)/shared/curated-content/giat-routine/document/teks.tsx index 6cf83faf..b7fbb8dc 100644 --- a/app/[locale]/(protected)/shared/curated-content/giat-routine/document/teks.tsx +++ b/app/[locale]/(protected)/shared/curated-content/giat-routine/document/teks.tsx @@ -18,6 +18,8 @@ import { import { Icon } from "@iconify/react/dist/iconify.js"; import { useParams, usePathname, useRouter } from "next/navigation"; import React, { Component, useEffect, useState } from "react"; +import { listDataTracking } from "@/service/media-tracking/media-tracking"; // sesuaikan path +import { getCookiesDecrypt } from "@/lib/utils"; const TeksSliderPage = () => { const [documentData, setDocumentData] = useState(); @@ -31,14 +33,47 @@ const TeksSliderPage = () => { initFetch(); }, [page, limit, search]); - const initFetch = async () => { - const response = await listCuratedContent(search, limit, page - 1, 3, "1"); - // console.log(response); + // const initFetch = async () => { + // const response = await listCuratedContent(search, limit, page - 1, 3, "1"); + // // console.log(response); - const data = response?.data?.data; - const contentData = data?.content; - setHasData(displayDocument && displayDocument.length > 0); - setDisplayDocument(contentData); + // const data = response?.data?.data; + // const contentData = data?.content; + // setHasData(displayDocument && displayDocument.length > 0); + // setDisplayDocument(contentData); + // }; + + const initFetch = async () => { + try { + const levelName = (getCookiesDecrypt("levelName") || "").toUpperCase(); + + const res = await listDataTracking( + limit, + page - 1, + search, + "", // category + "", // status + levelName, + "3", // ✅ TEXT / DOCUMENT + ); + + const data = res?.data?.data?.content || []; + + console.log("TEXT DATA:", data); + + const mapped = data.map((item: any) => ({ + id: item.id, + title: item.title, + createdAt: item.createdAt, + timezone: item.timezone, + clickCount: item.clickCount || 0, + })); + + setDisplayDocument(mapped); + setHasData(mapped.length > 0); + } catch (error) { + console.error("Error fetching text:", error); + } }; return ( @@ -83,7 +118,7 @@ const TeksSliderPage = () => {
{formatDateToIndonesian( - new Date(document?.createdAt) + new Date(document?.createdAt), )}{" "} {document?.timezone ? document?.timezone : "WIB"} |{" "} {" "} diff --git a/app/[locale]/(protected)/shared/curated-content/giat-routine/image/image.tsx b/app/[locale]/(protected)/shared/curated-content/giat-routine/image/image.tsx index ab2bf11b..b143758b 100644 --- a/app/[locale]/(protected)/shared/curated-content/giat-routine/image/image.tsx +++ b/app/[locale]/(protected)/shared/curated-content/giat-routine/image/image.tsx @@ -16,6 +16,11 @@ import { formatDateToIndonesian } from "@/utils/globals"; import { Icon } from "@iconify/react/dist/iconify.js"; import { useRouter } from "next/navigation"; import React, { useEffect, useState } from "react"; +import { + listDataAllNonPagination, + listDataTracking, + mediaTrackingSave, +} from "@/service/media-tracking/media-tracking"; type ImageData = { id: string; @@ -33,15 +38,49 @@ const ImageSliderPage = () => { const [page, setPage] = useState(1); const [limit] = useState(10); + const ALLOWED_LEVEL = ["POLDA", "POLRES", "SATKER", "MABES"]; + useEffect(() => { fetchData(); }, [page]); - const fetchData = async () => { - const response = await listCuratedContent("", limit, page - 1, 1, "1"); - const data = response?.data?.data?.content || []; - setImageData(data); - }; + // const fetchData = async () => { + // const response = await listCuratedContent("", limit, page - 1, 1, "1"); + // const data = response?.data?.data?.content || []; + // setImageData(data); + // }; + +const fetchData = async () => { + try { + const levelName = getCookiesDecrypt("levelName") || ""; + + const res = await listDataTracking( + limit, + page - 1, + "", + "", + "", + levelName + ); + + const data = res?.data?.data?.content || []; + + console.log("RAW DATA:", data); + + const mapped = data.map((item: any) => ({ + id: item.id, + title: item.title, + createdAt: item.createdAt, + timezone: item.timezone, + thumbnailLink: item.thumbnailLink, + clickCount: item.clickCount || 0, + })); + + setImageData(mapped); + } catch (error) { + console.error(error); + } +}; return (
@@ -78,7 +117,7 @@ const ImageSliderPage = () => {

{formatDateToIndonesian( - new Date(image?.createdAt) + new Date(image?.createdAt), )}{" "} {image?.timezone || "WIB"} | { fetchData(); }, [page, limit, search]); - const fetchData = async () => { - const response = await listCuratedContent(search, limit, page - 1, 2, "1"); - // console.log(response); + // const fetchData = async () => { + // const response = await listCuratedContent(search, limit, page - 1, 2, "1"); + // // console.log(response); - const data = response?.data?.data; - const contentData = data?.content; - setVideoData(contentData); + // const data = response?.data?.data; + // const contentData = data?.content; + // setVideoData(contentData); + // }; + + const fetchData = async () => { + try { + const levelName = (getCookiesDecrypt("levelName") || "").toUpperCase(); + + const res = await listDataTracking( + limit, + page - 1, + search, + "", // category + "", // status + levelName, + "2", + ); + + const data = res?.data?.data?.content || []; + + console.log("VIDEO DATA:", data); + + const mapped = data.map((item: any) => ({ + id: item.id, + title: item.title, + createdAt: item.createdAt, + timezone: item.timezone, + thumbnailLink: item.thumbnailLink, // ✅ penting (bukan thumbnailUrl) + clickCount: item.clickCount || 0, + })); + + setVideoData(mapped); + } catch (error) { + console.error("Error fetching video:", error); + } }; return ( @@ -77,7 +112,7 @@ const VideoSliderPage = () => {

{formatDateToIndonesian( - new Date(video?.createdAt) + new Date(video?.createdAt), )}{" "} {video?.timezone || "WIB"} | { return import("@/components/editor/custom-editor"); }, - { ssr: false } + { ssr: false }, ); export default function FormAudio() { @@ -117,7 +117,7 @@ export default function FormAudio() { const [isGeneratedArticle, setIsGeneratedArticle] = useState(false); const [articleBody, setArticleBody] = useState(""); const [selectedArticleId, setSelectedArticleId] = useState( - null + null, ); const [selectedMainKeyword, setSelectedMainKeyword] = useState(""); const [selectedSize, setSelectedSize] = useState(""); @@ -185,7 +185,7 @@ export default function FormAudio() { } const filesWithPreview = acceptedFiles.map((file) => - Object.assign(file, { preview: URL.createObjectURL(file) }) + Object.assign(file, { preview: URL.createObjectURL(file) }), ); setFiles((prevFiles) => [...prevFiles, ...filesWithPreview]); @@ -420,7 +420,7 @@ export default function FormAudio() { const articleData = await waitForStatusUpdate(); const cleanArticleBody = articleData?.articleBody?.replace( /]*>/g, - "" + "", ); const articleImagesData = articleData?.imagesUrl?.split(","); setValue("description", cleanArticleBody || ""); @@ -474,7 +474,7 @@ export default function FormAudio() { if (scheduleId && scheduleType === "3") { const findCategory = resCategory.find((o) => - o.name.toLowerCase().includes("pers rilis") + o.name.toLowerCase().includes("pers rilis"), ); if (findCategory) { @@ -499,7 +499,7 @@ export default function FormAudio() { setPublishedFor( options .filter((opt: any) => opt.id !== "all") - .map((opt: any) => opt.id) + .map((opt: any) => opt.id), ); } } else { @@ -632,17 +632,17 @@ export default function FormAudio() { translatedTitle && translatedTitle.trim() !== "" ? translatedTitle : isSwitchOn - ? title - : data.title; + ? title + : data.title; const finalDescription = translatedContent && translatedContent.trim() !== "" ? translatedContent : isSwitchOn - ? data.description - : selectedFileType === "rewrite" - ? data.rewriteDescription - : data.descriptionOri; + ? data.description + : selectedFileType === "rewrite" + ? data.rewriteDescription + : data.descriptionOri; if (!finalDescription?.trim()) { MySwal.fire("Error", "Deskripsi tidak boleh kosong.", "error"); @@ -654,7 +654,7 @@ export default function FormAudio() { data.descriptionOri = translatedContent; console.log( "🌍 Translate dimasukkan ke descriptionOri:", - translatedContent + translatedContent, ); } @@ -762,7 +762,7 @@ export default function FormAudio() { idx: number, id: string, file: any, - duration: string + duration: string, ) { // console.log(idx, id, file, duration); @@ -799,7 +799,7 @@ export default function FormAudio() { onChunkComplete: ( chunkSize: any, bytesAccepted: any, - bytesTotal: any + bytesTotal: any, ) => { const uploadPersen = Math.floor((bytesAccepted / bytesTotal) * 100); progressInfo[idx].percentage = uploadPersen; @@ -1754,7 +1754,7 @@ export default function FormAudio() { const isChecked = option.id === "all" ? isAllChecked - : field.value?.includes(option.id) ?? false; + : (field.value?.includes(option.id) ?? false); const handleChange = () => { let updated: string[] = []; @@ -1767,7 +1767,9 @@ export default function FormAudio() { .map((opt: any) => opt.id); } else { updated = isChecked - ? (field.value ?? []).filter((val) => val !== option.id) + ? (field.value ?? []).filter( + (val) => val !== option.id, + ) : [...(field.value ?? []), option.id]; if (isAllChecked && option.id !== "all") { @@ -1806,16 +1808,24 @@ export default function FormAudio() {

- {levelNumber !== "2" && ( + {levelNumber !== "2" && levelNumber !== "3" && ( )}
- + {/* */}
diff --git a/components/form/content/image-form.tsx b/components/form/content/image-form.tsx index eb9b88fb..53ac959b 100644 --- a/components/form/content/image-form.tsx +++ b/components/form/content/image-form.tsx @@ -1684,7 +1684,7 @@ export default function FormImage() { const isChecked = option.id === "all" ? isAllChecked - : field.value?.includes(option.id) ?? false; + : (field.value?.includes(option.id) ?? false); const handleChange = () => { let updated: string[] = []; @@ -1697,7 +1697,9 @@ export default function FormImage() { .map((opt: any) => opt.id); } else { updated = isChecked - ? (field.value ?? []).filter((val) => val !== option.id) + ? (field.value ?? []).filter( + (val) => val !== option.id, + ) : [...(field.value ?? []), option.id]; if (isAllChecked && option.id !== "all") { @@ -1741,16 +1743,24 @@ export default function FormImage() { {/* */} - {levelNumber !== "2" && ( + {levelNumber !== "2" && levelNumber !== "3" && ( )}
- + {/* */}
diff --git a/components/form/content/teks-form.tsx b/components/form/content/teks-form.tsx index 6b222418..24fd82ea 100644 --- a/components/form/content/teks-form.tsx +++ b/components/form/content/teks-form.tsx @@ -71,7 +71,7 @@ const CustomEditor = dynamic( () => { return import("@/components/editor/custom-editor"); }, - { ssr: false } + { ssr: false }, ); type Option = { @@ -113,7 +113,7 @@ export default function FormTeks() { const [isGeneratedArticle, setIsGeneratedArticle] = useState(false); const [articleBody, setArticleBody] = useState(""); const [selectedArticleId, setSelectedArticleId] = useState( - null + null, ); const [isContentRewriteClicked, setIsContentRewriteClicked] = useState(false); const [showRewriteEditor, setShowRewriteEditor] = useState(false); @@ -174,13 +174,13 @@ export default function FormTeks() { "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.ms-powerpoint", "application/vnd.openxmlformats-officedocument.presentationml.presentation", - ].includes(file.type) && file.size <= 20 * 1024 * 1024 + ].includes(file.type) && file.size <= 20 * 1024 * 1024, ); const filesWithPreview = filtered.map((file) => Object.assign(file, { preview: URL.createObjectURL(file), - }) + }), ); setFiles(filesWithPreview); @@ -214,8 +214,8 @@ export default function FormTeks() { "application/vnd.ms-powerpoint", "application/vnd.openxmlformats-officedocument.presentationml.presentation", ].includes(file.type), - { message: "Format file tidak didukung" } - ) + { message: "Format file tidak didukung" }, + ), ) .min(1, { message: "File wajib diunggah" }), description: z.string().optional(), @@ -430,7 +430,7 @@ export default function FormTeks() { const articleData = await waitForStatusUpdate(); const cleanArticleBody = articleData?.articleBody?.replace( /]*>/g, - "" + "", ); const articleImagesData = articleData?.imagesUrl?.split(","); setValue("description", cleanArticleBody || ""); @@ -490,7 +490,7 @@ export default function FormTeks() { if (scheduleId && scheduleType === "3") { const findCategory = resCategory.find((o) => - o.name.toLowerCase().includes("pers rilis") + o.name.toLowerCase().includes("pers rilis"), ); if (findCategory) { @@ -515,7 +515,7 @@ export default function FormTeks() { setPublishedFor( options .filter((opt: any) => opt.id !== "all") - .map((opt: any) => opt.id) + .map((opt: any) => opt.id), ); } } else { @@ -662,17 +662,17 @@ export default function FormTeks() { translatedTitle && translatedTitle.trim() !== "" ? translatedTitle : isSwitchOn - ? title - : data.title; + ? title + : data.title; const finalDescription = translatedContent && translatedContent.trim() !== "" ? translatedContent : isSwitchOn - ? data.description - : selectedFileType === "rewrite" - ? data.rewriteDescription - : data.descriptionOri; + ? data.description + : selectedFileType === "rewrite" + ? data.rewriteDescription + : data.descriptionOri; if (!finalDescription?.trim()) { MySwal.fire("Error", "Deskripsi tidak boleh kosong.", "error"); @@ -684,7 +684,7 @@ export default function FormTeks() { data.descriptionOri = translatedContent; console.log( "🌍 Translate dimasukkan ke descriptionOri:", - translatedContent + translatedContent, ); } @@ -755,7 +755,7 @@ export default function FormTeks() { index, String(id), item, - fileTypeId == "2" || fileTypeId == "4" ? item.duration : "0" + fileTypeId == "2" || fileTypeId == "4" ? item.duration : "0", ); }); @@ -782,7 +782,7 @@ export default function FormTeks() { idx: number, id: string, file: any, - duration: string + duration: string, ) { // console.log(idx, id, file, duration); @@ -819,7 +819,7 @@ export default function FormTeks() { onChunkComplete: ( chunkSize: any, bytesAccepted: any, - bytesTotal: any + bytesTotal: any, ) => { const uploadPersen = Math.floor((bytesAccepted / bytesTotal) * 100); progressInfo[idx].percentage = uploadPersen; @@ -861,7 +861,7 @@ export default function FormTeks() { } if (counter == progressInfo.length) { setIsStartUpload(false); - close(); + close(); // hideProgress(); Cookies.remove("idCreate"); successSubmit("/in/contributor/content/teks"); @@ -1721,7 +1721,7 @@ export default function FormTeks() { const isChecked = option.id === "all" ? isAllChecked - : field.value?.includes(option.id) ?? false; + : (field.value?.includes(option.id) ?? false); const handleChange = () => { let updated: string[] = []; @@ -1734,7 +1734,9 @@ export default function FormTeks() { .map((opt: any) => opt.id); } else { updated = isChecked - ? (field.value ?? []).filter((val) => val !== option.id) + ? (field.value ?? []).filter( + (val) => val !== option.id, + ) : [...(field.value ?? []), option.id]; if (isAllChecked && option.id !== "all") { @@ -1776,16 +1778,24 @@ export default function FormTeks() { {/* */} - {levelNumber !== "2" && ( + {levelNumber !== "2" && levelNumber !== "3" && ( )}
- + {/* */}
diff --git a/components/form/content/video-form.tsx b/components/form/content/video-form.tsx index 90278a23..e6f6a787 100644 --- a/components/form/content/video-form.tsx +++ b/components/form/content/video-form.tsx @@ -1770,7 +1770,7 @@ export default function FormVideo() { const isChecked = option.id === "all" ? isAllChecked - : field.value?.includes(option.id) ?? false; + : (field.value?.includes(option.id) ?? false); const handleChange = () => { let updated: string[] = []; @@ -1783,7 +1783,9 @@ export default function FormVideo() { .map((opt: any) => opt.id); } else { updated = isChecked - ? (field.value ?? []).filter((val) => val !== option.id) + ? (field.value ?? []).filter( + (val) => val !== option.id, + ) : [...(field.value ?? []), option.id]; if (isAllChecked && option.id !== "all") { @@ -1825,16 +1827,24 @@ export default function FormVideo() { {/* */} - {levelNumber !== "2" && ( + {levelNumber !== "2" && levelNumber !== "3" && ( )} -
- + {/* */}
diff --git a/service/media-tracking/media-tracking.ts b/service/media-tracking/media-tracking.ts index 0841c6b0..5daa2287 100644 --- a/service/media-tracking/media-tracking.ts +++ b/service/media-tracking/media-tracking.ts @@ -57,10 +57,12 @@ export async function listDataTracking( page: number, keyword = "", categoryFilter = "", - statusFilter = "" + statusFilter = "", + creatorGroupLevelName = "", + typeId = "" ) { return await httpGetInterceptor( - `media/list?isForAdmin=true&title=${keyword}&enablePage=1&sortBy=createdAt&sort=desc&size=${size}&page=${page}&categoryId=${categoryFilter}&statusId=${statusFilter}` + `media/list?isForAdmin=true&title=${keyword}&enablePage=1&sortBy=createdAt&sort=desc&size=${size}&page=${page}&categoryId=${categoryFilter}&statusId=${statusFilter}&creatorGroupLevelName=${creatorGroupLevelName}&typeId=${typeId}` ); }