fix : donasi
deksripsi: - mengant use server menjadi api src/app/api/donasi/[id]/invoice/count/route.ts src/app/api/donasi/[id]/invoice/route.ts src/app/api/donasi/kabar/[id]/route.ts src/app/dev/(user)/donasi/cerita_penggalang/[id]/layout.tsx src/app/dev/(user)/donasi/cerita_penggalang/[id]/page.tsx src/app/dev/(user)/donasi/detail/donasi_saya/[id]/page.tsx src/app/dev/(user)/donasi/detail/kabar/[id]/page.tsx src/app/dev/(user)/donasi/proses_donasi/invoice/[id]/page.tsx src/app_modules/admin/donasi/detail/publish/detail_list_donatur.tsx src/app_modules/admin/donasi/fun/update/fun_update_status_dan_total.ts src/app_modules/donasi/detail/detail_donasi_saya/index.tsx src/app_modules/donasi/detail/detail_kabar/index.tsx src/app_modules/donasi/detail/detail_main/cerita_penggalang/layout.tsx src/app_modules/donasi/lib/api_donasi.ts src/app_modules/donasi/proses_donasi/invoice/index.tsx No Issue
This commit is contained in:
@@ -8,15 +8,48 @@ import ComponentDonasi_InformasiPenggalangMain from "../../component/detail_main
|
||||
import TampilanRupiahDonasi from "../../component/tampilan_rupiah";
|
||||
import { MODEL_DONASI_INVOICE } from "../../model/interface";
|
||||
import { AccentColor } from "@/app_modules/_global/color/color_pallet";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { useParams } from "next/navigation";
|
||||
import { apiGetCountDonatur, apiGetDonasiInvoiceById } from "../../lib/api_donasi";
|
||||
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
||||
|
||||
export default function DetailDonasiSaya() {
|
||||
const params = useParams<{ id: string }>();
|
||||
const invoiceId = params.id;
|
||||
const [invoice, setInvoice] = useState<MODEL_DONASI_INVOICE | null>(null);
|
||||
const [countDonatur, setCountDonatur] = useState<number | null>(null);
|
||||
|
||||
useShallowEffect(() => {
|
||||
onLoadData();
|
||||
getCountDonatur();
|
||||
}, [invoiceId]);
|
||||
|
||||
async function onLoadData() {
|
||||
try {
|
||||
const response = await apiGetDonasiInvoiceById({ id: invoiceId });
|
||||
if (response.success) {
|
||||
setInvoice(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error fetching invoice data:", error);
|
||||
}
|
||||
}
|
||||
|
||||
async function getCountDonatur() {
|
||||
try {
|
||||
const response = await apiGetCountDonatur({ id: invoiceId });
|
||||
if (response.success) {
|
||||
setCountDonatur(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error fetching count donatur data:", error);
|
||||
}
|
||||
}
|
||||
|
||||
if (!invoice || countDonatur === null) {
|
||||
return <CustomSkeleton height={400} />;
|
||||
}
|
||||
|
||||
export default function DetailDonasiSaya({
|
||||
dataDonasi,
|
||||
countDonatur,
|
||||
}: {
|
||||
dataDonasi: MODEL_DONASI_INVOICE;
|
||||
countDonatur: number;
|
||||
}) {
|
||||
const [invoice, setInvoice] = useState(dataDonasi);
|
||||
return (
|
||||
<>
|
||||
<Stack pb={"lg"}>
|
||||
|
||||
@@ -7,13 +7,34 @@ import {
|
||||
import { Group, Stack, Text, Title } from "@mantine/core";
|
||||
import { useState } from "react";
|
||||
import { MODEL_DONASI_KABAR } from "../../model/interface";
|
||||
import { apiGetDonasiKabarById } from "../../lib/api_donasi";
|
||||
import { useParams } from "next/navigation";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
||||
|
||||
export default function DetailKabarDonasi() {
|
||||
const param = useParams<{ id: string }>();
|
||||
const [kabar, setKabar] = useState<MODEL_DONASI_KABAR | null>(null);
|
||||
|
||||
useShallowEffect(() => {
|
||||
onLoadData();
|
||||
}, []);
|
||||
|
||||
async function onLoadData() {
|
||||
try {
|
||||
const response = await apiGetDonasiKabarById({ id: param.id });
|
||||
if (response.success) {
|
||||
setKabar(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error fetching kabar data:", error);
|
||||
}
|
||||
}
|
||||
|
||||
if (!kabar) {
|
||||
return <CustomSkeleton />;
|
||||
}
|
||||
|
||||
export default function DetailKabarDonasi({
|
||||
dataDonasi,
|
||||
}: {
|
||||
dataDonasi: MODEL_DONASI_KABAR;
|
||||
}) {
|
||||
const [kabar, setKabar] = useState(dataDonasi);
|
||||
return (
|
||||
<>
|
||||
<ComponentGlobal_CardStyles>
|
||||
|
||||
@@ -6,55 +6,76 @@ import UI_NewLayoutTamplate, {
|
||||
UI_NewFooter,
|
||||
UI_NewHeader,
|
||||
} from "@/app_modules/_global/ui/V2_layout_tamplate";
|
||||
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
||||
import ButtonDonasi from "@/app_modules/donasi/component/footer_button_donasi";
|
||||
import React from "react";
|
||||
import { apiGetOneDonasiById } from "@/app_modules/donasi/lib/api_donasi";
|
||||
import { MODEL_DONASI } from "@/app_modules/donasi/model/interface";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { useParams } from "next/navigation";
|
||||
import React, { useState } from "react";
|
||||
|
||||
export default function LayoutCeritaPenggalangDonasi({
|
||||
children,
|
||||
statusDonasiId,
|
||||
donasiId,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
statusDonasiId: string;
|
||||
donasiId: string;
|
||||
}) {
|
||||
if (statusDonasiId !== "1") {
|
||||
return (
|
||||
<>
|
||||
{/* <UIGlobal_LayoutTamplate
|
||||
header={
|
||||
<UIGlobal_LayoutHeaderTamplate title="Cerita Penggalang Dana" />
|
||||
}
|
||||
>
|
||||
{children}
|
||||
</UIGlobal_LayoutTamplate> */}
|
||||
const param = useParams<{ id: string }>();
|
||||
const [data, setData] = useState({} as MODEL_DONASI);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
<UI_NewLayoutTamplate>
|
||||
<UI_NewHeader>
|
||||
<Component_Header title="Cerita Penggalang Dana" />
|
||||
</UI_NewHeader>
|
||||
<UI_NewChildren>{children}</UI_NewChildren>
|
||||
</UI_NewLayoutTamplate>
|
||||
</>
|
||||
);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
// <UIGlobal_LayoutTamplate
|
||||
// header={<UIGlobal_LayoutHeaderTamplate title="Cerita Penggalang Dana" />}
|
||||
// footer={<ButtonDonasi donasiId={donasiId} />}
|
||||
// >
|
||||
// {children}
|
||||
// </UIGlobal_LayoutTamplate>
|
||||
// if (data?.donasiMaster_StatusDonasiId !== "1") {
|
||||
// return (
|
||||
// <>
|
||||
// <UI_NewLayoutTamplate>
|
||||
// <UI_NewHeader>
|
||||
// <Component_Header title="Cerita Penggalang Dana" />
|
||||
// </UI_NewHeader>
|
||||
// <UI_NewChildren>{children}</UI_NewChildren>
|
||||
// </UI_NewLayoutTamplate>
|
||||
// </>
|
||||
// );
|
||||
// }
|
||||
|
||||
return (
|
||||
<UI_NewLayoutTamplate>
|
||||
<UI_NewHeader>
|
||||
<Component_Header title="Cerita Penggalang Dana" />
|
||||
</UI_NewHeader>
|
||||
<UI_NewChildren>{children}</UI_NewChildren>
|
||||
<UI_NewFooter>
|
||||
<ButtonDonasi donasiId={donasiId} />
|
||||
</UI_NewFooter>
|
||||
<UI_NewChildren>
|
||||
{loading ? (
|
||||
<CustomSkeleton height={400} />
|
||||
) : (
|
||||
data?.donasiMaster_StatusDonasiId === "1" ? (
|
||||
children
|
||||
) : (
|
||||
<CustomSkeleton height={400} />
|
||||
)
|
||||
)}
|
||||
</UI_NewChildren>
|
||||
{data?.donasiMaster_StatusDonasiId === "1" && (
|
||||
<UI_NewFooter>
|
||||
<ButtonDonasi donasiId={data?.id as string} />
|
||||
</UI_NewFooter>
|
||||
)}
|
||||
</UI_NewLayoutTamplate>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -119,12 +119,12 @@ export const apiGetTemporaryCreate = async ({ id }: { id: string }) => {
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => null);
|
||||
console.error(
|
||||
"Failed to get donasi cerita penggalang",
|
||||
"Failed to get donasi temporary create",
|
||||
response.statusText,
|
||||
errorData
|
||||
);
|
||||
throw new Error(
|
||||
errorData?.message || "Failed to get donasi cerita penggalang"
|
||||
errorData?.message || "Failed to get donasi temporary create"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -132,7 +132,120 @@ export const apiGetTemporaryCreate = async ({ id }: { id: string }) => {
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error("Error get donasi cerita penggalang", error);
|
||||
console.error("Error get donasi temporary create", error);
|
||||
throw error; // Re-throw the error to handle it in the calling function
|
||||
}
|
||||
};
|
||||
|
||||
export const apiGetDonasiInvoiceById = 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}/invoice`, {
|
||||
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 invoice",
|
||||
response.statusText,
|
||||
errorData
|
||||
);
|
||||
throw new Error(errorData?.message || "Failed to get donasi invoice");
|
||||
}
|
||||
|
||||
// Return the JSON response
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error("Error get donasi invoice", error);
|
||||
throw error; // Re-throw the error to handle it in the calling function
|
||||
}
|
||||
};
|
||||
|
||||
export const apiGetCountDonatur = 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}/invoice/count`, {
|
||||
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 invoice count",
|
||||
response.statusText,
|
||||
errorData
|
||||
);
|
||||
throw new Error(
|
||||
errorData?.message || "Failed to get donasi invoice count"
|
||||
);
|
||||
}
|
||||
|
||||
// Return the JSON response
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error("Error get donasi invoice count", error);
|
||||
throw error; // Re-throw the error to handle it in the calling function
|
||||
}
|
||||
};
|
||||
|
||||
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
|
||||
}
|
||||
};
|
||||
@@ -1,52 +1,65 @@
|
||||
"use client";
|
||||
|
||||
import { DIRECTORY_ID } from "@/lib";
|
||||
import { IRealtimeData } from "@/lib/global_state";
|
||||
import { RouterDonasi } from "@/lib/router_hipmi/router_donasi";
|
||||
import {
|
||||
AccentColor,
|
||||
MainColor,
|
||||
} from "@/app_modules/_global/color/color_pallet";
|
||||
import { ComponentGlobal_ButtonUploadFileImage } from "@/app_modules/_global/component";
|
||||
import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
|
||||
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
|
||||
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
||||
import notifikasiToAdmin_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_admin";
|
||||
import { DIRECTORY_ID } from "@/lib";
|
||||
import { IRealtimeData } from "@/lib/global_state";
|
||||
import { RouterDonasi } from "@/lib/router_hipmi/router_donasi";
|
||||
import {
|
||||
Button,
|
||||
Center,
|
||||
CopyButton,
|
||||
FileButton,
|
||||
Grid,
|
||||
Group,
|
||||
Paper,
|
||||
Stack,
|
||||
Text,
|
||||
Title,
|
||||
Title
|
||||
} from "@mantine/core";
|
||||
import { IconCamera, IconCircleCheck } from "@tabler/icons-react";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { IconCircleCheck } from "@tabler/icons-react";
|
||||
import { useAtom } from "jotai";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { WibuRealtime } from "wibu-pkg";
|
||||
import TampilanRupiahDonasi from "../../component/tampilan_rupiah";
|
||||
import { Donasi_funUpdateStatusInvoice } from "../../fun/update/fun_update_status_invoice";
|
||||
import { gs_donasi_hot_menu } from "../../global_state";
|
||||
import { apiGetDonasiInvoiceById } from "../../lib/api_donasi";
|
||||
import { MODEL_DONASI_INVOICE } from "../../model/interface";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
import { ComponentGlobal_ButtonUploadFileImage } from "@/app_modules/_global/component";
|
||||
|
||||
export default function Donasi_InvoiceProses({
|
||||
dataInvoice,
|
||||
}: {
|
||||
dataInvoice: MODEL_DONASI_INVOICE;
|
||||
}) {
|
||||
const [invoice, setDataInvoice] = useState(dataInvoice);
|
||||
export default function Donasi_InvoiceProses() {
|
||||
const param = useParams<{ id: string }>();
|
||||
const [invoice, setDataInvoice] = useState<MODEL_DONASI_INVOICE | null>(null);
|
||||
const router = useRouter();
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
const [active, setActive] = useAtom(gs_donasi_hot_menu);
|
||||
const [isLoading, setLoading] = useState(false);
|
||||
|
||||
useShallowEffect(() => {
|
||||
onLoadInvoice();
|
||||
}, []);
|
||||
|
||||
async function onLoadInvoice() {
|
||||
try {
|
||||
const response = await apiGetDonasiInvoiceById({ id: param.id });
|
||||
if (response.success) {
|
||||
setDataInvoice(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
async function onClick() {
|
||||
try {
|
||||
setLoading(true);
|
||||
@@ -62,7 +75,7 @@ export default function Donasi_InvoiceProses({
|
||||
}
|
||||
|
||||
const res = await Donasi_funUpdateStatusInvoice({
|
||||
invoiceId: invoice.id,
|
||||
invoiceId: invoice?.id as any,
|
||||
statusId: "2",
|
||||
fileId: uploadImage.data.id,
|
||||
});
|
||||
@@ -88,7 +101,7 @@ export default function Donasi_InvoiceProses({
|
||||
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
setActive(2);
|
||||
router.push(RouterDonasi.proses_transaksi + `${invoice.id}`);
|
||||
router.push(RouterDonasi.proses_transaksi + `${invoice?.id}`);
|
||||
}
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
@@ -96,10 +109,14 @@ export default function Donasi_InvoiceProses({
|
||||
}
|
||||
} catch (error) {
|
||||
setLoading(false);
|
||||
clientLogger.error("Error upload data invoice", error);
|
||||
console.error("Error upload data invoice", error);
|
||||
}
|
||||
}
|
||||
|
||||
if (!invoice) {
|
||||
return <CustomSkeleton height={400} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack spacing={"lg"} py={"md"}>
|
||||
|
||||
Reference in New Issue
Block a user