fix bug:
deskripsi: - bug donasi cerita penggalangan dana - bug login
This commit is contained in:
34
src/app/api/donasi/[id]/cerita-penggalang/route.ts
Normal file
34
src/app/api/donasi/[id]/cerita-penggalang/route.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
export { GET };
|
||||
|
||||
async function GET(req: Request, { params }: { params: { id: string } }) {
|
||||
try {
|
||||
const donasiId = params.id;
|
||||
const data = await prisma.donasi_Cerita.findFirst({
|
||||
where: {
|
||||
donasiId: donasiId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
pembukaan: true,
|
||||
cerita: true,
|
||||
imageCeritaDonasi: true,
|
||||
createdAt: 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,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
import { CeritaPenggalangDonasi } from "@/app_modules/donasi";
|
||||
import Donasi_getCeritaByDonasiId from "@/app_modules/donasi/fun/get/get_cerita_penggalang";
|
||||
|
||||
export default async function Page({ params }: { params: { id: string } }) {
|
||||
const dataCerita = await Donasi_getCeritaByDonasiId(params.id);
|
||||
// console.log(dataCerita)
|
||||
export default async function Page() {
|
||||
// const dataCerita = await Donasi_getCeritaByDonasiId(params.id);
|
||||
return (
|
||||
<>
|
||||
<CeritaPenggalangDonasi dataCerita={dataCerita as any}/>
|
||||
<CeritaPenggalangDonasi />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -57,8 +57,8 @@ export const Comp_ButtonSticker = ({
|
||||
<Text fw={"bold"} color="gray">
|
||||
Sticker belum tersedia
|
||||
</Text>
|
||||
<Text color="gray" fw={"bold"}>
|
||||
Silahkan hubungi admin untuk info lebih lanjut
|
||||
<Text color="gray" fw={"bold"} align="center">
|
||||
Silahkan hubungi admin
|
||||
</Text>
|
||||
</Stack>
|
||||
</Center>
|
||||
|
||||
@@ -163,10 +163,11 @@ function ButtonOnHeader({
|
||||
|
||||
const newData = await AdminDonasi_getOneById(donasi?.id);
|
||||
setData(newData);
|
||||
// router.back()
|
||||
ComponentAdminGlobal_NotifikasiBerhasil(
|
||||
"Berhasil Mengubah Status Donasi"
|
||||
);
|
||||
router.back()
|
||||
setLoadingPublish(false);
|
||||
} else {
|
||||
setLoadingPublish(false);
|
||||
ComponentAdminGlobal_NotifikasiPeringatan(
|
||||
|
||||
@@ -33,13 +33,13 @@ export default function Login({ version }: { version: string }) {
|
||||
setLoading(true);
|
||||
const respone = await apiFetchLogin({ nomor: nomor });
|
||||
|
||||
if (respone) {
|
||||
if (respone && respone.success) {
|
||||
localStorage.setItem("hipmi_auth_code_id", respone.kodeId);
|
||||
ComponentGlobal_NotifikasiBerhasil(respone.message, 2000);
|
||||
router.push("/validasi", { scroll: false });
|
||||
} else {
|
||||
setLoading(false);
|
||||
ComponentGlobal_NotifikasiPeringatan(respone.message);
|
||||
ComponentGlobal_NotifikasiPeringatan(respone?.message);
|
||||
}
|
||||
} catch (error) {
|
||||
setLoading(false);
|
||||
|
||||
@@ -2,47 +2,71 @@
|
||||
|
||||
import { AccentColor } from "@/app_modules/_global/color/color_pallet";
|
||||
import { ComponentGlobal_LoadImageLandscape } from "@/app_modules/_global/component";
|
||||
import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data";
|
||||
import { Comp_SetInnerHTML } from "@/app_modules/_global/component/new/comp_set_inner_html";
|
||||
import { Comp_V3_SetInnerHTMLWithStiker } from "@/app_modules/_global/component/new/comp_V3_set_html_with_stiker";
|
||||
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
||||
import { apiGetDonasiCeritaPenggalang } from "@/app_modules/donasi/lib/api_donasi";
|
||||
import { MODEL_CERITA_DONASI } from "@/app_modules/donasi/model/interface";
|
||||
import { Stack, Text } from "@mantine/core";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { useParams } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import moment from "moment";
|
||||
import "moment/locale/id";
|
||||
import { ComponentGlobal_NotifikasiGagal, ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global";
|
||||
|
||||
export default function CeritaPenggalangDonasi() {
|
||||
const param = useParams<{ id: string }>();
|
||||
|
||||
const [data, setData] = useState<MODEL_CERITA_DONASI | null>(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 <CustomSkeleton height={"200px"} />;
|
||||
|
||||
export default function CeritaPenggalangDonasi({
|
||||
dataCerita,
|
||||
}: {
|
||||
dataCerita: MODEL_CERITA_DONASI;
|
||||
}) {
|
||||
const [data, setData] = useState(dataCerita);
|
||||
return (
|
||||
<>
|
||||
{/* <pre>{JSON.stringify(data.imageCeritaDonasi, null, 2)}</pre> */}
|
||||
<Stack
|
||||
style={{
|
||||
padding: "15px",
|
||||
backgroundColor: AccentColor.darkblue,
|
||||
borderRadius: "10px",
|
||||
border: `2px solid ${AccentColor.blue}`,
|
||||
color: "white",
|
||||
marginBottom: "15px",
|
||||
}}
|
||||
>
|
||||
<Text>
|
||||
{new Intl.DateTimeFormat("id-ID", { dateStyle: "full" }).format(
|
||||
data.createdAt
|
||||
)}
|
||||
</Text>
|
||||
<Text fw={"bold"}> #HaloOrangBaik</Text>
|
||||
{/* <Text>{data.pembukaan}</Text> */}
|
||||
{data === null ? (
|
||||
<ComponentGlobal_IsEmptyData />
|
||||
) : (
|
||||
<Stack
|
||||
style={{
|
||||
padding: "15px",
|
||||
backgroundColor: AccentColor.darkblue,
|
||||
borderRadius: "10px",
|
||||
border: `2px solid ${AccentColor.blue}`,
|
||||
color: "white",
|
||||
marginBottom: "15px",
|
||||
}}
|
||||
>
|
||||
<Text>
|
||||
{moment(data?.createdAt).format("DD MMMM YYYY")}
|
||||
</Text>
|
||||
<Text fw={"bold"}> #HaloOrangBaik</Text>
|
||||
|
||||
<Comp_SetInnerHTML props={data?.pembukaan} />
|
||||
<Comp_SetInnerHTML props={data?.pembukaan || ""} />
|
||||
|
||||
<ComponentGlobal_LoadImageLandscape fileId={data.imageId} />
|
||||
<ComponentGlobal_LoadImageLandscape fileId={data?.imageId || ""} />
|
||||
|
||||
<Comp_SetInnerHTML props={data?.cerita} />
|
||||
|
||||
{/* <Text>{data.cerita}</Text> */}
|
||||
</Stack>
|
||||
<Comp_SetInnerHTML props={data?.cerita || ""} />
|
||||
</Stack>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user