(null);
+
+ useShallowEffect(() => {
+ const getData = async () => {
+ try {
+ const response = await apiGetDonasiCeritaPenggalang({ id: param.id });
+ if (response.success) {
+ setData(response.data);
+ } else {
+ ComponentGlobal_NotifikasiPeringatan(response.message);
+ }
+ } catch (error) {
+ ComponentGlobal_NotifikasiGagal("Terjadi error saat mengambil data");
+ }
+ };
+ getData();
+ }, []);
+
+
+
+ if (!data) return ;
-export default function CeritaPenggalangDonasi({
- dataCerita,
-}: {
- dataCerita: MODEL_CERITA_DONASI;
-}) {
- const [data, setData] = useState(dataCerita);
return (
<>
- {/* {JSON.stringify(data.imageCeritaDonasi, null, 2)} */}
-
-
- {new Intl.DateTimeFormat("id-ID", { dateStyle: "full" }).format(
- data.createdAt
- )}
-
- #HaloOrangBaik
- {/* {data.pembukaan} */}
+ {data === null ? (
+
+ ) : (
+
+
+ {moment(data?.createdAt).format("DD MMMM YYYY")}
+
+ #HaloOrangBaik
-
+
-
+
-
-
- {/* {data.cerita} */}
-
+
+
+ )}
>
);
}
diff --git a/src/app_modules/donasi/lib/api_donasi.ts b/src/app_modules/donasi/lib/api_donasi.ts
index c46cfc0b..b4511798 100644
--- a/src/app_modules/donasi/lib/api_donasi.ts
+++ b/src/app_modules/donasi/lib/api_donasi.ts
@@ -57,3 +57,39 @@ export const apiGetOneDonasiById = async (path: string, kategori: string) => {
});
return await response.json().catch(() => null);
};
+
+
+export const apiGetDonasiCeritaPenggalang = async ({ id }: { id: string }) => {
+ try {
+ console.log("id in Fetch>>", id);
+ // 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}/cerita-penggalang`, {
+ 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 cerita penggalang", response.statusText, errorData);
+ throw new Error(errorData?.message || "Failed to get donasi cerita penggalang");
+ }
+
+ // Return the JSON response
+ const data = await response.json();
+ console.log("data fetch>>", data);
+ return data;
+ } catch (error) {
+ console.error("Error get donasi cerita penggalang", error);
+ throw error; // Re-throw the error to handle it in the calling function
+ }
+};