diff --git a/next.config.js b/next.config.js index 66e268d2..cbd8e584 100644 --- a/next.config.js +++ b/next.config.js @@ -5,23 +5,23 @@ const nextConfig = { serverActions: true, }, output: "standalone", + staticPageGenerationTimeout: 180, // tingkatkan menjadi 3 menit // eslint: { // ignoreDuringBuilds: true, // }, - async headers() { - return [ - { - source: "/(.*)", - headers: [ - { - key: "Cache-Control", - value: "no-store, max-age=0", - }, - ], - }, - ]; - }, - + // async headers() { + // return [ + // { + // source: "/(.*)", + // headers: [ + // { + // key: "Cache-Control", + // value: "no-store, max-age=0", + // }, + // ], + // }, + // ]; + // }, }; module.exports = nextConfig; diff --git a/src/app/api/admin/forum/[id]/report-komentar/route.ts b/src/app/api/admin/forum/[id]/report-komentar/route.ts index 06f45cfb..5f045ab7 100644 --- a/src/app/api/admin/forum/[id]/report-komentar/route.ts +++ b/src/app/api/admin/forum/[id]/report-komentar/route.ts @@ -3,103 +3,107 @@ import _ from "lodash"; import { NextResponse } from "next/server"; import prisma from "@/lib/prisma"; - -export async function GET(request: Request, - { params }: { params: { id: string } } +export async function GET( + request: Request, + { params }: { params: { id: string } } ) { - const { searchParams } = new URL(request.url); - const search = searchParams.get('search'); - const page = searchParams.get('page'); - const takeData = 10; - const skipData = Number(page) * takeData - takeData; + const { searchParams } = new URL(request.url); + const search = searchParams.get("search"); + const page = searchParams.get("page"); + const takeData = 10; + const skipData = Number(page) * takeData - takeData; - try { - let fixData; - const { id } = params; - const komentarId = id + try { + let fixData; + const { id } = params; + const komentarId = id; - if (!page) { - fixData = await prisma.forum_ReportKomentar.findMany({ - - orderBy: { - createdAt: "desc" - }, - where: { - forum_KomentarId: komentarId, - }, - select: { - id: true, - isActive: true, - createdAt: true, - deskripsi: true, - ForumMaster_KategoriReport: true, - User: { - select: { - Profile: { - select: { - id: true, - name: true, - }, - }, - }, - }, - }, - }); - } else { - const data = await prisma.forum_ReportKomentar.findMany({ - take: takeData, - skip: skipData, - orderBy: { - createdAt: "desc" - }, - where: { - forum_KomentarId: komentarId, - }, - select: { - id: true, - isActive: true, - createdAt: true, - deskripsi: true, - ForumMaster_KategoriReport: true, - User: { - select: { - Profile: { - select: { - id: true, - name: true, - }, - }, - }, - }, - }, - }); - - const nCount = await prisma.forum_ReportKomentar.count({ - where: { - forum_KomentarId: komentarId, - } - }) - - fixData = { - data: data, - nPage: _.ceil(nCount / takeData) - } - } - - return NextResponse.json({ - success: true, - message: "Success get detail data report komentar", - data: fixData + if (!page) { + fixData = await prisma.forum_ReportKomentar.findMany({ + orderBy: { + createdAt: "desc", }, - { status: 200 } - ) - } catch (error) { - backendLogger.error("Error get detail data report komentar >>", error); - return NextResponse.json({ - success: false, - message: "Error get detail data report komentar", - reason: (error as Error).message - }, { status: 500 }) + where: { + forum_KomentarId: komentarId, + }, + select: { + id: true, + isActive: true, + createdAt: true, + deskripsi: true, + ForumMaster_KategoriReport: true, + User: { + select: { + username: true, + Profile: { + select: { + id: true, + name: true, + }, + }, + }, + }, + }, + }); + } else { + const data = await prisma.forum_ReportKomentar.findMany({ + take: takeData, + skip: skipData, + orderBy: { + createdAt: "desc", + }, + where: { + forum_KomentarId: komentarId, + }, + select: { + id: true, + isActive: true, + createdAt: true, + deskripsi: true, + ForumMaster_KategoriReport: true, + User: { + select: { + username: true, + Profile: { + select: { + id: true, + name: true, + }, + }, + }, + }, + }, + }); + + const nCount = await prisma.forum_ReportKomentar.count({ + where: { + forum_KomentarId: komentarId, + }, + }); + + fixData = { + data: data, + nPage: _.ceil(nCount / takeData), + }; } -} \ No newline at end of file + return NextResponse.json( + { + success: true, + message: "Success get detail data report komentar", + data: fixData, + }, + { status: 200 } + ); + } catch (error) { + backendLogger.error("Error get detail data report komentar >>", error); + return NextResponse.json( + { + success: false, + message: "Error get detail data report komentar", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/admin/forum/[id]/report-posting/route.ts b/src/app/api/admin/forum/[id]/report-posting/route.ts index c88561da..12e47ce1 100644 --- a/src/app/api/admin/forum/[id]/report-posting/route.ts +++ b/src/app/api/admin/forum/[id]/report-posting/route.ts @@ -85,7 +85,7 @@ export async function GET(request: Request, }); const nCount = await prisma.forum_ReportPosting.count({ where: { - isActive: true, + forum_PostingId: postingId, }, }); diff --git a/src/app/api/admin/forum/komentar/[id]/route.ts b/src/app/api/admin/forum/komentar/[id]/route.ts new file mode 100644 index 00000000..5de5f484 --- /dev/null +++ b/src/app/api/admin/forum/komentar/[id]/route.ts @@ -0,0 +1,45 @@ +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; + +export async function GET( + request: Request, + { params }: { params: { id: string } } +) { + try { + const { id } = params; + const data = await prisma.forum_Komentar.findFirst({ + where: { + id: id, + }, + select: { + id: true, + isActive: true, + authorId: true, + Author: { + select: { + id: true, + username: true, + }, + }, + komentar: true, + forum_PostingId: true, + }, + }); + + return NextResponse.json({ + success: true, + message: "Success get data komentar", + data: data, + }); + } catch (error) { + console.error("Error get data komentar", error); + return NextResponse.json( + { + success: false, + message: "Error get data komentar", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/dev/admin/forum/sub-detail/report-komentar/[id]/page.tsx b/src/app/dev/admin/forum/sub-detail/report-komentar/[id]/page.tsx index 94f2bd0f..17c6f084 100644 --- a/src/app/dev/admin/forum/sub-detail/report-komentar/[id]/page.tsx +++ b/src/app/dev/admin/forum/sub-detail/report-komentar/[id]/page.tsx @@ -1,23 +1,21 @@ import { AdminForum_HasilReportKomentar } from "@/app_modules/admin/forum"; -import { adminForum_getListReportKomentarbyId } from "@/app_modules/admin/forum/fun/get/get_list_report_komentar_by_id"; -import adminForum_funGetOneKomentarById from "@/app_modules/admin/forum/fun/get/get_one_komentar_by_id"; export default async function Page({ params }: { params: { id: string } }) { - let komentarId = params.id; - const listReport = await adminForum_getListReportKomentarbyId({ - komentarId: komentarId, - page: 1, - }); - const dataKomentar = await adminForum_funGetOneKomentarById({ - komentarId: komentarId, - }); + // let komentarId = params.id; + // const listReport = await adminForum_getListReportKomentarbyId({ + // komentarId: komentarId, + // page: 1, + // }); + // const dataKomentar = await adminForum_funGetOneKomentarById({ + // komentarId: komentarId, + // }); return ( <> ); diff --git a/src/app/dev/admin/forum/sub-detail/report-posting/[id]/page.tsx b/src/app/dev/admin/forum/sub-detail/report-posting/[id]/page.tsx index a40c7fed..4d4fa163 100644 --- a/src/app/dev/admin/forum/sub-detail/report-posting/[id]/page.tsx +++ b/src/app/dev/admin/forum/sub-detail/report-posting/[id]/page.tsx @@ -3,19 +3,19 @@ import { adminForum_getListReportPostingById } from "@/app_modules/admin/forum/f import { adminForum_getOnePostingById } from "@/app_modules/admin/forum/fun/get/get_one_posting_by_id"; export default async function Page({ params }: { params: { id: string } }) { - let postingId = params.id; - const listReport = await adminForum_getListReportPostingById({ - postingId: postingId, - page: 1, - }); + // let postingId = params.id; + // const listReport = await adminForum_getListReportPostingById({ + // postingId: postingId, + // page: 1, + // }); - const dataPosting = await adminForum_getOnePostingById(postingId); + // const dataPosting = await adminForum_getOnePostingById(postingId); return ( <> ); diff --git a/src/app_modules/admin/forum/lib/api_fetch_admin_forum.ts b/src/app_modules/admin/forum/lib/api_fetch_admin_forum.ts index e104a1ce..9179d220 100644 --- a/src/app_modules/admin/forum/lib/api_fetch_admin_forum.ts +++ b/src/app_modules/admin/forum/lib/api_fetch_admin_forum.ts @@ -1,13 +1,15 @@ export { - apiGetAdminForumPublishCountDasboard, - apiGetAdminCountForumReportPosting, - apiGetAdminCountForumReportKomentar, - apiGetAdminForumReportPosting, - apiGetAdminForumReportKomentar, - apiGetAdminForumPublish, - apiGetAdminHasilReportPosting, - apiAdminGetKomentarForumById, + apiAdminGetListKomentarForumById as apiAdminGetKomentarForumById, + apiAdminGetOneKomentarForumById, apiAdminGetPostingForumById, + apiGetAdminCountForumReportKomentar, + apiGetAdminCountForumReportPosting, + apiGetAdminForumPublish, + apiGetAdminForumPublishCountDasboard, + apiGetAdminForumReportKomentar, + apiGetAdminForumReportPosting, + apiGetAdminHasilReportPosting, + apiAdminGetListReportKomentarById, }; const apiGetAdminForumPublishCountDasboard = async () => { @@ -162,7 +164,7 @@ const apiGetAdminHasilReportPosting = async ({ return await response.json().catch(() => null); }; -const apiAdminGetKomentarForumById = async ({ +const apiAdminGetListKomentarForumById = async ({ id, page, search, @@ -214,11 +216,7 @@ const apiAdminGetKomentarForumById = async ({ } }; -const apiAdminGetPostingForumById = async ({ - id, -}: { - id: string; -}) => { +const apiAdminGetPostingForumById = async ({ id }: { id: string }) => { try { const { token } = await fetch("/api/get-cookie").then((res) => res.json()); if (!token) { @@ -256,3 +254,81 @@ const apiAdminGetPostingForumById = async ({ throw error; // Re-throw the error to handle it in the calling function } }; + +const apiAdminGetOneKomentarForumById = async ({ id }: { id: string }) => { + try { + const { token } = await fetch("/api/get-cookie").then((res) => res.json()); + if (!token) { + console.error("No token found"); + return null; + } + + const response = await fetch(`/api/admin/forum/komentar/${id}`, { + method: "GET", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + Authorization: `Bearer ${token}`, + }, + }); + + // Check if the response is OK + if (!response.ok) { + const errorData = await response.json().catch(() => null); + console.error( + "Failed to get admin komentar forum", + response.statusText, + errorData + ); + throw new Error( + errorData?.message || "Failed to get admin komentar forum" + ); + } + + // Return the JSON response + const resulst = await response.json(); + return resulst; + } catch (error) { + console.error("Error get admin komentar forum", error); + throw error; // Re-throw the error to handle it in the calling function + } +}; + +const apiAdminGetListReportKomentarById = async ({ id, page }: { id: string; page?: string }) => { + try { + const { token } = await fetch("/api/get-cookie").then((res) => res.json()); + if (!token) { + console.error("No token found"); + return null; + } + + const response = await fetch(`/api/admin/forum/${id}/report-komentar${page ? `?page=${page}` : ""}`, { + method: "GET", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + Authorization: `Bearer ${token}`, + }, + }); + + // Check if the response is OK + if (!response.ok) { + const errorData = await response.json().catch(() => null); + console.error( + "Failed to get admin list report komentar forum", + response.statusText, + errorData + ); + throw new Error( + errorData?.message || "Failed to get admin list report komentar forum" + ); + } + + // Return the JSON response + const resulst = await response.json(); + return resulst; + } catch (error) { + console.error("Error get admin list report komentar forum", error); + throw error; // Re-throw the error to handle it in the calling function + } +}; diff --git a/src/app_modules/admin/forum/sub_detail/hasil_report_komentar.tsx b/src/app_modules/admin/forum/sub_detail/hasil_report_komentar.tsx index 6121954c..f41686ed 100644 --- a/src/app_modules/admin/forum/sub_detail/hasil_report_komentar.tsx +++ b/src/app_modules/admin/forum/sub_detail/hasil_report_komentar.tsx @@ -7,6 +7,7 @@ import { import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil"; import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal"; import ComponentAdminGlobal_HeaderTamplate from "@/app_modules/admin/_admin_global/header_tamplate"; +import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; import { MODEL_FORUM_KOMENTAR, MODEL_FORUM_REPORT_POSTING, @@ -15,6 +16,7 @@ import mqtt_client from "@/util/mqtt_client"; import { Box, Button, + Center, Group, Paper, ScrollArea, @@ -24,10 +26,10 @@ import { Text, Title, } from "@mantine/core"; -import { useDisclosure } from "@mantine/hooks"; +import { useDisclosure, useShallowEffect } from "@mantine/hooks"; import { IconTrash } from "@tabler/icons-react"; import _ from "lodash"; -import { useRouter } from "next/navigation"; +import { useParams, useRouter } from "next/navigation"; import { useState } from "react"; import { Admin_ComponentModal } from "../../_admin_global/_component/comp_admin_modal"; import Admin_ComponentBackButton from "../../_admin_global/back_button"; @@ -37,18 +39,42 @@ import { Admin_V3_ComponentBreakpoint } from "../../_components_v3/comp_simple_g import adminNotifikasi_funCreateToUser from "../../notifikasi/fun/create/fun_create_notif_user"; import ComponentAdminForum_ViewOneDetailKomentar from "../component/detail_one_komentar"; import { adminForum_funDeleteKomentarById } from "../fun/delete/fun_delete_komentar_by_id"; -import { adminForum_getListReportKomentarbyId } from "../fun/get/get_list_report_komentar_by_id"; +import { + apiAdminGetListReportKomentarById, + apiAdminGetOneKomentarForumById, +} from "../lib/api_fetch_admin_forum"; -export default function AdminForum_HasilReportKomentar({ - komentarId, - listReport, - dataKomentar, -}: { - komentarId: string; - listReport: any; - dataKomentar: MODEL_FORUM_KOMENTAR; -}) { - const [data, setData] = useState(dataKomentar); +export default function AdminForum_HasilReportKomentar( +// { +// komentarId, +// listReport, +// dataKomentar, +// }: { +// komentarId: string; +// listReport: any; +// dataKomentar: MODEL_FORUM_KOMENTAR; +// } +) { + const { id } = useParams(); + const [data, setData] = useState(null); + + useShallowEffect(() => { + onLoadData(); + }, []); + + async function onLoadData() { + try { + const response = await apiAdminGetOneKomentarForumById({ + id: id as string, + }); + if (response && response.success) { + setData(response.data); + } + } catch (error) { + console.error("Invalid data get one forum", error); + setData(null); + } + } return ( <> @@ -56,20 +82,24 @@ export default function AdminForum_HasilReportKomentar({ - - - - { - setData(val); - }} - /> - - + {!data ? ( + + ) : ( + + + + { + setData(val); + }} + /> + + + )} - + ); @@ -188,67 +218,106 @@ function ButtonDeleteKomentar({ } function HasilReportPosting({ - listReport, + // listReport, komentarId, }: { - listReport: any; + // listReport: any; komentarId: string; }) { const router = useRouter(); - const [data, setData] = useState( - listReport.data - ); - const [nPage, setNPage] = useState(listReport.nPage); + const [data, setData] = useState(null); + const [nPage, setNPage] = useState(1); const [activePage, setActivePage] = useState(1); + useShallowEffect(() => { + onLoadData(); + }, [komentarId, activePage]); + + async function onLoadData() { + try { + const response = await apiAdminGetListReportKomentarById({ + id: komentarId, + page: `${activePage}`, + }); + if (response && response.success) { + setData(response.data.data); + setNPage(response.data.nPage); + } + } catch (error) { + console.error("Invalid data format received:", error); + setData([]); + setNPage(1); + } + } + async function onPageClick(p: any) { setActivePage(p); - const loadData = await adminForum_getListReportKomentarbyId({ - komentarId: komentarId, - page: p, - }); - setData(loadData.data as any); - setNPage(loadData.nPage); } - const TableRows = data?.map((e, i) => ( - - - - {e?.User?.username} - - - - - - {e?.ForumMaster_KategoriReport?.title - ? e?.ForumMaster_KategoriReport?.title - : "-"} - - - + const TableRows = () => { + if (!Array.isArray(data) || data.length === 0) { + return ( + + +
+ Tidak ada data +
+ + + ); + } - - - - {e?.ForumMaster_KategoriReport?.deskripsi ? ( - {e?.ForumMaster_KategoriReport?.deskripsi} - ) : ( - - - )} - - - + return data?.map((e, i) => ( + + + + {e?.User?.username} + + + + + + {e?.ForumMaster_KategoriReport?.title + ? e?.ForumMaster_KategoriReport?.title + : "-"} + + + - - - - {e?.deskripsi ? {e?.deskripsi} : -} - - - - - )); + + + + {e?.ForumMaster_KategoriReport?.deskripsi ? ( + {e?.ForumMaster_KategoriReport?.deskripsi} + ) : ( + - + )} + + + + + + + + {e?.deskripsi ? {e?.deskripsi} : -} + + + + + )); + }; + + if (!data) { + return ; + } return ( <> @@ -293,7 +362,7 @@ function HasilReportPosting({ - {TableRows} + {TableRows()} (null); + + useShallowEffect(() => { + onLoadData(); + }, []); + + async function onLoadData() { + try { + const response = await apiAdminGetPostingForumById({ + id: id as string, + }); + if (response && response.success) { + setData(response.data); + } + } catch (error) { + console.error("Invalid data format received:", error); + setData(null); + } + } -export default function AdminForum_HasilReportPosting({ - dataPosting, - listReport, -}: { - dataPosting: MODEL_FORUM_POSTING; - listReport: any; -}) { return ( <> - - - - - - + {!data ? ( + + ) : ( + <> + + + + + + + + )} - + ); @@ -164,75 +194,128 @@ function ButtonDeletePosting({ } function HasilReportPosting({ - listReport, + // listReport, postingId, }: { - listReport: any; + // listReport: any; postingId: string; }) { const router = useRouter(); - const [data, setData] = useState( - listReport.data - ); - const [nPage, setNPage] = useState(listReport.nPage); + const [data, setData] = useState(null); + const [nPage, setNPage] = useState(1); const [activePage, setActivePage] = useState(1); + const [isSearch, setSearch] = useState(""); - async function onPageClick(p: any) { - setActivePage(p); - const loadData = await adminForum_getListReportPostingById({ - postingId: postingId, - page: p, - }); - setData(loadData.data as any); - setNPage(loadData.nPage); + useShallowEffect(() => { + const loadInitialData = async () => { + try { + const response = await apiGetAdminForumReportPosting({ + page: `${activePage}`, + search: isSearch, + }); + + if (response?.success && response?.data.data) { + setData(response.data.data); + setNPage(response.data.nCount || 1); + } else { + console.error("Invalid data format recieved", response), setData([]); + } + } catch (error) { + console.error("Invalid data format recieved", error); + setData([]); + } + }; + loadInitialData(); + }, [activePage, isSearch]); + async function onSearch(searchTerm: string) { + setSearch(searchTerm); + setActivePage(1); } - const TableRows = data?.map((e, i) => ( - - -
- {e?.User?.username} -
- - -
- - {e?.ForumMaster_KategoriReport?.title - ? e?.ForumMaster_KategoriReport?.title - : "-"} - -
- + const onPageClick = (page: number) => { + setActivePage(page); + }; - -
- - {e?.ForumMaster_KategoriReport?.deskripsi ? ( - - {e?.ForumMaster_KategoriReport?.deskripsi} - - ) : ( - - - )} - -
- + // async function onPageClick(p: any) { + // setActivePage(p); + // const loadData = await adminForum_getListReportPostingById({ + // postingId: postingId, + // page: p, + // }); + // setData(loadData.data as any); + // setNPage(loadData.nPage); + // } - -
- - {e?.deskripsi ? ( - - {e?.deskripsi} - - ) : ( - - - )} - -
- - - )); + const TableRows = () => { + if (!Array.isArray(data) || data.length === 0) { + return ( + + +
+ Tidak ada data +
+ + + ); + } + + return data?.map((e, i) => ( + + +
+ {e?.User?.username} +
+ + +
+ + {e?.ForumMaster_KategoriReport?.title + ? e?.ForumMaster_KategoriReport?.title + : "-"} + +
+ + + +
+ + {e?.ForumMaster_KategoriReport?.deskripsi ? ( + + {e?.ForumMaster_KategoriReport?.deskripsi} + + ) : ( + - + )} + +
+ + + +
+ + {e?.deskripsi ? ( + + {e?.deskripsi} + + ) : ( + - + )} + +
+ + + )); + }; + + if (!data) return ; return ( <> @@ -293,7 +376,7 @@ function HasilReportPosting({ - {TableRows} + {TableRows()}