fix: donasi

deskripsi:
- perubahan metode pengambilan data dari use server menjadi API:
src/app/api/donasi/[id]/pencairan-dana/route.ts
src/app/api/donasi/[id]/penggalang-dana/route.ts
src/app/dev/(user)/donasi/pencairan_dana/[id]/page.tsx
src/app/dev/(user)/donasi/penggalang_dana/[id]/page.tsx
src/app_modules/admin/donasi/detail/publish/pencairan_dana.tsx
src/app_modules/donasi/component/card_view/box_informasi_pencarian_dana.tsx
src/app_modules/donasi/component/card_view/box_pencairan_dana.tsx
src/app_modules/donasi/component/card_view/card_pencairan_dana.tsx
src/app_modules/donasi/detail/detail_main/pencairan_dana/index.tsx
src/app_modules/donasi/detail/detail_main/penggalang_dana/index.tsx
src/app_modules/donasi/lib/api_donasi.ts

No Issue
This commit is contained in:
2025-06-10 10:21:39 +08:00
parent 4fdfb6f4b0
commit 9c5f0053b6
11 changed files with 455 additions and 196 deletions

View File

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