This commit is contained in:
2025-02-11 10:42:00 +08:00
parent a1405e301b
commit 2c443587ba
9 changed files with 487 additions and 128 deletions

View File

@@ -0,0 +1,156 @@
import { prisma } from "@/app/lib";
import backendLogger from "@/util/backendLogger";
import _ from "lodash";
import { NextResponse } from "next/server";
export async function GET(request: Request, { params }:
{ params: { status: string } }
) {
const { status } = params;
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 fixStatus = _.startCase(status);
if (!page) {
fixData = await prisma.projectCollaboration.findMany({
skip: skipData,
take: takeData,
orderBy: {
createdAt: "desc",
},
where: {
isActive: true,
isReject: false,
Author: {
active: true,
},
title: {
contains: search ? search : "",
mode: "insensitive",
},
},
select: {
id: true,
createdAt: true,
isActive: true,
title: true,
Author: {
select: {
id: true,
username: true,
Profile: true,
},
},
projectCollaborationMaster_IndustriId: true,
ProjectCollaborationMaster_Industri: true,
ProjectCollaboration_Partisipasi: {
where: {
User: {
active: true,
},
},
// select: {
// User: {
// select: {
// id: true,
// username: true,
// Profile: true,
// },
// },
// },
},
},
});
} else {
const data = await prisma.projectCollaboration.findMany({
skip: skipData,
take: takeData,
orderBy: {
createdAt: "desc",
},
where: {
isActive: true,
isReject: false,
Author: {
active: true,
},
title: {
contains: search ? search : "",
mode: "insensitive",
},
},
select: {
id: true,
createdAt: true,
isActive: true,
title: true,
Author: {
select: {
id: true,
username: true,
Profile: true,
},
},
projectCollaborationMaster_IndustriId: true,
ProjectCollaborationMaster_Industri: true,
ProjectCollaboration_Partisipasi: {
where: {
User: {
active: true,
},
},
// select: {
// User: {
// select: {
// id: true,
// username: true,
// Profile: true,
// },
// },
// },
},
},
});
const nCount = await prisma.projectCollaboration.count({
where: {
isActive: true,
isReject: false,
Author: {
active: true,
},
},
});
fixData = {
data: data,
nPage: _.ceil(nCount / takeData),
}
}
return NextResponse.json({
success: true,
message: "Success get data collaboration dashboard",
data: fixData,
},
{ status: 200 }
);
} catch (error) {
backendLogger.error("Error get data collaboration dashboard >>", error);
return NextResponse.json({
success: false,
message: "Error get data collaboration dashboard",
reason: (error as Error).message
},
{ status: 500 }
)
}
}

View File

@@ -0,0 +1,139 @@
import { prisma } from "@/app/lib";
import backendLogger from "@/util/backendLogger";
import _ from "lodash";
import { NextResponse } from "next/server";
export async function GET(request: Request) {
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.projectCollaboration_RoomChat.findMany({
orderBy: {
createdAt: "desc",
},
where: {
isActive: true,
},
select: {
id: true,
createdAt: true,
isActive: true,
name: true,
ProjectCollaboration_AnggotaRoomChat: {
select: {
User: {
select: {
id: true,
Profile: true,
},
},
},
},
ProjectCollaboration: {
select: {
id: true,
isActive: true,
title: true,
lokasi: true,
purpose: true,
benefit: true,
createdAt: true,
report: true,
Author: {
select: {
id: true,
Profile: {
select: {
name: true,
},
},
},
},
ProjectCollaborationMaster_Industri: true,
},
},
},
});
} else {
const data = await prisma.projectCollaboration_RoomChat.findMany({
take: takeData,
skip: skipData,
orderBy: {
createdAt: "desc",
},
where: {
isActive: true,
},
select: {
id: true,
createdAt: true,
isActive: true,
name: true,
ProjectCollaboration_AnggotaRoomChat: {
select: {
User: {
select: {
id: true,
Profile: true,
},
},
},
},
ProjectCollaboration: {
select: {
id: true,
isActive: true,
title: true,
lokasi: true,
purpose: true,
benefit: true,
createdAt: true,
report: true,
Author: {
select: {
id: true,
Profile: {
select: {
name: true,
},
},
},
},
ProjectCollaborationMaster_Industri: true,
},
},
},
});
const nCount = await prisma.projectCollaboration_RoomChat.count({
where: {
isActive: true,
},
})
fixData = {
data: data,
nPage: _.ceil(nCount / takeData)
}
}
} catch (error) {
backendLogger.error("Error get data collaboration group >>", error);
return NextResponse.json({
success: false,
message: "Error get data collaboration group",
reason: (error as Error).message
},
{ status: 500 }
)
}
}

View File

@@ -30,7 +30,7 @@ export async function GET(request: Request, { params }: {
if (!page) { if (!page) {
const data = await prisma.investasi.findMany({ fixData = await prisma.investasi.findMany({
orderBy: { orderBy: {
updatedAt: "desc", updatedAt: "desc",
}, },
@@ -62,6 +62,8 @@ export async function GET(request: Request, { params }: {
}); });
} else { } else {
const data = await prisma.investasi.findMany({ const data = await prisma.investasi.findMany({
take: takeData,
skip: skipData,
orderBy: { orderBy: {
updatedAt: "desc", updatedAt: "desc",
}, },

View File

@@ -2,11 +2,11 @@ import { AdminForum_TableReportPosting } from "@/app_modules/admin/forum";
import adminForum_funGetAllReportPosting from "@/app_modules/admin/forum/fun/get/get_all_report_posting"; import adminForum_funGetAllReportPosting from "@/app_modules/admin/forum/fun/get/get_all_report_posting";
export default async function Page() { export default async function Page() {
const listData = await adminForum_funGetAllReportPosting({ page: 1 });
return ( return (
<> <>
<AdminForum_TableReportPosting listData={listData} /> <AdminForum_TableReportPosting />
</> </>
); );
} }

View File

@@ -1,5 +1,7 @@
export { export {
apiGetAdminCollaborationStatusCountDashboard, apiGetAdminCollaborationStatusCountDashboard,
apiGetAdminCollaborationStatusById,
apiGetAdminCollaborationRoomById
} }
const apiGetAdminCollaborationStatusCountDashboard = async ({ const apiGetAdminCollaborationStatusCountDashboard = async ({
@@ -23,3 +25,47 @@ const apiGetAdminCollaborationStatusCountDashboard = async ({
// console.log("Ini Response", await response.json()); // console.log("Ini Response", await response.json());
return await response.json().catch(() => null); return await response.json().catch(() => null);
} }
const apiGetAdminCollaborationStatusById = async ({ status, page, search }: {
status: "Publish" | "Reject",
page: string,
search: 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/collaboration/${status}${isPage}${isSearch}`, {
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
}
})
return await response.json().catch(() => null);
}
const apiGetAdminCollaborationRoomById = async ({ page, search }: {
page: string,
search: 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/collaboration/group${isPage}${isSearch}`, {
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
}
})
return await response.json().catch(() => null);
}

View File

@@ -58,11 +58,12 @@ const apiGetAdminCountForumReportKomentar = async () => {
return await response.json().catch(() => null); return await response.json().catch(() => null);
} }
const apiGetAdminForumReportPosting = async () => { const apiGetAdminForumReportPosting = async ({page} : { page?: string}) => {
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);
const response = await fetch(`/api/admin/forum/posting`, { const isPage = page ? `?page=${page}` : "";
const response = await fetch(`/api/admin/forum/posting${isPage}`, {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",

View File

@@ -84,7 +84,7 @@ function TablePublish() {
page: `${activePage}` page: `${activePage}`
}); });
setData(loadData.data.data); setData(loadData.data.data);
setNPage(loadData.data.nPage); setNPage(loadData.data.nCount);
} }
const onPageClick = (page: number) => { const onPageClick = (page: number) => {

View File

@@ -30,139 +30,153 @@ import ComponentAdminForum_ButtonDeletePosting from "../component/button_delete"
import adminForum_funGetAllReportPosting from "../fun/get/get_all_report_posting"; import adminForum_funGetAllReportPosting from "../fun/get/get_all_report_posting";
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 { useShallowEffect } from "@mantine/hooks";
import { apiGetAdminForumReportPosting } from "../lib/api_fetch_admin_forum";
import { clientLogger } from "@/util/clientLogger";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
export default function AdminForum_TableReportPosting({ export default function AdminForum_TableReportPosting() {
listData,
}: {
listData: any;
}) {
return ( return (
<> <>
<Stack> <Stack>
<ComponentAdminGlobal_HeaderTamplate name="Forum" /> <ComponentAdminGlobal_HeaderTamplate name="Forum" />
<TableView listData={listData} /> <TableView />
{/* <pre>{JSON.stringify(listPublish, null, 2)}</pre> */} {/* <pre>{JSON.stringify(listPublish, null, 2)}</pre> */}
</Stack> </Stack>
</> </>
); );
} }
function TableView({ listData }: { listData: any }) { function TableView() {
const router = useRouter(); const router = useRouter();
const [data, setData] = useState<MODEL_FORUM_REPORT_POSTING[]>(listData.data); const [data, setData] = useState<MODEL_FORUM_REPORT_POSTING[] | null>(null);
const [nPage, setNPage] = useState(listData.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) { useShallowEffect(() => {
setSearch(s); const loadInitialData = async () => {
try {
const response = await apiGetAdminForumReportPosting({
page: `${activePage}`
})
if (response?.success && response?.data) {
setData(response.data);
setNPage(response.data.nCount || 1)
} else {
console.error("Invalid data format recieved", response),
setData([])
}
} catch (error) {
clientLogger.error("Invalid data format recieved", error)
setData([])
}
}
loadInitialData();
}, [activePage, isSearch]);
async function onSearch(searchTerm: string) {
setSearch(searchTerm);
setActivePage(1); setActivePage(1);
const loadData = await adminForum_funGetAllReportPosting({
page: 1,
search: s,
});
setData(loadData.data as any);
setNPage(loadData.nPage);
} }
async function onPageClick(p: any) { const onPageClick = (page: number) => {
setActivePage(p); setActivePage(page);
const loadData = await adminForum_funGetAllReportPosting({
search: isSearch,
page: p,
});
setData(loadData.data as any);
setNPage(loadData.nPage);
} }
async function onLoadData() { const renderTableBody = () => {
const loadData = await adminForum_funGetAllReportPosting({ if (!Array.isArray(data) || data.length === 0) {
page: 1, return (
}); <tr>
setData(loadData.data as any); <td colSpan={12}>
setNPage(loadData.nPage); <Center>
} <Text color={"gray"}>Tidak ada data</Text>
</Center>
const TableRows = data?.map((e, i) => ( </td>
<tr key={i}> </tr>
<td> )
<Center c={AdminColor.white} w={200}> }
<Text lineClamp={1}>{e?.User.username}</Text> return data?.map((e, i) => (
</Center> <tr key={i}>
</td> <td>
<td> <Center c={AdminColor.white} w={200}>
<Center c={AdminColor.white} w={200}> <Text lineClamp={1}>{e?.User.username}</Text>
{e?.forumMaster_KategoriReportId === null ? ( </Center>
<Text>Lainnya</Text> </td>
) : ( <td>
<Text lineClamp={1}>{e?.ForumMaster_KategoriReport.title}</Text> <Center c={AdminColor.white} w={200}>
)} {e?.forumMaster_KategoriReportId === null ? (
</Center> <Text>Lainnya</Text>
</td> ) : (
<Text lineClamp={1}>{e?.ForumMaster_KategoriReport.title}</Text>
{/* <td>
<Center w={200}>
<Text lineClamp={1}>{e?.Forum_Posting.Author.username}</Text>
</Center>
</td>
<td>
<Box w={400}>
<Spoiler
// w={400}
maxHeight={60}
hideLabel="sembunyikan"
showLabel="tampilkan"
>
<div
dangerouslySetInnerHTML={{
__html: e?.Forum_Posting.diskusi,
}}
/>
</Spoiler>
</Box>
</td> */}
<td>
<Center w={200}>
<Badge
color={
(e?.Forum_Posting.ForumMaster_StatusPosting?.id as any) === 1
? "green"
: "red"
}
>
{e?.Forum_Posting.ForumMaster_StatusPosting?.status}
</Badge>
</Center>
</td>
<td>
<Center w={150}>
<Text c={AdminColor.white}>
{new Intl.DateTimeFormat(["id-ID"], { dateStyle: "medium" }).format(
e.createdAt
)} )}
</Text> </Center>
</Center> </td>
</td>
<td> {/* <td>
<Stack align="center" spacing={"xs"}> <Center w={200}>
{/* <ButtonAction postingId={e?.id} /> */} <Text lineClamp={1}>{e?.Forum_Posting.Author.username}</Text>
<ButtonLihatReportLainnya postingId={e?.forum_PostingId} /> </Center>
{/* <ComponentAdminForum_ButtonDeletePosting </td>
postingId={e?.forum_PostingId}
onSuccesDelete={(val) => { <td>
if (val) { <Box w={400}>
onLoadData(); <Spoiler
// w={400}
maxHeight={60}
hideLabel="sembunyikan"
showLabel="tampilkan"
>
<div
dangerouslySetInnerHTML={{
__html: e?.Forum_Posting.diskusi,
}}
/>
</Spoiler>
</Box>
</td> */}
<td>
<Center w={200}>
<Badge
color={
(e?.Forum_Posting?.ForumMaster_StatusPosting?.id as any) === 1
? "green"
: "red"
} }
}} >
/> */} {e?.Forum_Posting?.ForumMaster_StatusPosting?.status}
</Stack> </Badge>
</td> </Center>
</tr> </td>
));
<td>
<Center w={150}>
<Text c={AdminColor.white}>
{new Intl.DateTimeFormat("id-ID", { dateStyle: "medium" }).format(
new Date(e?.createdAt)
)}
</Text>
</Center>
</td>
<td>
<Stack align="center" spacing={"xs"}>
{/* <ButtonAction postingId={e?.id} /> */}
<ButtonLihatReportLainnya postingId={e?.forum_PostingId} />
{/* <ComponentAdminForum_ButtonDeletePosting
postingId={e?.forum_PostingId}
onSuccesDelete={(val) => {
if (val) {
onLoadData();
}
}}
/> */}
</Stack>
</td>
</tr>
));
}
return ( return (
<> <>
@@ -172,14 +186,14 @@ function TableView({ listData }: { listData: any }) {
color={AdminColor.softBlue} color={AdminColor.softBlue}
component={ component={
<TextInput <TextInput
icon={<IconSearch size={20} />} icon={<IconSearch size={20} />}
radius={"xl"} radius={"xl"}
placeholder="Cari postingan" placeholder="Cari postingan"
onChange={(val) => { onChange={(val) => {
onSearch(val.currentTarget.value); onSearch(val.currentTarget.value);
}} }}
/> />
} }
/> />
{/* <Group {/* <Group
@@ -202,8 +216,8 @@ function TableView({ listData }: { listData: any }) {
/> />
</Group> */} </Group> */}
{isEmpty(data) ? ( {!data ? (
<ComponentAdminGlobal_IsEmptyData /> <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>
@@ -241,7 +255,7 @@ function TableView({ listData }: { listData: any }) {
</th> </th>
</tr> </tr>
</thead> </thead>
<tbody>{TableRows}</tbody> <tbody>{renderTableBody()}</tbody>
</Table> </Table>
</ScrollArea> </ScrollArea>
<Center mt={"xl"}> <Center mt={"xl"}>

View File

@@ -34,6 +34,7 @@ const middlewareConfig: MiddlewareConfig = {
// ADMIN API // ADMIN API
// >> buat dibawah sini << // >> buat dibawah sini <<
"/api/admin/collaboration/*",
// Akses awal // Akses awal
"/api/get-cookie", "/api/get-cookie",