Tambahan Hari Ini
This commit is contained in:
116
src/app/api/admin/forum/komentar/route.ts
Normal file
116
src/app/api/admin/forum/komentar/route.ts
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
import { count } from 'console';
|
||||||
|
import { prisma } from "@/app/lib";
|
||||||
|
import backendLogger from "@/util/backendLogger";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
export async function GET(request: Request, { komentarId }: { komentarId: string }) {
|
||||||
|
const method = request.method;
|
||||||
|
if (method !== "GET") {
|
||||||
|
return NextResponse.json({
|
||||||
|
success: false,
|
||||||
|
message: "Method not allowed"
|
||||||
|
},
|
||||||
|
{ status: 405 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
console.log("Ini page", page)
|
||||||
|
|
||||||
|
try {
|
||||||
|
let fixData;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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,
|
||||||
|
nCount: _.ceil(nCount / takeData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log("Ini fixData", fixData)
|
||||||
|
return NextResponse.json({
|
||||||
|
success: true,
|
||||||
|
message: "Success get data forum komentar",
|
||||||
|
data: fixData,
|
||||||
|
},
|
||||||
|
{ status: 200 }
|
||||||
|
)
|
||||||
|
} catch (error) {
|
||||||
|
backendLogger.error("Error get data forum komentar", error);
|
||||||
|
return NextResponse.json({
|
||||||
|
success: false,
|
||||||
|
message: "Error get data forum komentar",
|
||||||
|
reason: (error as Error).message
|
||||||
|
},
|
||||||
|
)
|
||||||
|
} finally {
|
||||||
|
await prisma.$disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
150
src/app/api/admin/forum/posting/route.ts
Normal file
150
src/app/api/admin/forum/posting/route.ts
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
import { prisma } from "@/app/lib";
|
||||||
|
import backendLogger from "@/util/backendLogger";
|
||||||
|
import _ from "lodash";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
export async function GET(request: Request,
|
||||||
|
{ postingId }: { postingId: string }) {
|
||||||
|
const method = request.method;
|
||||||
|
if (method !== "GET") {
|
||||||
|
return NextResponse.json({
|
||||||
|
success: false,
|
||||||
|
message: "Method not allowed",
|
||||||
|
},
|
||||||
|
{ status: 405 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
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: {
|
||||||
|
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_Posting: {
|
||||||
|
isActive: true,
|
||||||
|
diskusi: {
|
||||||
|
contains: search ? search : '',
|
||||||
|
mode: "insensitive"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
isActive: true,
|
||||||
|
createdAt: true,
|
||||||
|
deskripsi: true,
|
||||||
|
forumMaster_KategoriReportId: true,
|
||||||
|
ForumMaster_KategoriReport: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
title: true,
|
||||||
|
deskripsi: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
forum_PostingId: true,
|
||||||
|
Forum_Posting: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
diskusi: true,
|
||||||
|
ForumMaster_StatusPosting: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
status: true,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Author: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
username: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
userId: true,
|
||||||
|
User: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
username: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const nCount = await prisma.forum_ReportPosting.count({
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
fixData = {
|
||||||
|
data: data,
|
||||||
|
nCount: _.ceil(nCount / takeData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NextResponse.json({
|
||||||
|
success: true,
|
||||||
|
data: fixData,
|
||||||
|
message: "Success get data forum posting"
|
||||||
|
},
|
||||||
|
{ 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 }
|
||||||
|
)
|
||||||
|
} finally {
|
||||||
|
await prisma.$disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,41 @@ export async function GET(request: Request) {
|
|||||||
let fixData;
|
let fixData;
|
||||||
|
|
||||||
if (!page) {
|
if (!page) {
|
||||||
|
fixData = await prisma.forum_Posting.findMany({
|
||||||
|
|
||||||
|
orderBy: {
|
||||||
|
createdAt: "desc",
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
diskusi: {
|
||||||
|
contains: search ? search : "",
|
||||||
|
mode: "insensitive",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
diskusi: true,
|
||||||
|
isActive: true,
|
||||||
|
createdAt: true,
|
||||||
|
Author: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
username: true,
|
||||||
|
Profile: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Forum_ReportPosting: true,
|
||||||
|
Forum_Komentar: {
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ForumMaster_StatusPosting: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
const data = await prisma.forum_Posting.findMany({
|
const data = await prisma.forum_Posting.findMany({
|
||||||
take: takeData,
|
take: takeData,
|
||||||
skip: skipData,
|
skip: skipData,
|
||||||
@@ -73,7 +108,6 @@ export async function GET(request: Request) {
|
|||||||
data: data,
|
data: data,
|
||||||
nCount: _.ceil(nCount / takeData)
|
nCount: _.ceil(nCount / takeData)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
@@ -91,5 +125,7 @@ export async function GET(request: Request) {
|
|||||||
},
|
},
|
||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
)
|
)
|
||||||
|
} finally {
|
||||||
|
await prisma.$disconnect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ export async function GET(request: Request) {
|
|||||||
)
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
backendLogger.error('Error get data voting dashboard >>', error);
|
backendLogger.error('Error get data voting dashboard >>', error);
|
||||||
NextResponse.json({
|
return NextResponse.json({
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Error get data voting dashboard',
|
message: 'Error get data voting dashboard',
|
||||||
reason: (error as Error).message
|
reason: (error as Error).message
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
export {
|
export {
|
||||||
apiGetAdminForumPublishCountDasboard,
|
apiGetAdminForumPublishCountDasboard,
|
||||||
|
apiGetAdminCountForumReportPosting ,
|
||||||
|
apiGetAdminCountForumReportKomentar,
|
||||||
apiGetAdminForumReportPosting,
|
apiGetAdminForumReportPosting,
|
||||||
apiGetAdminForumReportKomentar
|
apiGetAdminForumReportKomentar,
|
||||||
|
apiGetAdminForumPublish
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiGetAdminForumPublishCountDasboard = async () => {
|
const apiGetAdminForumPublishCountDasboard = async () => {
|
||||||
@@ -21,7 +24,7 @@ const apiGetAdminForumPublishCountDasboard = async () => {
|
|||||||
return await response.json().catch(() => null);
|
return await response.json().catch(() => null);
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiGetAdminForumReportPosting = async () => {
|
const apiGetAdminCountForumReportPosting = async () => {
|
||||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||||
if (!token) return await token.json().catch(() => null);
|
if (!token) return await token.json().catch(() => null);
|
||||||
|
|
||||||
@@ -38,6 +41,38 @@ const apiGetAdminForumReportPosting = async () => {
|
|||||||
return await response.json().catch(() => null);
|
return await response.json().catch(() => null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const apiGetAdminCountForumReportKomentar = async () => {
|
||||||
|
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||||
|
if (!token) return await token.json().catch(() => null);
|
||||||
|
|
||||||
|
const response = await fetch(`/api/admin/forum/dashboard/report_komentar`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Accept: "application/json",
|
||||||
|
"Access-Control-Allow-Origin": "*",
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return await response.json().catch(() => null);
|
||||||
|
}
|
||||||
|
const apiGetAdminForumReportPosting = async () => {
|
||||||
|
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||||
|
if (!token) return await token.json().catch(() => null);
|
||||||
|
|
||||||
|
const response = await fetch(`/api/admin/forum/dashboard/report_posting`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Accept: "application/json",
|
||||||
|
"Access-Control-Allow-Origin": "*",
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return await response.json().catch(() => null);
|
||||||
|
}
|
||||||
const apiGetAdminForumReportKomentar = async () => {
|
const apiGetAdminForumReportKomentar = async () => {
|
||||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||||
if (!token) return await token.json().catch(() => null);
|
if (!token) return await token.json().catch(() => null);
|
||||||
@@ -54,3 +89,19 @@ const apiGetAdminForumReportKomentar = async () => {
|
|||||||
|
|
||||||
return await response.json().catch(() => null);
|
return await response.json().catch(() => null);
|
||||||
}
|
}
|
||||||
|
const apiGetAdminForumPublish = async () => {
|
||||||
|
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||||
|
if (!token) return await token.json().catch(() => null);
|
||||||
|
|
||||||
|
const response = await fetch(`/api/admin/forum/dashboard/publish`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Accept: "application/json",
|
||||||
|
"Access-Control-Allow-Origin": "*",
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return await response.json().catch(() => null);
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ import { AdminColor } from "@/app_modules/_global/color/color_pallet";
|
|||||||
import { useShallowEffect } from "@mantine/hooks";
|
import { useShallowEffect } from "@mantine/hooks";
|
||||||
import { clientLogger } from "@/util/clientLogger";
|
import { clientLogger } from "@/util/clientLogger";
|
||||||
import global_limit from "@/app/lib/limit";
|
import global_limit from "@/app/lib/limit";
|
||||||
import { apiGetAdminForumPublishCountDasboard } from "../lib/api_fetch_admin_forum";
|
import { apiGetAdminCountForumReportKomentar, apiGetAdminCountForumReportPosting, apiGetAdminForumPublishCountDasboard } from "../lib/api_fetch_admin_forum";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ function ForumMain() {
|
|||||||
|
|
||||||
async function onLoadCountReportPosting() {
|
async function onLoadCountReportPosting() {
|
||||||
try {
|
try {
|
||||||
const response = await apiGetAdminForumPublishCountDasboard()
|
const response = await apiGetAdminCountForumReportPosting()
|
||||||
if (response) {
|
if (response) {
|
||||||
setCountLaporanPosting(response.data)
|
setCountLaporanPosting(response.data)
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,7 @@ function ForumMain() {
|
|||||||
|
|
||||||
async function onLoadCountReportKomentar() {
|
async function onLoadCountReportKomentar() {
|
||||||
try {
|
try {
|
||||||
const response = await apiGetAdminForumPublishCountDasboard()
|
const response = await apiGetAdminCountForumReportKomentar()
|
||||||
if (response) {
|
if (response) {
|
||||||
setCountLaporanKomentar(response.data)
|
setCountLaporanKomentar(response.data)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
|
||||||
import { RouterAdminForum } from "@/app/lib/router_admin/router_admin_forum";
|
import { RouterAdminForum } from "@/app/lib/router_admin/router_admin_forum";
|
||||||
import { RouterForum } from "@/app/lib/router_hipmi/router_forum";
|
import { RouterForum } from "@/app/lib/router_hipmi/router_forum";
|
||||||
import ComponentAdminGlobal_HeaderTamplate from "@/app_modules/admin/_admin_global/header_tamplate";
|
import ComponentAdminGlobal_HeaderTamplate from "@/app_modules/admin/_admin_global/header_tamplate";
|
||||||
@@ -30,13 +31,17 @@ import { useState } from "react";
|
|||||||
import { adminForum_funDeletePostingById } from "../fun/delete/fun_delete_posting_by_id";
|
import { adminForum_funDeletePostingById } from "../fun/delete/fun_delete_posting_by_id";
|
||||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
|
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
|
||||||
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
|
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
|
||||||
import { useDisclosure } from "@mantine/hooks";
|
import { useDisclosure, useShallowEffect } from "@mantine/hooks";
|
||||||
import { adminForum_getListPosting } from "../fun/get/get_list_publish";
|
import { adminForum_getListPosting } from "../fun/get/get_list_publish";
|
||||||
import adminJob_getListPublish from "@/app_modules/admin/job/fun/get/get_list_publish";
|
import adminJob_getListPublish from "@/app_modules/admin/job/fun/get/get_list_publish";
|
||||||
import ComponentAdminForum_ButtonDeletePosting from "../component/button_delete";
|
import ComponentAdminForum_ButtonDeletePosting from "../component/button_delete";
|
||||||
import ComponentAdminGlobal_IsEmptyData from "../../_admin_global/is_empty_data";
|
import ComponentAdminGlobal_IsEmptyData from "../../_admin_global/is_empty_data";
|
||||||
import { ComponentAdminGlobal_TitlePage } from "../../_admin_global/_component";
|
import { ComponentAdminGlobal_TitlePage } from "../../_admin_global/_component";
|
||||||
import { AdminColor } from "@/app_modules/_global/color/color_pallet";
|
import { AdminColor } from "@/app_modules/_global/color/color_pallet";
|
||||||
|
import { apiGetAdminForumPublish } from "../lib/api_fetch_admin_forum";
|
||||||
|
import { clientLogger } from "@/util/clientLogger";
|
||||||
|
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
||||||
|
|
||||||
|
|
||||||
export default function AdminForum_TablePosting({
|
export default function AdminForum_TablePosting({
|
||||||
listPublish,
|
listPublish,
|
||||||
@@ -47,39 +52,45 @@ export default function AdminForum_TablePosting({
|
|||||||
<>
|
<>
|
||||||
<Stack>
|
<Stack>
|
||||||
<ComponentAdminGlobal_HeaderTamplate name="Forum" />
|
<ComponentAdminGlobal_HeaderTamplate name="Forum" />
|
||||||
<TablePublish listPublish={listPublish} />
|
<TablePublish />
|
||||||
{/* <pre>{JSON.stringify(listPublish, null, 2)}</pre> */}
|
{/* <pre>{JSON.stringify(listPublish, null, 2)}</pre> */}
|
||||||
</Stack>
|
</Stack>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function TablePublish({ listPublish }: { listPublish: any }) {
|
|
||||||
|
function TablePublish() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [data, setData] = useState<MODEL_FORUM_POSTING[]>(listPublish.data);
|
const [data, setData] = useState<MODEL_FORUM_POSTING[] | null>(null);
|
||||||
const [nPage, setNPage] = useState(listPublish.nPage);
|
const [nPage, setNPage] = useState<number>(1);
|
||||||
const [activePage, setActivePage] = useState(1);
|
const [activePage, setActivePage] = useState(1);
|
||||||
const [isSearch, setSearch] = useState("");
|
const [isSearch, setSearch] = useState("");
|
||||||
|
|
||||||
async function onSearch(s: string) {
|
|
||||||
setSearch(s);
|
|
||||||
setActivePage(1);
|
|
||||||
const loadData = await adminForum_getListPosting({
|
|
||||||
page: 1,
|
|
||||||
search: s,
|
|
||||||
});
|
|
||||||
setData(loadData.data as any);
|
|
||||||
setNPage(loadData.nPage);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function onPageClick(p: any) {
|
useShallowEffect(() => {
|
||||||
setActivePage(p);
|
const loadInitialData = async () => {
|
||||||
const loadData = await adminForum_getListPosting({
|
try {
|
||||||
search: isSearch,
|
const response = await apiGetAdminForumPublish()
|
||||||
page: p,
|
|
||||||
});
|
|
||||||
setData(loadData.data as any);
|
if (response?.success && response?.data.data) {
|
||||||
setNPage(loadData.nPage);
|
setData(response.data.data);
|
||||||
|
setNPage(response.data.nPage || 1);
|
||||||
|
} else {
|
||||||
|
console.error("Invalid data format recieved:", response);
|
||||||
|
setData([]);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
clientLogger.error("Invlid data format recieved:", error);
|
||||||
|
setData([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loadInitialData();
|
||||||
|
}, [activePage, isSearch]);
|
||||||
|
const onSearch = async (searchTerm: string) => {
|
||||||
|
setSearch(searchTerm);
|
||||||
|
setActivePage(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onLoadData() {
|
async function onLoadData() {
|
||||||
@@ -90,7 +101,24 @@ function TablePublish({ listPublish }: { listPublish: any }) {
|
|||||||
setNPage(loadData.nPage);
|
setNPage(loadData.nPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
const TableRows = data?.map((e, i) => (
|
const onPageClick = (page: number) => {
|
||||||
|
setActivePage(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const renderTableBody = () => {
|
||||||
|
if (!Array.isArray(data) || data.length === 0) {
|
||||||
|
return (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={12}>
|
||||||
|
<Center>
|
||||||
|
<Text color="gray">Tidak ada data</Text>
|
||||||
|
</Center>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return data?.map((e, i) => (
|
||||||
<tr key={i}>
|
<tr key={i}>
|
||||||
<td>
|
<td>
|
||||||
<Center w={200}>
|
<Center w={200}>
|
||||||
@@ -166,6 +194,8 @@ function TablePublish({ listPublish }: { listPublish: any }) {
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
));
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -203,8 +233,9 @@ function TablePublish({ listPublish }: { listPublish: any }) {
|
|||||||
/>
|
/>
|
||||||
</Group> */}
|
</Group> */}
|
||||||
|
|
||||||
{isEmpty(data) ? (
|
|
||||||
<ComponentAdminGlobal_IsEmptyData />
|
{!data ? (
|
||||||
|
<CustomSkeleton height={"80vh"} width={"100%"} />
|
||||||
) : (
|
) : (
|
||||||
<Paper p={"md"} bg={AdminColor.softBlue} h={"80vh"}>
|
<Paper p={"md"} bg={AdminColor.softBlue} h={"80vh"}>
|
||||||
<ScrollArea w={"100%"} h={"90%"} offsetScrollbars>
|
<ScrollArea w={"100%"} h={"90%"} offsetScrollbars>
|
||||||
@@ -215,6 +246,7 @@ function TablePublish({ listPublish }: { listPublish: any }) {
|
|||||||
w={"100%"}
|
w={"100%"}
|
||||||
h={"100%"}
|
h={"100%"}
|
||||||
|
|
||||||
|
|
||||||
>
|
>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -241,7 +273,7 @@ function TablePublish({ listPublish }: { listPublish: any }) {
|
|||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>{TableRows}</tbody>
|
<tbody>{renderTableBody()}</tbody>
|
||||||
</Table>
|
</Table>
|
||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
<Center mt={"xl"}>
|
<Center mt={"xl"}>
|
||||||
@@ -260,11 +292,13 @@ function TablePublish({ listPublish }: { listPublish: any }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function ButtonAction({ postingId }: { postingId: string }) {
|
function ButtonAction({ postingId }: { postingId: string }) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [loadingKomentar, setLoadingKomentar] = useState(false);
|
const [loadingKomentar, setLoadingKomentar] = useState(false);
|
||||||
const [loadingReport, setLoadingReport] = useState(false);
|
const [loadingReport, setLoadingReport] = useState(false);
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Button
|
<Button
|
||||||
@@ -299,11 +333,13 @@ function ButtonAction({ postingId }: { postingId: string }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// function ButtonDeletePosting({ postingId }: { postingId: string }) {
|
// function ButtonDeletePosting({ postingId }: { postingId: string }) {
|
||||||
// const [opened, { open, close }] = useDisclosure(false);
|
// const [opened, { open, close }] = useDisclosure(false);
|
||||||
// const [loadingDel, setLoadingDel] = useState(false);
|
// const [loadingDel, setLoadingDel] = useState(false);
|
||||||
// const [loadingDel2, setLoadingDel2] = useState(false);
|
// const [loadingDel2, setLoadingDel2] = useState(false);
|
||||||
|
|
||||||
|
|
||||||
// async function onDelete() {
|
// async function onDelete() {
|
||||||
// await adminForum_funDeletePostingById(postingId).then((res) => {
|
// await adminForum_funDeletePostingById(postingId).then((res) => {
|
||||||
// if (res.status === 200) {
|
// if (res.status === 200) {
|
||||||
@@ -371,3 +407,6 @@ function ButtonAction({ postingId }: { postingId: string }) {
|
|||||||
// </>
|
// </>
|
||||||
// );
|
// );
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -38,12 +38,13 @@ const middlewareConfig: MiddlewareConfig = {
|
|||||||
// "/api/new/*",
|
// "/api/new/*",
|
||||||
// ADMIN API
|
// ADMIN API
|
||||||
// "/api/admin/event/*",
|
// "/api/admin/event/*",
|
||||||
"/api/admin/investasi/*",
|
// "/api/admin/investasi/*",
|
||||||
// "/api/admin/donasi/*",
|
// "/api/admin/donasi/*",
|
||||||
// "/api/admin/voting/dashboard/*",
|
// "/api/admin/voting/dashboard/*",
|
||||||
// "/api/admin/job/*",
|
// "/api/admin/job/*",
|
||||||
// "/api/admin/forum/*",
|
// "/api/admin/forum/*",
|
||||||
// "/api/admin/collaboration/*",
|
// "/api/admin/collaboration/*",
|
||||||
|
"api/admin/forum/*",
|
||||||
|
|
||||||
// Akses awal
|
// Akses awal
|
||||||
"/api/get-cookie",
|
"/api/get-cookie",
|
||||||
|
|||||||
Reference in New Issue
Block a user