diff --git a/src/app/api/admin/event/[id]/peserta/route.ts b/src/app/api/admin/event/[id]/peserta/route.ts index cc88dfdf..65be8b1c 100644 --- a/src/app/api/admin/event/[id]/peserta/route.ts +++ b/src/app/api/admin/event/[id]/peserta/route.ts @@ -1,11 +1,83 @@ import backendLogger from "@/util/backendLogger"; +import _ from "lodash"; import { NextResponse } from "next/server"; -export async function GET(req: Request, +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; + + try { - + let fixData; + const { id } = params; + const eventId = id + + if (!page) { + fixData = await prisma.event_Peserta.findMany({ + + where: { + eventId: eventId, + User: { + username: { + contains: search ? search : "", + } + } + + }, + select: { + isPresent: true, + User: { + include: { + Profile: true, + }, + }, + }, + }); + } else { + const data = await prisma.event_Peserta.findMany({ + skip: skipData, + take: takeData, + where: { + eventId: eventId, + User: { + username: { + contains: search ? search : "", + } + } + }, + select: { + isPresent: true, + User: { + include: { + Profile: true, + }, + }, + }, + }); + + const nCount = await prisma.event_Peserta.count({ + where: { + eventId: eventId, + }, + }); + + fixData = { + data: data, + nPage: _.ceil(nCount / takeData), + }; + } + return NextResponse.json({ + success: true, + message: "Success get data event detail", + data: fixData, + }, + { status: 200 } + ) } catch (error) { backendLogger.error("Error get data event detail >>", error); return NextResponse.json({ diff --git a/src/app/api/admin/forum/[id]/report-komentar/route.ts b/src/app/api/admin/forum/[id]/report-komentar/route.ts new file mode 100644 index 00000000..933cae39 --- /dev/null +++ b/src/app/api/admin/forum/[id]/report-komentar/route.ts @@ -0,0 +1,103 @@ +import backendLogger from "@/util/backendLogger"; +import _ from "lodash"; +import { NextResponse } from "next/server"; + +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; + + 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 + }, + { 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 }) + } + +} \ No newline at end of file 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 c0e397b3..436e00ba 100644 --- a/src/app/api/admin/forum/[id]/report-posting/route.ts +++ b/src/app/api/admin/forum/[id]/report-posting/route.ts @@ -4,112 +4,115 @@ import _ from "lodash"; import { NextResponse } from "next/server"; 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; + { params }: { params: { id: string } }) { - try { - let fixData; - const { id } = params; - const postingId = id + 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; - if (!page) { - fixData = await prisma.forum_ReportPosting.findMany({ - - orderBy: { - createdAt: "desc", - }, - where: { - forum_PostingId: postingId, - }, + try { + let fixData; + const { id } = params; + const postingId = id + + if (!page) { + fixData = await prisma.forum_ReportPosting.findMany({ + + orderBy: { + createdAt: "desc", + }, + where: { + forum_PostingId: postingId, + + + }, + select: { + id: true, + deskripsi: true, + createdAt: true, + User: { + select: { + id: true, + username: true, + Profile: { select: { - id: true, - deskripsi: true, - createdAt: true, - User: { - select: { - id: true, - username: true, - Profile: { - select: { - name: true, - }, - }, - }, - }, - ForumMaster_KategoriReport: { - select: { - id: true, - title: true, - deskripsi: true, - }, - }, - }, - }); - } else { - const data = await prisma.forum_ReportPosting.findMany({ - take: takeData, - skip: skipData, - orderBy: { - createdAt: "desc", - }, - where: { - forum_PostingId: postingId, + name: true, }, + }, + }, + }, + ForumMaster_KategoriReport: { + select: { + id: true, + title: true, + deskripsi: true, + }, + }, + + }, + }); + } else { + const data = await prisma.forum_ReportPosting.findMany({ + take: takeData, + skip: skipData, + orderBy: { + createdAt: "desc", + }, + where: { + forum_PostingId: postingId, + }, + select: { + id: true, + deskripsi: true, + createdAt: true, + User: { + select: { + id: true, + username: true, + Profile: { select: { - id: true, - deskripsi: true, - createdAt: true, - User: { - select: { - id: true, - username: true, - Profile: { - select: { - name: true, - }, - }, - }, - }, - ForumMaster_KategoriReport: { - select: { - id: true, - title: true, - deskripsi: true, - }, - }, + name: true, }, - }); - const nCount = await prisma.forum_ReportPosting.count({ - where: { - isActive: true, - } - }) - - - fixData = { - data: data, - nCount: _.ceil(nCount / takeData) - } + }, + }, + }, + ForumMaster_KategoriReport: { + select: { + id: true, + title: true, + deskripsi: true, + }, + }, + }, + }); + const nCount = await prisma.forum_ReportPosting.count({ + where: { + isActive: true, } - return NextResponse.json({ - success: true, - message: "Success get data forum posting", - data: fixData - }, - { status: 200 } - ) - } catch (error) { - backendLogger.error("Error get data forum posting >>", error); - return NextResponse.json({ - success: false, - message: "Error get data forum posting", - }, - { status: 500 } - ) - } + }) + + + fixData = { + data: data, + nPage: _.ceil(nCount / takeData) + } + } + return NextResponse.json({ + success: true, + message: "Success get data forum report posting", + data: fixData + }, + { status: 200 } + ) + } catch (error) { + backendLogger.error("Error get data forum report posting >>", error); + return NextResponse.json({ + success: false, + message: "Error get data forum report posting", + }, + { status: 500 } + ) + } } \ No newline at end of file diff --git a/src/app/dev/admin/event/detail/peserta/[id]/page.tsx b/src/app/dev/admin/event/detail/peserta/[id]/page.tsx index 7038c519..18969dac 100644 --- a/src/app/dev/admin/event/detail/peserta/[id]/page.tsx +++ b/src/app/dev/admin/event/detail/peserta/[id]/page.tsx @@ -1,13 +1,10 @@ import { AdminEvent_UiDetailPeserta } from "@/app_modules/admin/event/_ui"; -import { adminEvent_getListPesertaById } from "@/app_modules/admin/event/fun/get/get_list_peserta_by_id"; -export default async function Page({ params }: { params: { id: string } }) { - const eventId = params.id; - const dataPeserta = await adminEvent_getListPesertaById({ eventId, page: 1 }); +export default async function Page(){ return ( <> - + ); } diff --git a/src/app_modules/admin/event/_lib/api_fecth_admin_event.ts b/src/app_modules/admin/event/_lib/api_fecth_admin_event.ts index c1dd5da8..7ca22fa6 100644 --- a/src/app_modules/admin/event/_lib/api_fecth_admin_event.ts +++ b/src/app_modules/admin/event/_lib/api_fecth_admin_event.ts @@ -5,7 +5,8 @@ export { apiGetAdminEventByStatus as apiGetDataEventByStatus, apiGetAdminEventRiwayat, apiGetAdminEventTipeAcara, - apiGetAdminDetailEventById + apiGetAdminDetailEventById, + apiGetAdminDetailEventPesertaById }; const apiGetAdminEventStatusCountDashboard = async ({ @@ -150,3 +151,31 @@ const apiGetAdminDetailEventById = async ({ id }: { id: string }) => { return await response.json().catch(() => null); } + +const apiGetAdminDetailEventPesertaById = async ({ + page, + search, + id +}: { + page: string; + search: string; + id: string +}) => { + const { token } = await fetch("/api/get-cookie").then((res) => res.json()); + if (!token) return await token.json().catch(() => null); + + const isPage = page ? `?page=${page}` : ""; + const isSearch = search ? `&search=${search}` : ""; + + const response = await fetch(`/api/admin/event/${id}/peserta${isPage}${isSearch}`, { + method: "GET", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "Access-Control-Allow-Origin": "*", + Authorization: `Bearer ${token}`, + }, + }) + + return await response.json().catch(() => null); +} diff --git a/src/app_modules/admin/event/_ui/ui_detail_peserta.tsx b/src/app_modules/admin/event/_ui/ui_detail_peserta.tsx index ec7a646e..f1e55c7d 100644 --- a/src/app_modules/admin/event/_ui/ui_detail_peserta.tsx +++ b/src/app_modules/admin/event/_ui/ui_detail_peserta.tsx @@ -6,21 +6,13 @@ import { AdminEvent_ViewDetailPeserta } from "../_view"; import { MODEL_EVENT_PESERTA } from "@/app_modules/event/_lib/interface"; import { ComponentAdminGlobal_TitlePage } from "../../_admin_global/_component"; -export function AdminEvent_UiDetailPeserta({ - dataPeserta, - eventId, -}: { - dataPeserta: any; - eventId: string -}) { +export function AdminEvent_UiDetailPeserta() { return ( <> diff --git a/src/app_modules/admin/event/_view/view_detail_peserta.tsx b/src/app_modules/admin/event/_view/view_detail_peserta.tsx index d0291b28..eb634265 100644 --- a/src/app_modules/admin/event/_view/view_detail_peserta.tsx +++ b/src/app_modules/admin/event/_view/view_detail_peserta.tsx @@ -10,6 +10,8 @@ import { ScrollArea, Stack, Table, + Text, + TextInput, Title, } from "@mantine/core"; import { useState } from "react"; @@ -17,32 +19,68 @@ import { adminEvent_getListPesertaById } from "../fun"; import _ from "lodash"; import ComponentAdminGlobal_IsEmptyData from "../../_admin_global/is_empty_data"; import { AdminColor } from "@/app_modules/_global/color/color_pallet"; +import { useShallowEffect } from "@mantine/hooks"; +import { clientLogger } from "@/util/clientLogger"; +import { apiGetAdminDetailEventPesertaById } from "../_lib/api_fecth_admin_event"; +import { useParams } from "next/navigation"; +import { IconSearch } from "@tabler/icons-react"; +import { ComponentAdminGlobal_TitlePage } from "../../_admin_global/_component"; +import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; -export function AdminEvent_ViewDetailPeserta({ - dataPeserta, - eventId, -}: { - dataPeserta: any; - eventId: string; -}) { - const [data, setData] = useState(dataPeserta.data); - const [isNPage, setNPage] = useState(dataPeserta.nPage); +export function AdminEvent_ViewDetailPeserta() { + const params = useParams<{ id: string }>(); + const [data, setData] = useState(null); + const [isNPage, setNPage] = useState(1); const [isActivePage, setActivePage] = useState(1); + const [isSearch, setSearch] = useState(""); + useShallowEffect(() => { + loadInitialData(); + }, [isActivePage, isSearch]) - async function onPageClick(p: any) { - setActivePage(p); - const loadData = await adminEvent_getListPesertaById({ - eventId: eventId, - page: p, - }); - setData(loadData.data as any); - setNPage(loadData.nPage); + const loadInitialData = async () => { + try { + const response = await apiGetAdminDetailEventPesertaById({ + id: params.id, + page: `${isActivePage}`, + search: isSearch, + }) + + if (response?.success && response?.data.data) { + setData(response.data.data) + setNPage(response.data.nPage || 1) + } else { + console.error("Invalid data format recieved:", response); + setData([]); + } + } catch (error) { + clientLogger.error("Invalid data format recieved:", error); + setData([]); + } } - const tableRow = _.isEmpty(data) - ? [] - : data.map((e, i) => ( + const onSearch = async (searchTerm: string) => { + setSearch(searchTerm); + setActivePage(1); + } + const onPageClick = (page: number) => { + setActivePage(page); + } + + const renderTableBody = () => { + if (!Array.isArray(data) || data.length === 0) { + return ( + + +
+ Tidak ada data +
+ + + ); + } + + return data?.map((e, i) => (
{e?.User?.username}
@@ -67,65 +105,81 @@ export function AdminEvent_ViewDetailPeserta({ )); + } return ( <> - - Daftar Peserta - - - - - - - - - - - - - - {tableRow} -
-
Username
-
-
Name
-
-
Nomor
-
-
Email
-
-
Konfirmasi Kehadiran
-
- {_.isEmpty(data) ? ( - - ) : ( - "" - )} -
- -
- } + radius={"xl"} + placeholder="Masukan username" onChange={(val) => { - onPageClick(val); + onSearch(val.currentTarget.value); }} /> -
-
+ } + /> + {!data ? ( + + ): ( + + + + + + + + + + + + + {renderTableBody()} +
+
Username
+
+
Name
+
+
Nomor
+
+
Email
+
+
Konfirmasi Kehadiran
+
+ {_.isEmpty(data) ? ( + + ) : ( + "" + )} +
+ +
+ { + onPageClick(val); + }} + /> +
+
+ )} +
{/*
{JSON.stringify(dataPeserta, null, 2)}
*/} diff --git a/src/app_modules/admin/event/table_status/detail_publish.tsx b/src/app_modules/admin/event/table_status/detail_publish.tsx index 7b78bbe3..2fd2e3eb 100644 --- a/src/app_modules/admin/event/table_status/detail_publish.tsx +++ b/src/app_modules/admin/event/table_status/detail_publish.tsx @@ -53,7 +53,7 @@ function AdminEvent_DetailPublish() { ) : null} {selectPage == "2" ? ( - + ) : null} {selectPage == "3" ? ( 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 0deb34a8..d611494e 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,10 +1,11 @@ export { apiGetAdminForumPublishCountDasboard, - apiGetAdminCountForumReportPosting , + apiGetAdminCountForumReportPosting, apiGetAdminCountForumReportKomentar, apiGetAdminForumReportPosting, apiGetAdminForumReportKomentar, - apiGetAdminForumPublish + apiGetAdminForumPublish, + apiGetAdminHasilReportPosting } const apiGetAdminForumPublishCountDasboard = async () => { @@ -38,7 +39,7 @@ const apiGetAdminCountForumReportPosting = async () => { }, }) - + return await response.json().catch(() => null); } @@ -58,7 +59,7 @@ const apiGetAdminCountForumReportKomentar = async () => { return await response.json().catch(() => null); } -const apiGetAdminForumReportPosting = async ({page} : { page?: string}) => { +const apiGetAdminForumReportPosting = async ({ page }: { page?: string }) => { const { token } = await fetch("/api/get-cookie").then((res) => res.json()); if (!token) return await token.json().catch(() => null); @@ -75,10 +76,10 @@ const apiGetAdminForumReportPosting = async ({page} : { page?: string}) => { return await response.json().catch(() => null); } -const apiGetAdminForumReportKomentar = async({ page } : { page?: string}) => { +const apiGetAdminForumReportKomentar = async ({ page }: { page?: string }) => { const { token } = await fetch("/api/get-cookie").then((res) => res.json()); if (!token) return await token.json().catch(() => null); - + const isPage = page ? `?page=${page}` : ""; const response = await fetch(`/api/admin/forum/komentar${isPage}`, { method: "GET", @@ -92,12 +93,13 @@ const apiGetAdminForumReportKomentar = async({ page } : { page?: string}) => { return await response.json().catch(() => null); } -const apiGetAdminForumPublish = async ({ page }: { page?: string }) => { +const apiGetAdminForumPublish = async ( + { page }: { page?: string }) => { const { token } = await fetch("/api/get-cookie").then((res) => res.json()); if (!token) return await token.json().catch(() => null); const isPage = page ? `?page=${page}` : ""; - const response = await fetch(`/api/admin/forum/publish${isPage}`, { + const response = await fetch(`/api/admin/forum/publish/${isPage}`, { method: "GET", headers: { "Content-Type": "application/json", @@ -106,15 +108,26 @@ const apiGetAdminForumPublish = async ({ page }: { page?: string }) => { Authorization: `Bearer ${token}`, }, }) - + return await response.json().catch(() => null); } -const apiGetAdminHasilReportPosting = async ({id} : {id: string}) => { +const apiGetAdminHasilReportPosting = async ({ page, id }: { page?: string, id: string }) => { const { token } = await fetch("/api/get-cookie").then((res) => res.json()); if (!token) return await token.json().catch(() => null); - + const isPage = page ? `?page=${page}` : ""; + const response = await fetch(`/api/admin/forum/${id}/report_posting${isPage}`, { + method: "GET", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "Access-Control-Allow-Origin": "*", + Authorization: `Bearer ${token}`, + } + }) + + return await response.json().catch(() => null); } \ No newline at end of file diff --git a/src/middleware.ts b/src/middleware.ts index cab61889..22fc62e5 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -34,10 +34,8 @@ const middlewareConfig: MiddlewareConfig = { // ADMIN API // >> buat dibawah sini << - // "/api/admin/collaboration/*", - // "/api/admin/investasi/*", - // "/api/admin/event/*", - // "/api/admin/forum/*", + + // Akses awal "/api/get-cookie",