diff --git a/src/app/api/event/kontribusi/route.ts b/src/app/api/event/kontribusi/route.ts
new file mode 100644
index 00000000..5c692ab4
--- /dev/null
+++ b/src/app/api/event/kontribusi/route.ts
@@ -0,0 +1,132 @@
+import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
+import backendLogger from "@/util/backendLogger";
+import { NextResponse } from "next/server";
+
+export { GET };
+
+async function GET(request: Request) {
+ try {
+ let fixData;
+ const { searchParams } = new URL(request.url);
+ const page = searchParams.get("page");
+ const takeData = 5;
+ const skipData = Number(page) * takeData - takeData;
+
+ const userLoginId = await funGetUserIdByToken();
+ if (!userLoginId) {
+ return NextResponse.json(
+ {
+ success: false,
+ message: "Gagal mendapatkan data",
+ reason: "User not found",
+ },
+ {
+ status: 401,
+ }
+ );
+ }
+
+ if (!page) {
+ fixData = await prisma.event_Peserta.findMany({
+ orderBy: {
+ createdAt: "desc",
+ },
+ where: {
+ userId: userLoginId,
+ },
+ select: {
+ id: true,
+ Event: {
+ select: {
+ id: true,
+ title: true,
+ tanggal: true,
+ deskripsi: true,
+ Author: {
+ select: {
+ Profile: true,
+ },
+ },
+ Event_Peserta: {
+ take: 5,
+ orderBy: {
+ createdAt: "desc",
+ },
+ select: {
+ id: true,
+ userId: true,
+ User: {
+ select: {
+ Profile: true,
+ },
+ },
+ },
+ },
+ },
+ },
+ },
+ });
+ } else {
+ fixData = await prisma.event_Peserta.findMany({
+ take: takeData,
+ skip: skipData,
+ orderBy: {
+ createdAt: "desc",
+ },
+ where: {
+ userId: userLoginId,
+ },
+ select: {
+ id: true,
+ Event: {
+ select: {
+ id: true,
+ title: true,
+ tanggal: true,
+ deskripsi: true,
+ Author: {
+ select: {
+ Profile: true,
+ },
+ },
+ Event_Peserta: {
+ take: 5,
+ orderBy: {
+ createdAt: "desc",
+ },
+ select: {
+ id: true,
+ userId: true,
+ User: {
+ select: {
+ Profile: true,
+ },
+ },
+ },
+ },
+ },
+ },
+ },
+ });
+ }
+
+ return NextResponse.json(
+ {
+ success: true,
+ message: "Success get kontribusi",
+ data: fixData,
+ },
+ { status: 200 }
+ );
+ } catch (error) {
+ backendLogger.error("Error get kontribusi", error);
+ return NextResponse.json(
+ {
+ success: false,
+ message: "Failed get kontribusi",
+ reason: (error as Error).message,
+ },
+ { status: 500 }
+ );
+ }
+}
diff --git a/src/app/dev/event/main/kontribusi/page.tsx b/src/app/dev/event/main/kontribusi/page.tsx
index 0a883c1b..18e81ccf 100644
--- a/src/app/dev/event/main/kontribusi/page.tsx
+++ b/src/app/dev/event/main/kontribusi/page.tsx
@@ -2,11 +2,10 @@ import { Event_Kontribusi } from "@/app_modules/event";
import { event_getListKontibusiByUserId } from "@/app_modules/event/fun/get/get_list_kontribusi_by_user_id";
export default async function Page() {
- const listKontribusi = await event_getListKontibusiByUserId({page: 1})
return (
<>
-
+
>
);
}
diff --git a/src/app_modules/event/component/button/api_fetch_event.ts b/src/app_modules/event/component/button/api_fetch_event.ts
index a6c6823e..7106c4ac 100644
--- a/src/app_modules/event/component/button/api_fetch_event.ts
+++ b/src/app_modules/event/component/button/api_fetch_event.ts
@@ -1,4 +1,4 @@
-export { apiGetEventByStatus };
+export { apiGetEventByStatus, apiGetKontribusiEvent };
const apiGetEventByStatus = async ({
status,
@@ -43,3 +43,41 @@ const apiGetEventByStatus = async ({
throw error; // Re-throw the error to handle it in the calling function
}
};
+
+const apiGetKontribusiEvent = async ({ page }: { page: string }) => {
+ try {
+ // Fetch token from cookie
+ const { token } = await fetch("/api/get-cookie").then((res) => res.json());
+ if (!token) {
+ console.error("No token found");
+ return null;
+ }
+
+ // Send PUT request to update portfolio logo
+ const isPage = `?page=${page}`;
+ const response = await fetch(`/api/event/kontribusi${isPage}`, {
+ 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(
+ "Error updating portfolio logo:",
+ errorData?.message || "Unknown error"
+ );
+
+ return null;
+ }
+
+ return await response.json();
+ } catch (error) {
+ console.error("Error updating portfolio medsos:", error);
+ throw error; // Re-throw the error to handle it in the calling function
+ }
+};
diff --git a/src/app_modules/event/main/kontribusi/index.tsx b/src/app_modules/event/main/kontribusi/index.tsx
index e8b4a15e..a6d44bd9 100644
--- a/src/app_modules/event/main/kontribusi/index.tsx
+++ b/src/app_modules/event/main/kontribusi/index.tsx
@@ -2,25 +2,69 @@
import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data";
import ComponentGlobal_Loader from "@/app_modules/_global/component/loader";
-import {
- Box,
- Center
-} from "@mantine/core";
+import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
+import { clientLogger } from "@/util/clientLogger";
+import { Box, Center, Stack } from "@mantine/core";
+import { useShallowEffect } from "@mantine/hooks";
import _ from "lodash";
import { ScrollOnly } from "next-scroll-loader";
import { useState } from "react";
-import { ComponentEvent_CardKontributor } from "../../component/card_view/card_kontributor";
-import { event_getListKontibusiByUserId } from "../../fun/get/get_list_kontribusi_by_user_id";
import { MODEL_EVENT_PESERTA } from "../../_lib/interface";
+import {
+ apiGetKontribusiEvent
+} from "../../component/button/api_fetch_event";
+import { ComponentEvent_CardKontributor } from "../../component/card_view/card_kontributor";
-export default function Event_Kontribusi({
- listKontribusi,
-}: {
- listKontribusi: MODEL_EVENT_PESERTA[];
-}) {
- const [data, setData] = useState(listKontribusi);
+export default function Event_Kontribusi() {
+ const [data, setData] = useState(null);
const [activePage, setActivePage] = useState(1);
+ useShallowEffect(() => {
+ handleLoadData();
+ }, []);
+
+ const handleLoadData = async () => {
+ try {
+ const response = await apiGetKontribusiEvent({
+ page: `${activePage}`,
+ });
+ if (response.success) {
+ setData(response.data);
+ } else {
+ setData(null);
+ }
+ } catch (error) {
+ clientLogger.error("Error get kontribusi event", error);
+ setData(null);
+ }
+ };
+
+ const hanldeMoreData = async () => {
+ try {
+ const nextPage = activePage + 1;
+ const response = await apiGetKontribusiEvent({
+ page: `${nextPage}`,
+ });
+ if (response.success) {
+ setActivePage(nextPage);
+ return response.data;
+ }
+ } catch (error) {
+ clientLogger.error("Error get kontribusi event", error);
+ setData(null);
+ }
+ };
+
+ if (!data)
+ return (
+ <>
+
+
+
+
+ >
+ );
+
return (
{_.isEmpty(data) ? (
@@ -35,16 +79,8 @@ export default function Event_Kontribusi({
)}
data={data}
- setData={setData}
- moreData={async () => {
- const loadData = await event_getListKontibusiByUserId({
- page: activePage + 1,
- });
-
- setActivePage((val) => val + 1);
-
- return loadData;
- }}
+ setData={setData as any}
+ moreData={hanldeMoreData}
>
{(item) => }