Merge pull request #361 from bipproduction/bagas/4-mar-25

fix api investasi
This commit is contained in:
Bagasbanuna02
2025-03-05 10:26:34 +08:00
committed by GitHub
18 changed files with 258 additions and 60 deletions

View File

@@ -2,6 +2,8 @@
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
## [1.2.72](https://github.com/bipproduction/hipmi/compare/v1.2.71...v1.2.72) (2025-03-05)
## [1.2.71](https://github.com/bipproduction/hipmi/compare/v1.2.70...v1.2.71) (2025-03-04)
## [1.2.70](https://github.com/bipproduction/hipmi/compare/v1.2.69...v1.2.70) (2025-03-04)

View File

@@ -1,6 +1,6 @@
{
"name": "hipmi",
"version": "1.2.71",
"version": "1.2.72",
"private": true,
"prisma": {
"seed": "bun prisma/seed.ts"

View File

@@ -0,0 +1,49 @@
import { prisma } from "@/lib";
import { NextResponse } from "next/server";
export const dynamic = "force-dynamic";
// GET ONE DATA INVESTASI BY ID
export async function GET(
request: Request,
context: { params: { id: string } }
) {
try {
const { id } = context.params;
const data = await prisma.investasi.findUnique({
where: {
id: id,
},
include: {
author: {
include: {
Profile: true,
},
},
Investasi_Invoice: true,
MasterStatusInvestasi: true,
BeritaInvestasi: true,
DokumenInvestasi: true,
ProspektusInvestasi: true,
MasterPembagianDeviden: true,
MasterPencarianInvestor: true,
MasterPeriodeDeviden: true,
MasterProgresInvestasi: true,
},
});
return NextResponse.json(
{ success: true, message: "Berhasil mendapatkan data", data },
{ status: 200 }
);
} catch (error) {
console.error(error);
return NextResponse.json(
{
success: false,
message: "Gagal mendapatkan data, coba lagi nanti ",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,11 @@
import { Investasi_UiListInvestor } from "@/app_modules/investasi/_ui/detail/ui_list_investor";
async function Page() {
return (
<>
<Investasi_UiListInvestor />
</>
);
}
export default Page;

View File

@@ -1,20 +1,12 @@
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import { investasi_funGetOneInvestasiById } from "@/app_modules/investasi/_fun";
import { Investasi_UiDetailMain } from "@/app_modules/investasi/_ui";
export default async function Page({ params }: { params: { id: string } }) {
const investasiId = params.id;
export default async function Page() {
const userLoginId = await funGetUserIdByToken();
const dataInvestasi = await investasi_funGetOneInvestasiById({ investasiId });
return (
<>
<Investasi_UiDetailMain
dataInvestasi={dataInvestasi as any}
userLoginId={userLoginId as string}
/>
<Investasi_UiDetailMain userLoginId={userLoginId as string} />
</>
);
}

View File

@@ -15,8 +15,6 @@ function Event_Invoice({ userLoginId }: { userLoginId: string }) {
const [nominal, setNominal] = useAtom(gs_nominal_sponsor);
const [bankId, setBankId] = useAtom(gs_event_bank_id);
console.log("nominal >>", nominal);
console.log("bankId >>", bankId);
return (
<>

View File

@@ -110,6 +110,7 @@ async function onClick(
eventId: string,
setLoading: any
) {
setLoading(true);
const checkStatus = await event_checkStatus({ id: eventId });
if (checkStatus) {
@@ -141,13 +142,14 @@ async function onClick(
});
ComponentGlobal_NotifikasiBerhasil(res.message, 1500);
setLoading(true);
router.replace(RouterEvent.status({ id: "3" }));
}
} else {
setLoading(false);
ComponentGlobal_NotifikasiGagal(res.message);
}
} else {
router.back();
ComponentGlobal_NotifikasiPeringatan("Event telah direview admin");
}
}

View File

@@ -25,7 +25,6 @@ function Event_MetodePembayaran() {
const [nominal, setNominal] = useAtom(gs_nominal_sponsor);
const [bankId, setBankId] = useAtom(gs_event_bank_id);
const [isLoading, setIsLoading] = useState(false);
console.log("nominal >>", nominal);
const [data, setData] = useState<MODEL_MASTER_BANK[] | null>(null);
useShallowEffect(() => {

View File

@@ -77,8 +77,6 @@ function Event_TambahSponsor() {
data: data,
});
console.log("res >>", created);
if (created) {
router.replace(RouterEvent.nominal_sponsor({ id: params.id }));
ComponentGlobal_NotifikasiBerhasil(created.message);

View File

@@ -0,0 +1,43 @@
import { NEW_RouterInvestasi } from "@/lib/router_hipmi/router_investasi";
import { AccentColor, MainColor } from "@/app_modules/_global/color";
import { ActionIcon, Flex, Loader, Paper, Text } from "@mantine/core";
import { IconBookDownload, IconZoomMoney } from "@tabler/icons-react";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global";
export function Investasi_ComponentBoxInvestor({ id }: { id: string }) {
const router = useRouter();
const [isLoading, setLoading] = useState(false);
return (
<>
<Paper
style={{
padding: "15px",
backgroundColor: AccentColor.blue,
border: `2px solid ${AccentColor.softblue}`,
borderRadius: "10px",
color: "white",
}}
onClick={() => {
setLoading(true);
router.push(NEW_RouterInvestasi.list_investor({id:id}))
}}
>
<Flex direction={"column"} align={"center"} justify={"center"}>
<Text c={MainColor.white} fz={12}>
Investor
</Text>
<ActionIcon radius={"xl"} variant="transparent" size={60}>
{isLoading ? (
<Loader color="yellow" />
) : (
<IconZoomMoney size={70} color={MainColor.white} />
)}
</ActionIcon>
</Flex>
</Paper>
</>
);
}

View File

@@ -18,6 +18,7 @@ import { Investasi_ComponentDetailDataNonPublish } from "./detail/comp_detail_da
import { Investasi_ComponentButtonUpdateDataInvestasi } from "./button/comp_button_update_investasi";
import { Investasi_ComponentCardRekapDocument } from "./detail/comp_card_rekap_document";
import { Investasi_ComponentCardDaftarDocument } from "./detail/comp_card_daftar_document";
import { Investasi_ComponentBoxInvestor } from "./detail/comp_box_investor";
export { Investasi_ComponentFooterMain };
export { Investasi_ComponentCardBeranda };
@@ -39,3 +40,4 @@ export { Investasi_ComponentDetailDataNonPublish };
export { Investasi_ComponentButtonUpdateDataInvestasi };
export { Investasi_ComponentCardRekapDocument };
export { Investasi_ComponentCardDaftarDocument };
export { Investasi_ComponentBoxInvestor };

View File

@@ -1,4 +1,4 @@
export { apiFetchGetAllInvestasi };
export { apiFetchGetAllInvestasi, apiNewGetOneInvestasiById };
const apiFetchGetAllInvestasi = async ({ page }: { page: string }) => {
try {
@@ -33,3 +33,37 @@ const apiFetchGetAllInvestasi = async ({ page }: { page: string }) => {
throw error; // Re-throw the error to handle it in the calling function
}
};
const apiNewGetOneInvestasiById = 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/${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 all forum:", response.statusText, errorData);
throw new Error(errorData?.message || "Failed to get all forum");
}
// Return the JSON response
return await response.json();
} catch (error) {
console.error("Error get all forum", error);
throw error; // Re-throw the error to handle it in the calling function
}
};

View File

@@ -9,7 +9,7 @@ import { ActionIcon } from "@mantine/core";
import { IconCategoryPlus, IconDotsVertical } from "@tabler/icons-react";
import { MODEL_INVESTASI } from "../../_lib/interface";
import { Investasi_ViewDetailPublish } from "../../_view";
import { useRouter } from "next/navigation";
import { useParams, useRouter } from "next/navigation";
import { useState } from "react";
import {
NEW_RouterInvestasi,
@@ -17,32 +17,55 @@ import {
} 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";
export function Investasi_UiDetailMain({
dataInvestasi,
userLoginId,
}: {
dataInvestasi: MODEL_INVESTASI;
userLoginId: string;
}) {
const param = useParams<{ id: string }>();
const router = useRouter();
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: dataInvestasi.id }),
path: NEW_RouterInvestasi.rekap_dokumen({ id: data?.id as any }),
},
{
id: "2",
name: "Tambah & Edit Berita",
icon: <IconDeviceIpadPlus />,
path: NEW_RouterInvestasi.rekap_berita({ id: dataInvestasi.id }),
path: NEW_RouterInvestasi.rekap_berita({ id: data?.id as any }),
},
];
useShallowEffect(() => {
handleLoadData();
}, []);
const handleLoadData = async () => {
try {
const response = await apiNewGetOneInvestasiById({ id: param.id });
if (response.success) {
console.log(response.data);
setData(response.data);
} else {
setData(null);
}
} catch (error) {
console.error("Error get investasi", error);
setData(null);
}
};
return (
<>
<UIGlobal_LayoutTamplate
@@ -50,7 +73,7 @@ export function Investasi_UiDetailMain({
<UIGlobal_LayoutHeaderTamplate
title="Detail "
customButtonRight={
userLoginId === dataInvestasi.authorId ? (
userLoginId === data?.authorId ? (
<ActionIcon
variant="transparent"
onClick={() => setOpenDrawer(true)}
@@ -65,7 +88,7 @@ export function Investasi_UiDetailMain({
}
>
<Investasi_ViewDetailPublish
dataInvestasi={dataInvestasi}
data={data as any}
userLoginId={userLoginId}
/>
</UIGlobal_LayoutTamplate>

View File

@@ -0,0 +1,20 @@
"use client";
import {
UIGlobal_LayoutHeaderTamplate,
UIGlobal_LayoutTamplate,
} from "@/app_modules/_global/ui";
import { Stack } from "@mantine/core";
import { Investasi_ViewListInvestor } from "../../_view/detail/view_list_investor";
export function Investasi_UiListInvestor() {
return (
<>
<UIGlobal_LayoutTamplate
header={<UIGlobal_LayoutHeaderTamplate title="Daftar Investor" />}
>
<Investasi_ViewListInvestor />
</UIGlobal_LayoutTamplate>
</>
);
}

View File

@@ -20,8 +20,6 @@ export function Investasi_UiFileViewProspektus() {
const param = useParams<{ id: string }>();
const prospektusId = param.id;
console.log(">>", prospektusId);
const [pdfPages, setPdfPages] = useState<PageData[] | null>(null);
const [loading, setLoading] = useState<boolean>(true);
const [error, setError] = useState<string | null>(null);

View File

@@ -1,23 +1,22 @@
"use client";
import {
NEW_RouterInvestasi,
RouterInvestasi_OLD,
} from "@/lib/router_hipmi/router_investasi";
import { MainColor } from "@/app_modules/_global/color/color_pallet";
import {
ComponentGlobal_AvatarAndUsername,
ComponentGlobal_CardStyles,
ComponentGlobal_LoadImageLandscape,
} from "@/app_modules/_global/component";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
import {
Investasi_ComponentBoxDaftarBerita,
Investasi_ComponentBoxDaftarDokumen,
Investasi_ComponentBoxInvestor,
Investasi_ComponentBoxProgress,
Investasi_ComponentBoxProspektus,
Investasi_ComponentTitleAndValueInDetail,
} from "@/app_modules/investasi/_component";
import { MODEL_INVESTASI } from "@/app_modules/investasi/_lib/interface";
import { NEW_RouterInvestasi } from "@/lib/router_hipmi/router_investasi";
import {
Box,
Button,
@@ -28,25 +27,19 @@ import {
Title,
} from "@mantine/core";
import { useLocalStorage } from "@mantine/hooks";
import {
IconBookDownload,
IconFileDescription,
IconSpeakerphone,
} from "@tabler/icons-react";
import _ from "lodash";
import moment from "moment";
import { useRouter } from "next/navigation";
import { useState } from "react";
export default function Investasi_ViewDetailPublish({
dataInvestasi,
data,
userLoginId,
}: {
dataInvestasi: MODEL_INVESTASI;
data: MODEL_INVESTASI | null;
userLoginId: string;
}) {
const router = useRouter();
const [data, setData] = useState(dataInvestasi);
const [boxId, setBoxId] = useState(0);
const [isLoadingBox, setLoadingBox] = useState(false);
const [isLoadingButton, setLoadingButton] = useState(false);
@@ -62,26 +55,28 @@ export default function Investasi_ViewDetailPublish({
setLoadingButton(true);
//NEW
router.push(NEW_RouterInvestasi.pembelian + data.id, { scroll: false });
router.push(NEW_RouterInvestasi.pembelian + data?.id, { scroll: false });
setTotal(0);
setJumlah(0);
}
if (!data) return <CustomSkeleton height={"80vh"} width={"100%"} />;
return (
<Stack>
<Investasi_ComponentBoxProgress progress={data.progress} />
<Investasi_ComponentBoxProgress progress={data?.progress} />
<ComponentGlobal_CardStyles>
<Stack spacing={"xl"}>
<ComponentGlobal_AvatarAndUsername
profile={data.author.Profile as any}
profile={data?.author.Profile as any}
/>
<ComponentGlobal_LoadImageLandscape fileId={data.imageId} />
<ComponentGlobal_LoadImageLandscape fileId={data?.imageId} />
{/* Title dan Persentase */}
<Center>
<Title color={MainColor.white} order={3} align="center">
{_.startCase(data.title)}
{_.startCase(data?.title)}
</Title>
</Center>
@@ -90,7 +85,11 @@ export default function Investasi_ViewDetailPublish({
<Stack>
<Investasi_ComponentTitleAndValueInDetail
title="Investor"
value={<Text c={MainColor.white}>{data.Investasi_Invoice.length} </Text>}
value={
<Text c={MainColor.white}>
{data?.Investasi_Invoice.length}{" "}
</Text>
}
/>
<Investasi_ComponentTitleAndValueInDetail
title="Target Dana"
@@ -99,7 +98,7 @@ export default function Investasi_ViewDetailPublish({
Rp.{" "}
{new Intl.NumberFormat("id-ID", {
maximumSignificantDigits: 20,
}).format(+data.targetDana)}{" "}
}).format(+data?.targetDana)}{" "}
</Text>
}
/>
@@ -111,14 +110,18 @@ export default function Investasi_ViewDetailPublish({
Rp.{" "}
{new Intl.NumberFormat("id-ID", {
maximumSignificantDigits: 10,
}).format(+data.hargaLembar)}
}).format(+data?.hargaLembar)}
</Text>
}
/>
<Investasi_ComponentTitleAndValueInDetail
title={<Text c={MainColor.white} fs={"italic"}>Return Of Invesment (RoI)</Text>}
value={<Text c={MainColor.white}>{data.roi} %</Text>}
title={
<Text c={MainColor.white} fs={"italic"}>
Return Of Invesment (RoI)
</Text>
}
value={<Text c={MainColor.white}>{data?.roi} %</Text>}
/>
<Investasi_ComponentTitleAndValueInDetail
@@ -127,7 +130,7 @@ export default function Investasi_ViewDetailPublish({
<Text c={MainColor.white}>
{new Intl.NumberFormat("id-ID", {
maximumSignificantDigits: 10,
}).format(+data.totalLembar)}{" "}
}).format(+data?.totalLembar)}{" "}
lembar
</Text>
}
@@ -139,7 +142,7 @@ export default function Investasi_ViewDetailPublish({
<Text c={MainColor.white}>
{new Intl.NumberFormat("id-ID", {
maximumSignificantDigits: 10,
}).format(+data.sisaLembar)}{" "}
}).format(+data?.sisaLembar)}{" "}
lembar
</Text>
}
@@ -147,29 +150,42 @@ export default function Investasi_ViewDetailPublish({
<Investasi_ComponentTitleAndValueInDetail
title="Jadwal Pembagian"
value={<Text c={MainColor.white}>{data.MasterPembagianDeviden.name} Bulan </Text>}
value={
<Text c={MainColor.white}>
{data?.MasterPembagianDeviden.name} Bulan{" "}
</Text>
}
/>
<Investasi_ComponentTitleAndValueInDetail
title="Pembagian Deviden"
value={<Text c={MainColor.white}>{data.MasterPeriodeDeviden.name}</Text>}
value={
<Text c={MainColor.white}>
{data?.MasterPeriodeDeviden.name}
</Text>
}
/>
<Investasi_ComponentTitleAndValueInDetail
title="Pencarian Investor"
value={<Text c={MainColor.white}>{data.MasterPencarianInvestor.name} Hari </Text>}
value={
<Text c={MainColor.white}>
{data?.MasterPencarianInvestor.name} Hari{" "}
</Text>
}
/>
</Stack>
{/* List Box */}
<SimpleGrid
cols={3}
cols={4}
breakpoints={[
{ maxWidth: "62rem", cols: 3, spacing: "md" },
{ maxWidth: "48rem", cols: 2, spacing: "sm" },
{ maxWidth: "36rem", cols: 1, spacing: "sm" },
]}
>
<Investasi_ComponentBoxInvestor id={data?.id} />
<Investasi_ComponentBoxProspektus
prospektusFileId={data.prospektusFileId}
prospektusFileId={data?.prospektusFileId}
/>
<Investasi_ComponentBoxDaftarDokumen investasiId={data?.id} />
<Investasi_ComponentBoxDaftarBerita investasiId={data?.id} />
@@ -178,9 +194,9 @@ export default function Investasi_ViewDetailPublish({
</ComponentGlobal_CardStyles>
<Box my={"md"}>
{data.sisaLembar === "0" ||
Number(data.MasterPencarianInvestor.name) -
moment(new Date()).diff(new Date(data.countDown), "days") <=
{data?.sisaLembar === "0" ||
Number(data?.MasterPencarianInvestor.name) -
moment(new Date()).diff(new Date(data?.countDown), "days") <=
0 ? (
<Center mb={"md"}>
<Button disabled radius={50} variant="transparent">
@@ -189,7 +205,7 @@ export default function Investasi_ViewDetailPublish({
</Center>
) : (
<Box>
{userLoginId === data.authorId ? (
{userLoginId === data?.authorId ? (
<Center mb={"md"}>
<Button disabled radius={50}>
Investasi Ini Milik Anda

View File

@@ -0,0 +1,9 @@
"use client"
import { Text } from "@mantine/core"
export function Investasi_ViewListInvestor(){
return<>
<Text>ini list</Text>
</>
}

View File

@@ -111,6 +111,8 @@ export const NEW_RouterInvestasi = {
*/
edit_prospektus: ({ id }: { id: string }) =>
`/dev/investasi/edit/prospektus/${id}`,
list_investor: ({ id }: { id: string }) => `/dev/investasi/${id}/investor`,
};
export const RouterInvestasi_OLD = {