diff --git a/src/app/api/donasi/[id]/pencairan-dana/route.ts b/src/app/api/donasi/[id]/pencairan-dana/route.ts
new file mode 100644
index 00000000..843e9f56
--- /dev/null
+++ b/src/app/api/donasi/[id]/pencairan-dana/route.ts
@@ -0,0 +1,52 @@
+import { NextResponse } from "next/server";
+import { prisma } from "@/lib";
+
+export const dynamic = "force-dynamic";
+
+export async function GET(
+ request: Request,
+ { params }: { params: { id: string } }
+) {
+ try {
+ let fixData;
+ const { id } = params;
+ const { searchParams } = new URL(request.url);
+ const page = Number(searchParams.get("page"));
+ const takeData = 3;
+ const skipData = page * takeData - takeData;
+
+ if (!page) {
+ fixData = await prisma.donasi_PencairanDana.findMany({
+ orderBy: {
+ createdAt: "asc",
+ },
+ where: {
+ donasiId: id,
+ },
+ });
+ } else {
+ fixData = await prisma.donasi_PencairanDana.findMany({
+ take: takeData,
+ skip: skipData,
+ orderBy: {
+ createdAt: "asc",
+ },
+ where: {
+ donasiId: id,
+ },
+ });
+ }
+
+ return NextResponse.json({
+ success: true,
+ message: "Data berhasil diambil",
+ data: fixData,
+ });
+ } catch (error) {
+ return NextResponse.json({
+ success: false,
+ message: "Terjadi kesalahan saat mengambil data",
+ reason: error as Error,
+ });
+ }
+}
diff --git a/src/app/api/donasi/[id]/penggalang-dana/route.ts b/src/app/api/donasi/[id]/penggalang-dana/route.ts
new file mode 100644
index 00000000..1c4c6d23
--- /dev/null
+++ b/src/app/api/donasi/[id]/penggalang-dana/route.ts
@@ -0,0 +1,73 @@
+import { NextResponse } from "next/server";
+import { prisma } from "@/lib";
+
+export async function GET(
+ request: Request,
+ { params }: { params: { id: string } }
+) {
+ try {
+ const { id } = params;
+ const data = await prisma.user.findFirst({
+ where: {
+ id: id,
+ },
+ select: {
+ id: true,
+ username: true,
+ nomor: true,
+ Profile: {
+ select: {
+ id: true,
+ name: true,
+ email: true,
+ imageId: true,
+ },
+ },
+ Donasi: {
+ orderBy: {
+ createdAt: "desc",
+ },
+ where: {
+ donasiMaster_StatusDonasiId: "1",
+ },
+ select: {
+ id: true,
+ title: true,
+ target: true,
+ active: true,
+ createdAt: true,
+ updatedAt: true,
+ publishTime: true,
+ catatan: true,
+ authorId: true,
+ progres: true,
+ terkumpul: true,
+ imagesId: true,
+ donasiMaster_KategoriId: true,
+ donasiMaster_DurasiId: true,
+ donasiMaster_StatusDonasiId: true,
+ Author: true,
+ imageDonasi: true,
+ CeritaDonasi: true,
+ DonasiMaster_Ketegori: true,
+ DonasiMaster_Durasi: true,
+ DonasiMaster_Status: true,
+ imageId: true,
+ },
+ },
+ },
+ });
+
+ return NextResponse.json({
+ success: true,
+ message: "Data berhasil diambil",
+ data: data,
+ });
+ } catch (error) {
+ return NextResponse.json({
+ success: false,
+ message: "Terjadi kesalahan saat mengambil data",
+ reason: error as Error,
+ });
+ }
+}
diff --git a/src/app/dev/(user)/donasi/pencairan_dana/[id]/page.tsx b/src/app/dev/(user)/donasi/pencairan_dana/[id]/page.tsx
index b8c06d3a..d5a2de17 100644
--- a/src/app/dev/(user)/donasi/pencairan_dana/[id]/page.tsx
+++ b/src/app/dev/(user)/donasi/pencairan_dana/[id]/page.tsx
@@ -3,16 +3,16 @@ import { donasi_funGetListPencairanDanaById } from "@/app_modules/donasi/fun/get
import { Donasi_getTotalPencairanDanaById } from "@/app_modules/donasi/fun/get/get_pencairan_dana_by_id";
export default async function Page({ params }: { params: { id: string } }) {
- let donasiId = params.id;
- const totalAkumulasi = await Donasi_getTotalPencairanDanaById(donasiId);
- const listPencairan = await donasi_funGetListPencairanDanaById({page: 1, donasiId: donasiId});
+ // let donasiId = params.id;
+ // const totalAkumulasi = await Donasi_getTotalPencairanDanaById(donasiId);
+ // const listPencairan = await donasi_funGetListPencairanDanaById({page: 1, donasiId: donasiId});
return (
<>
>
);
diff --git a/src/app/dev/(user)/donasi/penggalang_dana/[id]/page.tsx b/src/app/dev/(user)/donasi/penggalang_dana/[id]/page.tsx
index 9e1f0370..c0aea8d6 100644
--- a/src/app/dev/(user)/donasi/penggalang_dana/[id]/page.tsx
+++ b/src/app/dev/(user)/donasi/penggalang_dana/[id]/page.tsx
@@ -1,13 +1,9 @@
import { PenggalangDanaDonasi } from "@/app_modules/donasi";
-import { Donasi_getAuthorById } from "@/app_modules/donasi/fun/get/get_author_by_id";
-
-export default async function Page({ params }: { params: { id: string } }) {
- let authorId = params.id;
- const dataPenggalang = await Donasi_getAuthorById(authorId);
+export default async function Page() {
return (
<>
-
+
>
);
}
diff --git a/src/app_modules/admin/donasi/detail/publish/pencairan_dana.tsx b/src/app_modules/admin/donasi/detail/publish/pencairan_dana.tsx
index fbcddaee..8bb2847e 100644
--- a/src/app_modules/admin/donasi/detail/publish/pencairan_dana.tsx
+++ b/src/app_modules/admin/donasi/detail/publish/pencairan_dana.tsx
@@ -49,20 +49,19 @@ export default function AdminDonasi_PencairanDana() {
useShallowEffect(() => {
loadInitialData();
- }, [])
+ }, []);
const loadInitialData = async () => {
try {
const response = await apiGetAdminDonasiById({
id: donasiId,
- })
+ });
if (response?.success && response?.data) {
- setData(response.data)
- console.log("ini respone data", response.data)
+ setData(response.data);
// setTerkumpul(response.data.terkumpul)
// setTotal(response.data.totalPencairan)
} else {
- setData(null)
+ setData(null);
// setTerkumpul("")
// setTotal(0)
}
@@ -72,20 +71,22 @@ export default function AdminDonasi_PencairanDana() {
// setTerkumpul("");
// setTotal(0);
}
- }
+ };
return (
<>
- {!data ?
- (
- )
- : (
+ {!data ? (
+
+ ) : (
<>
-
-
+ {
@@ -95,7 +96,7 @@ export default function AdminDonasi_PencairanDana() {
/>
>
)}
-
+
>
);
}
@@ -109,8 +110,6 @@ function TotalDanaView({
}) {
const terkumpul = toNumber(danaTerkumpul);
const sisaDana = terkumpul - totalPencairan;
- console.log("Sisa dana", sisaDana);
- console.log("Terkumpul", terkumpul);
return (
<>
@@ -121,7 +120,9 @@ function TotalDanaView({
bg={AdminColor.softBlue}
>
- Dana Tersisa
+
+ Dana Tersisa
+
{
void;
- }) {
-
-
+}) {
const router = useRouter();
const [file, setFile] = useState(null);
const [images, setImages] = useState();
@@ -176,61 +175,63 @@ function FormView({
if (_.values(body).includes(""))
return ComponentAdminGlobal_NotifikasiPeringatan("Lengkapi Data");
- const uploadImage = await funGlobal_UploadToStorage({
- file: file as File,
- dirId: DIRECTORY_ID.donasi_bukti_trf_pencairan_dana,
- });
- if (!uploadImage.success)
- return ComponentAdminGlobal_NotifikasiPeringatan(
- "Gagal upload file gambar"
- );
-
- const res = await AdminDonasi_funCreatePencairanDana({
- data: body as any,
- fileId: uploadImage.data.id,
- });
- if (res.status === 200) {
+ try {
setIsLoading(true);
- const res2 = await AdminDonasi_AkumulasiPencairanById(
- body.donasiId as any,
- body.nominalCair as any
- );
- if (res2.status === 200) {
- const loadData = await apiGetAdminDonasiById({id: donasiId});
- onSuccess(loadData);
- console.log("load Data", loadData);
+ const uploadImage = await funGlobal_UploadToStorage({
+ file: file as File,
+ dirId: DIRECTORY_ID.donasi_bukti_trf_pencairan_dana,
+ });
+ if (!uploadImage.success)
+ return ComponentAdminGlobal_NotifikasiPeringatan(
+ "Gagal upload file gambar"
+ );
- const dataNotif = {
- appId: loadData?.data?.id,
- userId: loadData?.data?.authorId,
- pesan: loadData?.data?.title as any,
- status: "Pencairan Dana",
- kategoriApp: "DONASI",
- title: "Dana donasi berhasil dicairkan",
- };
+ const res = await AdminDonasi_funCreatePencairanDana({
+ data: body as any,
+ fileId: uploadImage.data.id,
+ });
+ if (res.status === 200) {
+ const res2 = await AdminDonasi_AkumulasiPencairanById(
+ body.donasiId as any,
+ body.nominalCair as any
+ );
+ if (res2.status === 200) {
+ const loadData = await apiGetAdminDonasiById({ id: donasiId });
+ onSuccess(loadData);
- console.log("Data Notif", dataNotif);
+ const dataNotif = {
+ appId: loadData?.data?.id,
+ userId: loadData?.data?.authorId,
+ pesan: loadData?.data?.title as any,
+ status: "Pencairan Dana",
+ kategoriApp: "DONASI",
+ title: "Dana donasi berhasil dicairkan",
+ };
- const notif = await adminNotifikasi_funCreateToUser({
- data: dataNotif as any,
- });
+ const notif = await adminNotifikasi_funCreateToUser({
+ data: dataNotif as any,
+ });
- if (notif.status === 201) {
- mqtt_client.publish(
- "USER",
- JSON.stringify({ userId: loadData?.authorId, count: 1 })
- );
+ if (notif.status === 201) {
+ mqtt_client.publish(
+ "USER",
+ JSON.stringify({ userId: loadData?.authorId, count: 1 })
+ );
+ }
+
+ ComponentAdminGlobal_NotifikasiBerhasil(res2.message);
+ router.back();
+ setIsLoading(false);
+ } else {
+ ComponentAdminGlobal_NotifikasiGagal(res2.message);
+ setIsLoading(false);
}
-
- ComponentAdminGlobal_NotifikasiBerhasil(res2.message);
- router.back();
- setIsLoading(false);
} else {
- ComponentAdminGlobal_NotifikasiGagal(res2.message);
+ ComponentAdminGlobal_NotifikasiGagal(res.message);
setIsLoading(false);
}
- } else {
- ComponentAdminGlobal_NotifikasiGagal(res.message);
+ } catch (error) {
+ ComponentAdminGlobal_NotifikasiGagal("Terjadi kesalahan");
setIsLoading(false);
}
}
@@ -238,9 +239,15 @@ function FormView({
return (
<>
-
+
- Form Pencairan Dana
+
+ Form Pencairan Dana
+
>
);
-}
\ No newline at end of file
+}
diff --git a/src/app_modules/donasi/component/card_view/box_informasi_pencarian_dana.tsx b/src/app_modules/donasi/component/card_view/box_informasi_pencarian_dana.tsx
index 55ef5371..39384152 100644
--- a/src/app_modules/donasi/component/card_view/box_informasi_pencarian_dana.tsx
+++ b/src/app_modules/donasi/component/card_view/box_informasi_pencarian_dana.tsx
@@ -4,27 +4,59 @@ import _ from "lodash";
import ComponentGlobal_Loader from "@/app_modules/_global/component/loader";
import { ScrollOnly } from "next-scroll-loader";
-import { useRouter } from "next/navigation";
+import { useParams, useRouter } from "next/navigation";
import { useState } from "react";
import { donasi_funGetListPencairanDanaById } from "../../fun/get/get_list_pencairan_dana_by_id";
import { MODEL_DONASI_PENCAIRAN_DANA } from "../../model/interface";
-import { ComponentDonasi_CardDonatur } from "./ui_card_donatur";
import { ComponentDonasi_CardPencairanDana } from "./card_pencairan_dana";
+import { useShallowEffect } from "@mantine/hooks";
+import { apiGetDonasiPencairanDanaById } from "../../lib/api_donasi";
+import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
-export function ComponentDonasi_InformasiPencairanDana({
- donasiId,
- listPD,
-}: {
- donasiId: string;
- listPD: MODEL_DONASI_PENCAIRAN_DANA[];
-}) {
- const router = useRouter();
- const [data, setData] = useState(listPD);
+export function ComponentDonasi_InformasiPencairanDana() {
+ const param = useParams<{ id: string }>();
+ const [data, setData] = useState(null);
const [activePage, setActivePage] = useState(1);
+ useShallowEffect(() => {
+ onLoadData();
+ }, [param.id]);
+
+ async function onLoadData() {
+ try {
+ const response = await apiGetDonasiPencairanDanaById({
+ id: param.id,
+ page: activePage,
+ });
+ if (response.success) {
+ setData(response.data);
+ }
+ } catch (error) {
+ console.error(error);
+ }
+ }
+
+ const onLoadMoreData = async () => {
+ try {
+ const nextPage = activePage + 1;
+ setActivePage(nextPage);
+ const response = await apiGetDonasiPencairanDanaById({
+ id: param.id,
+ page: nextPage,
+ });
+ if (response.success) {
+ return response.data;
+ }
+ } catch (error) {
+ console.error(error);
+ }
+ };
+
+ if (!data) return ;
+
return (
<>
- {_.isEmpty(listPD) ? (
+ {_.isEmpty(data) ? (
) : (
@@ -36,17 +68,8 @@ export function ComponentDonasi_InformasiPencairanDana({
)}
data={data}
- setData={setData}
- moreData={async () => {
- const loadData = await donasi_funGetListPencairanDanaById({
- page: activePage + 1,
- donasiId: donasiId,
- });
-
- setActivePage((val) => val + 1);
-
- return loadData;
- }}
+ setData={setData as any}
+ moreData={onLoadMoreData}
>
{(item) => }
diff --git a/src/app_modules/donasi/component/card_view/box_pencairan_dana.tsx b/src/app_modules/donasi/component/card_view/box_pencairan_dana.tsx
index 5705e1c7..4e857987 100644
--- a/src/app_modules/donasi/component/card_view/box_pencairan_dana.tsx
+++ b/src/app_modules/donasi/component/card_view/box_pencairan_dana.tsx
@@ -3,8 +3,40 @@ import ComponentGlobal_BoxInformation from "@/app_modules/_global/component/box_
import { Paper, Stack, Grid, Title, Text } from "@mantine/core";
import { MODEL_DONASI } from "../../model/interface";
import TampilanRupiahDonasi from "../tampilan_rupiah";
+import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
+import { useShallowEffect } from "@mantine/hooks";
+import { useParams } from "next/navigation";
+import { useState } from "react";
+import { apiGetOneDonasiById } from "../../lib/api_donasi";
-export function ComponentDonasi_BoxPencariranDana({ akumulasi }: { akumulasi: MODEL_DONASI }) {
+export function ComponentDonasi_BoxPencariranDana() {
+ const param = useParams<{ id: string }>();
+ const [data, setData] = useState(null);
+ const [loading, setLoading] = useState(true);
+
+ useShallowEffect(() => {
+ getData();
+ }, []);
+
+ async function getData() {
+ try {
+ setLoading(true);
+ const response = await apiGetOneDonasiById(param.id, "semua");
+
+ if (response.success) {
+ setData(response.data);
+ }
+ } catch (error) {
+ console.error(error);
+ } finally {
+ setLoading(false);
+ }
+ }
+
+ if (loading || !data) {
+ return ;
+ }
+
return (
<>
-
+
Dana sudah dicairkan
- {akumulasi.akumulasiPencairan} kali
+ {data.akumulasiPencairan} kali
Pencairan dana
diff --git a/src/app_modules/donasi/component/card_view/card_pencairan_dana.tsx b/src/app_modules/donasi/component/card_view/card_pencairan_dana.tsx
index e2071bee..2bcc7104 100644
--- a/src/app_modules/donasi/component/card_view/card_pencairan_dana.tsx
+++ b/src/app_modules/donasi/component/card_view/card_pencairan_dana.tsx
@@ -1,19 +1,9 @@
-import {
- AccentColor,
- MainColor,
-} from "@/app_modules/_global/color/color_pallet";
-import {
- Button,
- Center,
- Paper,
- Spoiler,
- Stack,
- Text,
- Title,
-} from "@mantine/core";
+import { MainColor } from "@/app_modules/_global/color/color_pallet";
+import { Button, Center, Spoiler, Stack, Text, Title } from "@mantine/core";
import { IconImageInPicture } from "@tabler/icons-react";
import moment from "moment";
+import { ComponentGlobal_CardStyles } from "@/app_modules/_global/component";
import { RouterImagePreview } from "@/lib";
import { useRouter } from "next/navigation";
import { useState } from "react";
@@ -29,15 +19,7 @@ export function ComponentDonasi_CardPencairanDana({
return (
<>
-
+
{moment(data.createdAt).format("ll")}
{data.title}
@@ -68,7 +50,7 @@ export function ComponentDonasi_CardPencairanDana({
-
+
>
);
}
diff --git a/src/app_modules/donasi/detail/detail_main/pencairan_dana/index.tsx b/src/app_modules/donasi/detail/detail_main/pencairan_dana/index.tsx
index 7abd386c..2a56ba4f 100644
--- a/src/app_modules/donasi/detail/detail_main/pencairan_dana/index.tsx
+++ b/src/app_modules/donasi/detail/detail_main/pencairan_dana/index.tsx
@@ -6,30 +6,27 @@ import {
MODEL_DONASI,
MODEL_DONASI_PENCAIRAN_DANA,
} from "@/app_modules/donasi/model/interface";
-import {
- Stack
-} from "@mantine/core";
+import { Stack } from "@mantine/core";
import { useState } from "react";
-export default function PencairanDanaDonasi({
- donasiId,
- totalAkumulasi,
- listPencairan,
-}: {
- donasiId: string;
- totalAkumulasi: MODEL_DONASI;
- listPencairan: MODEL_DONASI_PENCAIRAN_DANA[];
-}) {
- const [akumulasi, setAkumulasi] = useState(totalAkumulasi);
- const [listPD, setListPD] = useState(listPencairan);
+export default function PencairanDanaDonasi(
+ {
+ // donasiId,
+ // totalAkumulasi,
+ // listPencairan,
+ }: {
+ // donasiId: string;
+ // totalAkumulasi: MODEL_DONASI;
+ // listPencairan: MODEL_DONASI_PENCAIRAN_DANA[];
+ }
+) {
+ // const [akumulasi, setAkumulasi] = useState(totalAkumulasi);
+ // const [listPD, setListPD] = useState(listPencairan);
return (
<>
-
-
+
+
>
);
diff --git a/src/app_modules/donasi/detail/detail_main/penggalang_dana/index.tsx b/src/app_modules/donasi/detail/detail_main/penggalang_dana/index.tsx
index 3e52a8d8..85d33143 100644
--- a/src/app_modules/donasi/detail/detail_main/penggalang_dana/index.tsx
+++ b/src/app_modules/donasi/detail/detail_main/penggalang_dana/index.tsx
@@ -1,16 +1,16 @@
"use client";
-import { pathAssetImage, RouterImagePreview } from "@/lib";
-import { RouterDonasi } from "@/lib/router_hipmi/router_donasi";
import {
ComponentGlobal_CardStyles,
ComponentGlobal_LoaderAvatar,
} from "@/app_modules/_global/component";
+import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
import ComponentDonasi_CardPublish from "@/app_modules/donasi/component/card_view/card_publish";
-import {
- MODEL_DONASI_INFO_PENGGALANG
-} from "@/app_modules/donasi/model/interface";
+import { apiGetDonasiPenggalangDanaByUserId } from "@/app_modules/donasi/lib/api_donasi";
+import { MODEL_DONASI_INFO_PENGGALANG } from "@/app_modules/donasi/model/interface";
import { MODEL_USER } from "@/app_modules/home/model/interface";
+import { pathAssetImage, RouterImagePreview } from "@/lib";
+import { RouterDonasi } from "@/lib/router_hipmi/router_donasi";
import {
ActionIcon,
Box,
@@ -18,18 +18,36 @@ import {
Image,
Stack,
Text,
- Title
+ Title,
} from "@mantine/core";
+import { useShallowEffect } from "@mantine/hooks";
import { IconBrandGmail, IconMoodSmile, IconPhone } from "@tabler/icons-react";
-import { useRouter } from "next/navigation";
+import { useParams, useRouter } from "next/navigation";
import { useState } from "react";
-export default function PenggalangDanaDonasi({
- dataPenggalang,
-}: {
- dataPenggalang: MODEL_DONASI_INFO_PENGGALANG;
-}) {
- const [data, setData] = useState(dataPenggalang);
+export default function PenggalangDanaDonasi() {
+ const param = useParams<{ id: string }>();
+ const [data, setData] = useState(null);
+
+ useShallowEffect(() => {
+ onLoadData();
+ }, []);
+
+ async function onLoadData() {
+ try {
+ const response = await apiGetDonasiPenggalangDanaByUserId({
+ id: param.id,
+ });
+
+ if (response.success) {
+ setData(response.data);
+ }
+ } catch (error) {
+ console.error(error);
+ }
+ }
+
+ if (!data) return ;
return (
<>
diff --git a/src/app_modules/donasi/lib/api_donasi.ts b/src/app_modules/donasi/lib/api_donasi.ts
index 6da2c031..b8a6975c 100644
--- a/src/app_modules/donasi/lib/api_donasi.ts
+++ b/src/app_modules/donasi/lib/api_donasi.ts
@@ -214,38 +214,117 @@ export const apiGetCountDonatur = async ({ id }: { id: string }) => {
};
export const apiGetDonasiKabarById = async ({ id }: { id: 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;
- }
-
- const response = await fetch(`/api/donasi/kabar/${id}`, {
- method: "GET",
- headers: {
- "Content-Type": "application/json",
- Accept: "application/json",
- Authorization: `Bearer ${token}`,
- },
- });
-
- if (!response.ok) {
- const errorData = await response.json().catch(() => null);
- console.error(
- "Failed to get donasi kabar",
- response.statusText,
- errorData
- );
- throw new Error(errorData?.message || "Failed to get donasi kabar");
- }
-
- // Return the JSON response
- const data = await response.json();
- return data;
- } catch (error) {
- console.error("Error get donasi kabar", error);
- throw error; // Re-throw the error to handle it in the calling function
+ 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;
}
- };
\ No newline at end of file
+
+ const response = await fetch(`/api/donasi/kabar/${id}`, {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ Authorization: `Bearer ${token}`,
+ },
+ });
+
+ if (!response.ok) {
+ const errorData = await response.json().catch(() => null);
+ console.error(
+ "Failed to get donasi kabar",
+ response.statusText,
+ errorData
+ );
+ throw new Error(errorData?.message || "Failed to get donasi kabar");
+ }
+
+ // Return the JSON response
+ const data = await response.json();
+ return data;
+ } catch (error) {
+ console.error("Error get donasi kabar", error);
+ throw error; // Re-throw the error to handle it in the calling function
+ }
+};
+
+export const apiGetDonasiPenggalangDanaByUserId = async ({ id }: { id: 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;
+ }
+
+ const response = await fetch(`/api/donasi/${id}/penggalang-dana`, {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ Authorization: `Bearer ${token}`,
+ },
+ });
+
+ if (!response.ok) {
+ const errorData = await response.json().catch(() => null);
+ console.error(
+ "Failed to get donasi penggalang dana",
+ response.statusText,
+ errorData
+ );
+ throw new Error(
+ errorData?.message || "Failed to get donasi penggalang dana"
+ );
+ }
+
+ // Return the JSON response
+ const data = await response.json();
+ return data;
+ } catch (error) {
+ console.error("Error get donasi penggalang dana", error);
+ throw error; // Re-throw the error to handle it in the calling function
+ }
+}
+
+export const apiGetDonasiPencairanDanaById = async ({ id, page }: { id: string, page: number }) => {
+ 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;
+ }
+
+ const response = await fetch(`/api/donasi/${id}/pencairan-dana?page=${page}`, {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ Authorization: `Bearer ${token}`,
+ },
+ });
+
+ if (!response.ok) {
+ const errorData = await response.json().catch(() => null);
+ console.error(
+ "Failed to get donasi pencairan dana",
+ response.statusText,
+ errorData
+ );
+ throw new Error(
+ errorData?.message || "Failed to get donasi pencairan dana"
+ );
+ }
+
+ // Return the JSON response
+ const data = await response.json();
+ return data;
+ } catch (error) {
+ console.error("Error get donasi pencairan dana", error);
+ throw error; // Re-throw the error to handle it in the calling function
+ }
+}
+
\ No newline at end of file