fix event

deskripsi:
- fix event kontribusi
This commit is contained in:
2025-02-20 17:10:21 +08:00
parent ae1554a47f
commit e0143c5d8c
4 changed files with 230 additions and 25 deletions

View File

@@ -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
}
};

View File

@@ -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<MODEL_EVENT_PESERTA[] | null>(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 (
<>
<Stack>
<CustomSkeleton height={200} width={"100%"} />
<CustomSkeleton height={200} width={"100%"} />
</Stack>
</>
);
return (
<Box>
{_.isEmpty(data) ? (
@@ -35,16 +79,8 @@ export default function Event_Kontribusi({
</Center>
)}
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) => <ComponentEvent_CardKontributor data={item} />}
</ScrollOnly>