fix saham investasi

This commit is contained in:
2025-03-05 14:04:37 +08:00
parent a5f40b99e4
commit 8e2da169fc
6 changed files with 160 additions and 40 deletions

View File

@@ -0,0 +1,60 @@
import { NextResponse } from "next/server";
export { GET };
async function GET(request: Request, { params }: { params: { id: string } }) {
try {
const { id } = params;
const data = await prisma.investasi_Invoice.findFirst({
where: {
id: id,
},
include: {
MasterBank: true,
StatusInvoice: {
where: {
name: "Berhasil",
}
},
Investasi: {
include: {
MasterPembagianDeviden: true,
MasterPencarianInvestor: true,
MasterPeriodeDeviden: true,
ProspektusInvestasi: true,
Investasi_Invoice: {
where: {
statusInvoiceId: "1",
},
},
},
},
Author: {
include: {
Profile: true,
},
},
},
});
const { ...allData } = data;
const Investor = data?.Investasi?.Investasi_Invoice;
const result = { ...allData, Investor };
return NextResponse.json({
success: true,
message: "Berhasil mengambil data",
data: result,
});
} catch (error) {
console.log(error);
return NextResponse.json(
{
success: false,
message: "Gagal mengambil data",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}

View File

@@ -3,11 +3,11 @@ import { Investasi_UiDetailSahamSaya } from "@/app_modules/investasi/_ui";
export default async function Page({ params }: { params: { id: string } }) {
const invoiceId = params.id;
const dataSaham = await investasi_funGetOneInvoiceById({ invoiceId });
// const dataSaham = await investasi_funGetOneInvoiceById({ invoiceId });
return (
<>
<Investasi_UiDetailSahamSaya dataSaham={dataSaham} />
<Investasi_UiDetailSahamSaya />
</>
);
}

View File

@@ -2,6 +2,7 @@ export {
apiFetchGetAllInvestasi,
apiNewGetOneInvestasiById,
apiGetInvestorById,
apiGetOneSahamInvestasiById,
};
const apiFetchGetAllInvestasi = async ({ page }: { page: string }) => {
@@ -114,3 +115,44 @@ const apiGetInvestorById = async ({
throw error; // Re-throw the error to handle it in the calling function
}
};
const apiGetOneSahamInvestasiById = 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/investasi/saham/${id}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${token}`,
},
});
// Check if the response is OK
if (!response.ok) {
const errorData = await response.json().catch(() => null);
console.error(
"Failed to get list investor",
response.statusText,
errorData
);
throw new Error(errorData?.message || "Failed to get list investor");
}
// Return the JSON response
return await response.json();
} catch (error) {
console.error("Error get list investor", error);
throw error; // Re-throw the error to handle it in the calling function
}
};

View File

@@ -1,25 +1,22 @@
"use client";
import { MainColor } from "@/app_modules/_global/color";
import {
UIGlobal_Drawer,
UIGlobal_LayoutHeaderTamplate,
UIGlobal_LayoutTamplate,
} from "@/app_modules/_global/ui";
import {
NEW_RouterInvestasi
} from "@/lib/router_hipmi/router_investasi";
import { ActionIcon } from "@mantine/core";
import { IconCategoryPlus, IconDotsVertical } from "@tabler/icons-react";
import { MODEL_INVESTASI } from "../../_lib/interface";
import { Investasi_ViewDetailPublish } from "../../_view";
import { useShallowEffect } from "@mantine/hooks";
import { IconCategoryPlus, IconDeviceIpadPlus, IconDotsVertical } from "@tabler/icons-react";
import { useParams, useRouter } from "next/navigation";
import { useState } from "react";
import {
NEW_RouterInvestasi,
RouterInvestasi_OLD,
} from "@/lib/router_hipmi/router_investasi";
import { IconDeviceIpadPlus } from "@tabler/icons-react";
import { MainColor } from "@/app_modules/_global/color";
import { useShallowEffect } from "@mantine/hooks";
import { apiNewGetOneInvestasiById } from "../../_lib/api_fetch_new_investasi";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
import { MODEL_INVESTASI } from "../../_lib/interface";
import { Investasi_ViewDetailPublish } from "../../_view";
export function Investasi_UiDetailMain({
userLoginId,
@@ -31,21 +28,6 @@ export function Investasi_UiDetailMain({
const [openDrawer, setOpenDrawer] = useState(false);
const [data, setData] = useState<MODEL_INVESTASI | null>(null);
const listPage = [
{
id: "1",
name: "Tambah & Edit Dokumen",
icon: <IconCategoryPlus />,
path: NEW_RouterInvestasi.rekap_dokumen({ id: data?.id as any }),
},
{
id: "2",
name: "Tambah & Edit Berita",
icon: <IconDeviceIpadPlus />,
path: NEW_RouterInvestasi.rekap_berita({ id: data?.id as any }),
},
];
useShallowEffect(() => {
handleLoadData();
}, []);
@@ -65,6 +47,21 @@ export function Investasi_UiDetailMain({
}
};
const listPage = [
{
id: "1",
name: "Tambah & Edit Dokumen",
icon: <IconCategoryPlus />,
path: NEW_RouterInvestasi.rekap_dokumen({ id: data?.id as any }),
},
{
id: "2",
name: "Tambah & Edit Berita",
icon: <IconDeviceIpadPlus />,
path: NEW_RouterInvestasi.rekap_berita({ id: data?.id as any }),
},
];
return (
<>
<UIGlobal_LayoutTamplate

View File

@@ -4,13 +4,13 @@ import UIGlobal_LayoutHeaderTamplate from "@/app_modules/_global/ui/ui_header_ta
import UIGlobal_LayoutTamplate from "@/app_modules/_global/ui/ui_layout_tamplate";
import { Investasi_ViewDetailSahamSaya } from "../../_view";
export function Investasi_UiDetailSahamSaya({ dataSaham }: { dataSaham: any }) {
export function Investasi_UiDetailSahamSaya() {
return (
<>
<UIGlobal_LayoutTamplate
header={<UIGlobal_LayoutHeaderTamplate title="Detail Saham" />}
>
<Investasi_ViewDetailSahamSaya dataSaham={dataSaham as any} />
<Investasi_ViewDetailSahamSaya />
</UIGlobal_LayoutTamplate>
</>
);

View File

@@ -5,21 +5,42 @@ import {
Investasi_ComponentBoxHargaDanLembarSaham,
Investasi_ComponentBoxProgress,
} from "../../_component";
import { MODEL_INVOICE_INVESTASI } from "../../_lib/interface";
import { MODEL_INVESTASI, MODEL_INVOICE_INVESTASI } from "../../_lib/interface";
import { useShallowEffect } from "@mantine/hooks";
import { apiGetOneSahamInvestasiById, apiNewGetOneInvestasiById } from "../../_lib/api_fetch_new_investasi";
import { useParams } from "next/navigation";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
export function Investasi_ViewDetailSahamSaya({
dataSaham,
}: {
dataSaham: MODEL_INVOICE_INVESTASI;
}) {
const [data, setData] = useState(dataSaham);
export function Investasi_ViewDetailSahamSaya() {
const param = useParams<{ id: string }>();
const [data, setData] = useState<MODEL_INVOICE_INVESTASI | null>(null);
useShallowEffect(() => {
handleLoadData();
}, []);
const handleLoadData = async () => {
try {
const response = await apiGetOneSahamInvestasiById({ id: param.id });
if (response.success) {
setData(response.data);
} else {
setData(null);
}
} catch (error) {
console.error("Error get investasi", error);
setData(null);
}
};
if (!data) return <CustomSkeleton height={"80vh"} width={"100%"} />;
return (
<>
<Stack mb={"lg"}>
<Investasi_ComponentBoxHargaDanLembarSaham data={data} />
<Investasi_ComponentBoxProgress progress={data.Investasi.progress} />
<Investasi_ComponentBoxDetailData data={data} />
<Investasi_ComponentBoxHargaDanLembarSaham data={data as any} />
<Investasi_ComponentBoxProgress progress={data?.Investasi?.progress as any} />
<Investasi_ComponentBoxDetailData data={data as any} />
</Stack>
</>
);