fix: donasi

deskripsi:
- ubah use server menjadi API
src/app/dev/(user)/donasi/detail/donasi_saya/[id]/page.tsx
src/app/dev/(user)/donasi/detail/main/[id]/layout.tsx
src/app/dev/(user)/donasi/detail/main/[id]/page.tsx
src/app/dev/(user)/donasi/detail/publish/[id]/page.tsx
src/app/dev/(user)/donasi/detail/reject/[id]/page.tsx
src/app_modules/admin/donasi/detail/detail_review.tsx
src/app_modules/donasi/detail/detail_draft/index.tsx
src/app_modules/donasi/detail/detail_publish/index.tsx
src/app_modules/donasi/detail/detail_reject/index.tsx
src/app_modules/donasi/detail/detail_review/index.tsx

No Issue
This commit is contained in:
2025-06-09 10:20:06 +08:00
parent 0e4dda5356
commit 1b23c50ff0
10 changed files with 240 additions and 193 deletions

View File

@@ -6,12 +6,16 @@ import { Donasi_getOneInvoiceById } from "@/app_modules/donasi/fun/get/get_one_i
export default async function Page({ params }: { params: { id: string } }) { export default async function Page({ params }: { params: { id: string } }) {
let invoiceId = params.id; let invoiceId = params.id;
const dataDonasi = await Donasi_getOneInvoiceById(invoiceId); const dataDonasi = await Donasi_getOneInvoiceById(invoiceId);
const countDonatur= await Donasi_getCountDonatur(dataDonasi?.donasiId as any) const countDonatur = await Donasi_getCountDonatur(
dataDonasi?.donasiId as any
);
return ( return (
<> <>
<DetailDonasiSaya dataDonasi={dataDonasi as any} countDonatur={countDonatur} /> <DetailDonasiSaya
dataDonasi={dataDonasi as any}
countDonatur={countDonatur}
/>
</> </>
); );
} }

View File

@@ -1,22 +1,10 @@
import { LayoutDetailMainDonasiNew } from "@/app_modules/donasi"; import { LayoutDetailMainDonasiNew } from "@/app_modules/donasi";
import React from "react"; import React from "react";
export default async function Layout({ children, params, }: { children: React.ReactNode; params: { id: string }; }) { export default async function Layout({ children }: { children: React.ReactNode; }) {
// const donasiId = params.id;
// const getData = await Donasi_getOneById(donasiId);
// const authorId = getData?.authorId;
// const userLoginId = await funGetUserIdByToken();
return ( return (
<> <>
{/* <LayoutDetailMainDonasi
donasiId={donasiId}
authorId={authorId as any}
userLoginId={userLoginId as string}
>
{children}
</LayoutDetailMainDonasi> */}
<LayoutDetailMainDonasiNew> <LayoutDetailMainDonasiNew>
{children} {children}
</LayoutDetailMainDonasiNew> </LayoutDetailMainDonasiNew>

View File

@@ -1,19 +1,8 @@
import DetailMainDonasiNew from "@/app_modules/donasi/detail/detail_main/index_new"; import DetailMainDonasiNew from "@/app_modules/donasi/detail/detail_main/index_new";
export default async function Page({ params }: { params: { id: string } }) { export default async function Page() {
// let donasiId = params.id;
// const userLoginId = await funGetUserIdByToken();
// const dataDonasi = await Donasi_getOneById(donasiId);
// const countDonatur = await Donasi_getCountDonatur(donasiId);
return ( return (
<> <>
{/* <DetailMainDonasi
dataDonasi={dataDonasi as any}
countDonatur={countDonatur}
userLoginId={userLoginId as string}
/> */}
<DetailMainDonasiNew /> <DetailMainDonasiNew />
</> </>
); );

View File

@@ -1,20 +1,9 @@
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import { DetailPublishDonasi } from "@/app_modules/donasi"; import { DetailPublishDonasi } from "@/app_modules/donasi";
import { Donasi_getCountDonatur } from "@/app_modules/donasi/fun/count/get_count_donatur";
import { Donasi_getOneById } from "@/app_modules/donasi/fun/get/get_one_donasi_by_id";
export default async function Page({ params }: { params: { id: string } }) {
const dataPublish = await Donasi_getOneById(params.id);
const countDonatur = await Donasi_getCountDonatur(params.id);
const userLoginId = await funGetUserIdByToken();
export default async function Page() {
return ( return (
<> <>
<DetailPublishDonasi <DetailPublishDonasi />
dataPublish={dataPublish as any}
countDonatur={countDonatur}
userLoginId={userLoginId as string}
/>
</> </>
); );
} }

View File

@@ -1,14 +1,9 @@
import { DetailRejectDonasi } from "@/app_modules/donasi"; import { DetailRejectDonasi } from "@/app_modules/donasi";
import { Donasi_getOneById } from "@/app_modules/donasi/fun/get/get_one_donasi_by_id";
export default async function Page({params}: {params: {id: string}}) { export default async function Page() {
let donasiId= params.id return (
const dataReject = await Donasi_getOneById(donasiId) <>
const fileIdImageCerita = dataReject?.CeritaDonasi?.imageId <DetailRejectDonasi />
</>
return ( );
<> }
<DetailRejectDonasi dataReject={dataReject as any} fileIdImageCerita={fileIdImageCerita as any}/>
</>
);
}

View File

@@ -38,7 +38,7 @@ export default function AdminDonasi_DetailReview() {
try { try {
const response = await apiGetAdminDonasiById({ const response = await apiGetAdminDonasiById({
id: params.id, id: params.id,
}) });
if (response?.success && response?.data) { if (response?.success && response?.data) {
setData(response.data); setData(response.data);
@@ -50,14 +50,14 @@ export default function AdminDonasi_DetailReview() {
clientLogger.error("Invalid data format recieved:", error); clientLogger.error("Invalid data format recieved:", error);
setData(null); setData(null);
} }
} };
loadInitialData(); loadInitialData();
}) });
return ( return (
<> <>
<Stack> <Stack>
{!data ? ( {!data ? (
<SkeletonAdminDetailDonasiReview /> <SkeletonAdminDetailDonasiReview />
) : ( ) : (
<> <>
<ButtonOnHeader donasi={data} setData={setData} /> <ButtonOnHeader donasi={data} setData={setData} />
@@ -77,7 +77,7 @@ export default function AdminDonasi_DetailReview() {
</SimpleGrid> </SimpleGrid>
</> </>
)} )}
</Stack > </Stack>
</> </>
); );
} }
@@ -92,8 +92,10 @@ function ButtonOnHeader({
const router = useRouter(); const router = useRouter();
const [isLoadingPublish, setLoadingPublish] = useState(false); const [isLoadingPublish, setLoadingPublish] = useState(false);
const [isLoadingReject, setLoadingReject] = useState(false); const [isLoadingReject, setLoadingReject] = useState(false);
const [openedPublish, { open: openPublish, close: closePublish }] = useDisclosure(false); const [openedPublish, { open: openPublish, close: closePublish }] =
const [openedReject, { open: openReject, close: closeReject }] = useDisclosure(false); useDisclosure(false);
const [openedReject, { open: openReject, close: closeReject }] =
useDisclosure(false);
const [catatan, setCatatan] = useState(""); const [catatan, setCatatan] = useState("");
async function onPublish() { async function onPublish() {
@@ -152,7 +154,6 @@ function ButtonOnHeader({
title: "Donasi baru terpublish", title: "Donasi baru terpublish",
}; };
WibuRealtime.setData({ WibuRealtime.setData({
type: "notification", type: "notification",
pushNotificationTo: "USER", pushNotificationTo: "USER",
@@ -161,13 +162,11 @@ function ButtonOnHeader({
} }
} }
const newData = await AdminDonasi_getOneById(donasi?.id);
setData(newData);
ComponentAdminGlobal_NotifikasiBerhasil( ComponentAdminGlobal_NotifikasiBerhasil(
"Berhasil Mengubah Status Donasi" "Berhasil Mengubah Status Donasi"
); );
router.back()
setLoadingPublish(false); setLoadingPublish(false);
router.back();
} else { } else {
setLoadingPublish(false); setLoadingPublish(false);
ComponentAdminGlobal_NotifikasiPeringatan( ComponentAdminGlobal_NotifikasiPeringatan(
@@ -190,46 +189,52 @@ function ButtonOnHeader({
"Lengkapi Alasan Penolakan" "Lengkapi Alasan Penolakan"
); );
const checkStatus = await donasi_checkStatus({ id: donasi.id }); try {
setLoadingReject(true);
const checkStatus = await donasi_checkStatus({ id: donasi.id });
if (checkStatus) { if (checkStatus) {
const res = await AdminDonasi_funUpdateStatusReject( const res = await AdminDonasi_funUpdateStatusReject(
donasi.id, donasi.id,
"4", "4",
catatan catatan
); );
if (res.status === 200) { if (res.status === 200) {
const dataNotifikasi: IRealtimeData = { const dataNotifikasi: IRealtimeData = {
appId: res.data?.id as string, appId: res.data?.id as string,
status: res.data?.DonasiMaster_Status?.name as any, status: res.data?.DonasiMaster_Status?.name as any,
userId: res.data?.authorId as any, userId: res.data?.authorId as any,
pesan: res.data?.title as any, pesan: res.data?.title as any,
kategoriApp: "DONASI", kategoriApp: "DONASI",
title: "Donasi anda di tolak !", title: "Donasi anda di tolak !",
}; };
const notif = await adminNotifikasi_funCreateToUser({ const notif = await adminNotifikasi_funCreateToUser({
data: dataNotifikasi as any, data: dataNotifikasi as any,
});
if (notif.status === 201) {
WibuRealtime.setData({
type: "notification",
pushNotificationTo: "USER",
dataMessage: dataNotifikasi,
}); });
const newData = await AdminDonasi_getOneById(donasi?.id); if (notif.status === 201) {
setData(newData); WibuRealtime.setData({
close(); type: "notification",
ComponentAdminGlobal_NotifikasiBerhasil(res.message); pushNotificationTo: "USER",
setLoadingReject(true); dataMessage: dataNotifikasi,
});
ComponentAdminGlobal_NotifikasiBerhasil(res.message);
closeReject();
router.back()
}
} else {
setLoadingReject(false);
ComponentAdminGlobal_NotifikasiGagal(res.message);
} }
} else { } else {
ComponentAdminGlobal_NotifikasiGagal(res.message); setLoadingReject(false);
ComponentGlobal_NotifikasiPeringatan("Status donasi telah diubah user");
} }
} else { } catch (error) {
ComponentGlobal_NotifikasiPeringatan("Status donasi telah diubah user"); setLoadingReject(false);
console.error("Error to reject donasi", error);
} }
} }
@@ -332,10 +337,6 @@ function ButtonOnHeader({
} }
/> />
{/* <Modal {/* <Modal
opened={opened} opened={opened}
onClose={close} onClose={close}

View File

@@ -23,33 +23,33 @@ import { useParams } from "next/navigation";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
export default function DetailDraftDonasi() { export default function DetailDraftDonasi() {
const param = useParams<{ id: string }>(); const param = useParams<{ id: string }>();
const [data, setData] = useState({} as MODEL_DONASI); const [data, setData] = useState({} as MODEL_DONASI);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
useShallowEffect(() => { useShallowEffect(() => {
getData(); getData();
}, []); }, []);
async function getData() { async function getData() {
try { try {
setLoading(true); setLoading(true);
const response = await apiGetOneDonasiById(param.id, "semua"); const response = await apiGetOneDonasiById(param.id, "semua");
if (response.success) { if (response.success) {
setData(response.data); setData(response.data);
}
} catch (error) {
console.error(error);
} finally {
setLoading(false);
} }
} catch (error) {
console.error(error);
} finally {
setLoading(false);
} }
}
if (loading) {
return <CustomSkeleton height={400} />; if (loading) {
} return <CustomSkeleton height={400} />;
}
return ( return (
<> <>
<Stack spacing={"xl"} py={"md"}> <Stack spacing={"xl"} py={"md"}>
@@ -108,7 +108,7 @@ function ButtonAjukanPenggalangan({
}); });
ComponentGlobal_NotifikasiBerhasil("Berhasil Diajukan"); ComponentGlobal_NotifikasiBerhasil("Berhasil Diajukan");
router.push(RouterDonasi.status_galang_dana({ id: "2" })); router.replace(RouterDonasi.status_galang_dana({ id: "2" }));
} }
} else { } else {
setLoadingAjukan(false); setLoadingAjukan(false);

View File

@@ -1,34 +1,74 @@
"use client"; "use client";
import { import { Stack } from "@mantine/core";
Stack
} from "@mantine/core";
import { useState } from "react"; import { useState } from "react";
import ComponentDonasi_CeritaPenggalangMain from "../../component/detail_main/cerita_penggalang"; import ComponentDonasi_CeritaPenggalangMain from "../../component/detail_main/cerita_penggalang";
import { ComponentDonasi_DetailDataMain } from "../../component/detail_main/detail_data_donasi"; import { ComponentDonasi_DetailDataMain } from "../../component/detail_main/detail_data_donasi";
import ComponentDonasi_InformasiPenggalangMain from "../../component/detail_main/informasi_penggalang"; import ComponentDonasi_InformasiPenggalangMain from "../../component/detail_main/informasi_penggalang";
import { MODEL_DONASI } from "../../model/interface"; import { MODEL_DONASI } from "../../model/interface";
import { apiGetOneDonasiById } from "../../lib/api_donasi";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
import { useShallowEffect } from "@mantine/hooks";
import { useParams } from "next/navigation";
import { apiNewGetUserIdByToken } from "@/app_modules/_global/lib/api_fetch_global";
export default function DetailPublishDonasi({ export default function DetailPublishDonasi() {
dataPublish, const param = useParams<{ id: string }>();
countDonatur, const [data, setData] = useState<MODEL_DONASI | null>(null);
userLoginId const [countDonatur, setCountDonatur] = useState<number | null>(null);
}: { const [userLoginId, setUserLoginId] = useState<string | null>(null);
dataPublish: MODEL_DONASI; const [loading, setLoading] = useState(false);
countDonatur: number,
userLoginId: string useShallowEffect(() => {
}) { handleGetUserId();
const [donasi, setDonasi] = useState(dataPublish); onLoadData();
}, []);
async function handleGetUserId() {
try {
const response = await apiNewGetUserIdByToken();
if (response) {
setUserLoginId(response.userId);
}
} catch (error) {
console.error(error);
}
}
async function onLoadData() {
try {
setLoading(true);
const response = await apiGetOneDonasiById(param.id, "semua");
const responseCountDonatur = await apiGetOneDonasiById(param.id, "count");
if (response.success) {
setData(response.data);
}
if (responseCountDonatur.success) {
setCountDonatur(responseCountDonatur.data);
}
} catch (error) {
console.error(error);
} finally {
setLoading(false);
}
}
if (loading || !userLoginId || !data || countDonatur === null) {
return <CustomSkeleton height={400} />;
}
return ( return (
<> <>
{/* <pre>{JSON.stringify(donasi,null,2)}</pre> */} {/* <pre>{JSON.stringify(donasi,null,2)}</pre> */}
<Stack spacing={"xl"} pb={"lg"}> <Stack spacing={"xl"} pb={"lg"}>
<ComponentDonasi_DetailDataMain donasi={donasi} countDonatur={countDonatur} userLoginId={userLoginId}/> <ComponentDonasi_DetailDataMain
<ComponentDonasi_InformasiPenggalangMain author={donasi.Author}/> donasi={data as any}
<ComponentDonasi_CeritaPenggalangMain donasi={donasi} /> countDonatur={countDonatur as any}
userLoginId={userLoginId}
/>
<ComponentDonasi_InformasiPenggalangMain author={data?.Author as any} />
<ComponentDonasi_CeritaPenggalangMain donasi={data as any} />
</Stack> </Stack>
</> </>
); );
} }

View File

@@ -10,7 +10,7 @@ import {
} from "@/app_modules/_global/notif_global"; } from "@/app_modules/_global/notif_global";
import UIGlobal_Modal from "@/app_modules/_global/ui/ui_modal"; import UIGlobal_Modal from "@/app_modules/_global/ui/ui_modal";
import { Button, Group, Stack } from "@mantine/core"; import { Button, Group, Stack } from "@mantine/core";
import { useRouter } from "next/navigation"; import { useParams, useRouter } from "next/navigation";
import { useState } from "react"; import { useState } from "react";
import ComponentDonasi_DetailDataGalangDana from "../../component/detail_galang_dana/detail_data_donasi"; import ComponentDonasi_DetailDataGalangDana from "../../component/detail_galang_dana/detail_data_donasi";
import ComponentDonasi_CeritaPenggalangMain from "../../component/detail_main/cerita_penggalang"; import ComponentDonasi_CeritaPenggalangMain from "../../component/detail_main/cerita_penggalang";
@@ -18,15 +18,38 @@ import { Donasi_funDeleteDonasiById } from "../../fun/delete/fin_delete_donasi_b
import { Donasi_funGantiStatus } from "../../fun/update/fun_ganti_status"; import { Donasi_funGantiStatus } from "../../fun/update/fun_ganti_status";
import { MODEL_DONASI } from "../../model/interface"; import { MODEL_DONASI } from "../../model/interface";
import { AccentColor, MainColor } from "@/app_modules/_global/color"; import { AccentColor, MainColor } from "@/app_modules/_global/color";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
import { useShallowEffect } from "@mantine/hooks";
import { apiGetOneDonasiById } from "../../lib/api_donasi";
export default function DetailRejectDonasi() {
const param = useParams<{ id: string }>();
const [data, setData] = useState({} as MODEL_DONASI);
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) {
return <CustomSkeleton height={400} />;
}
export default function DetailRejectDonasi({
dataReject,
fileIdImageCerita,
}: {
dataReject: MODEL_DONASI;
fileIdImageCerita: string;
}) {
const [data, setData] = useState(dataReject);
return ( return (
<> <>
<Stack spacing={"xl"} pb={"md"}> <Stack spacing={"xl"} pb={"md"}>
@@ -35,7 +58,7 @@ export default function DetailRejectDonasi({
<ComponentDonasi_CeritaPenggalangMain donasi={data} /> <ComponentDonasi_CeritaPenggalangMain donasi={data} />
<ButtonAction <ButtonAction
donasiId={data.id} donasiId={data.id}
fileIdImageCerita={fileIdImageCerita} fileIdImageCerita={data.CeritaDonasi.imageId}
imageId={data.imageId} imageId={data.imageId}
/> />
</Stack> </Stack>
@@ -59,44 +82,54 @@ function ButtonAction({
const [isLoadingDelete, setLoadingDelete] = useState(false); const [isLoadingDelete, setLoadingDelete] = useState(false);
async function onChangeStatus() { async function onChangeStatus() {
await Donasi_funGantiStatus(donasiId, "3").then((res) => { try {
if (res.status === 200) { setLoadingEdit(true);
setLoadingEdit(true); await Donasi_funGantiStatus(donasiId, "3").then((res) => {
ComponentGlobal_NotifikasiBerhasil(res.message); if (res.status === 200) {
router.replace(RouterDonasi.status_galang_dana({ id: "3" })); ComponentGlobal_NotifikasiBerhasil(res.message);
} else { router.replace(RouterDonasi.status_galang_dana({ id: "3" }));
ComponentGlobal_NotifikasiGagal(res.message); } else {
setLoadingEdit(true); ComponentGlobal_NotifikasiGagal(res.message);
} setLoadingEdit(true);
}); }
});
} catch (error) {
console.error(error);
setLoadingEdit(false);
}
} }
async function onDelete() { async function onDelete() {
const del = await Donasi_funDeleteDonasiById(donasiId); try {
if (del.status === 200) {
setLoadingDelete(true); setLoadingDelete(true);
const deleteImageDonasi = await funGlobal_DeleteFileById({ const del = await Donasi_funDeleteDonasiById(donasiId);
fileId: imageId as any, if (del.status === 200) {
}); const deleteImageDonasi = await funGlobal_DeleteFileById({
fileId: imageId as any,
});
if (!deleteImageDonasi.success) { if (!deleteImageDonasi.success) {
ComponentGlobal_NotifikasiPeringatan("Gagal hapus gambar "); ComponentGlobal_NotifikasiPeringatan("Gagal hapus gambar ");
setLoadingDelete(false);
}
const deleteImageCerita = await funGlobal_DeleteFileById({
fileId: fileIdImageCerita as any,
});
if (!deleteImageCerita.success) {
ComponentGlobal_NotifikasiPeringatan("Gagal hapus gambar ");
setLoadingDelete(false);
}
router.replace(RouterDonasi.status_galang_dana({ id: "4" }));
ComponentGlobal_NotifikasiBerhasil(del.message);
setLoadingDelete(false);
} else {
ComponentGlobal_NotifikasiGagal(del.message);
setLoadingDelete(false); setLoadingDelete(false);
} }
} catch (error) {
const deleteImageCerita = await funGlobal_DeleteFileById({ console.error(error);
fileId: fileIdImageCerita as any,
});
if (!deleteImageCerita.success) {
ComponentGlobal_NotifikasiPeringatan("Gagal hapus gambar ");
setLoadingDelete(false);
}
router.replace(RouterDonasi.status_galang_dana({ id: "4" }));
ComponentGlobal_NotifikasiBerhasil(del.message);
setLoadingDelete(false);
} else {
ComponentGlobal_NotifikasiGagal(del.message);
setLoadingDelete(false); setLoadingDelete(false);
} }
} }
@@ -105,7 +138,7 @@ function ButtonAction({
<Group grow> <Group grow>
<Button <Button
radius={"xl"} radius={"xl"}
style={{ backgroundColor: AccentColor.yellow}} style={{ backgroundColor: AccentColor.yellow }}
c={MainColor.darkblue} c={MainColor.darkblue}
onClick={() => setOpenModalEdit(true)} onClick={() => setOpenModalEdit(true)}
> >
@@ -127,8 +160,12 @@ function ButtonAction({
opened={openModaEdit} opened={openModaEdit}
close={() => setOpenModalEdit(false)} close={() => setOpenModalEdit(false)}
buttonKiri={ buttonKiri={
<Button style={{ backgroundColor: AccentColor.blue }} <Button
c={AccentColor.white} radius={"xl"} onClick={() => setOpenModalEdit(false)}> style={{ backgroundColor: AccentColor.blue }}
c={AccentColor.white}
radius={"xl"}
onClick={() => setOpenModalEdit(false)}
>
Batal Batal
</Button> </Button>
} }
@@ -152,8 +189,12 @@ function ButtonAction({
opened={openModalDelete} opened={openModalDelete}
close={() => setOpenModalDelete(false)} close={() => setOpenModalDelete(false)}
buttonKiri={ buttonKiri={
<Button style={{ backgroundColor: AccentColor.blue }} <Button
c={AccentColor.white} radius={"xl"} onClick={() => setOpenModalDelete(false)}> style={{ backgroundColor: AccentColor.blue }}
c={AccentColor.white}
radius={"xl"}
onClick={() => setOpenModalDelete(false)}
>
Batal Batal
</Button> </Button>
} }

View File

@@ -96,7 +96,7 @@ function ButtonBatalReview({ donasi }: { donasi: MODEL_DONASI }) {
}); });
} }
ComponentGlobal_NotifikasiBerhasil("Berhasil Dibatalkan"); ComponentGlobal_NotifikasiBerhasil("Berhasil Dibatalkan");
router.push(RouterDonasi.status_galang_dana({ id: "3" })); router.replace(RouterDonasi.status_galang_dana({ id: "3" }));
} else { } else {
setLoading(false); setLoading(false);
ComponentGlobal_NotifikasiPeringatan(res.message); ComponentGlobal_NotifikasiPeringatan(res.message);