Update Versi 1.5.27 #32

Merged
bagasbanuna merged 1009 commits from staging into main 2025-12-17 12:22:28 +08:00
216 changed files with 7455 additions and 1185 deletions
Showing only changes of commit df6dcd6eb3 - Show all commits

View File

@@ -0,0 +1,39 @@
import { prisma } from "@/app/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,
},
select: {
id: true,
title: true,
targetDana: true,
hargaLembar: true,
totalLembar: true,
roi: true,
countDown: true,
catatan: true,
sisaLembar: true,
imageId: true,
masterPencarianInvestorId: true,
masterPeriodeDevidenId: true,
masterPembagianDevidenId: 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

@@ -1,39 +1,39 @@
import { investasi_funGetOneInvestasiById } from "@/app_modules/investasi/_fun";
import { Investasi_UiEditInvestasi } from "@/app_modules/investasi/_ui";
import { Investasi_UiEditInvestasi, Investasi_UiEditInvestasiNew } from "@/app_modules/investasi/_ui";
import getPembagianDeviden from "@/app_modules/investasi/fun/master/get_pembagian_deviden";
import getPencarianInvestor from "@/app_modules/investasi/fun/master/get_pencarian_investor";
import getPeriodeDeviden from "@/app_modules/investasi/fun/master/get_periode_deviden";
import _ from "lodash";
export default async function Page({ params }: { params: { id: string } }) {
const investasiId = params.id;
// console.log(investasiId);
// const investasiId = params.id;
const allData = await investasi_funGetOneInvestasiById({ investasiId });
const dataInvestasi = _.omit(allData, [
"BeritaInvestasi",
"DokumenInvestasi",
"MasterPembagianDeviden",
"MasterPencarianInvestor",
"MasterProgresInvestasi",
"MasterStatusInvestasi",
"ProspektusInvestasi",
"MasterPeriodeDeviden",
"author",
]);
// const allData = await investasi_funGetOneInvestasiById({ investasiId });
// const dataInvestasi = _.omit(allData, [
// "BeritaInvestasi",
// "DokumenInvestasi",
// "MasterPembagianDeviden",
// "MasterPencarianInvestor",
// "MasterProgresInvestasi",
// "MasterStatusInvestasi",
// "ProspektusInvestasi",
// "MasterPeriodeDeviden",
// "author",
// ]);
const listPencarian = await getPencarianInvestor();
const listPeriode = await getPeriodeDeviden();
const listPembagian = await getPembagianDeviden();
// const listPencarian = await getPencarianInvestor();
// const listPeriode = await getPeriodeDeviden();
// const listPembagian = await getPembagianDeviden();
return (
<>
<Investasi_UiEditInvestasi
{/* <Investasi_UiEditInvestasi
dataInvestasi={dataInvestasi}
pembagianDeviden={listPembagian}
pencarianInvestor={listPencarian}
periodeDeviden={listPeriode}
/>
/> */}
<Investasi_UiEditInvestasiNew />
</>
);
}

View File

@@ -25,6 +25,7 @@ export function Investasi_ComponentButtonUpdateDataInvestasi({
const [isLoading, setIsLoading] = useState(false);
async function onUpdate() {
setIsLoading(true);
if (totalLembar === "0")
return ComponentGlobal_NotifikasiPeringatan("Total lembar kosong");
@@ -74,6 +75,8 @@ export function Investasi_ComponentButtonUpdateDataInvestasi({
return (
<Stack>
<Button
loading={isLoading}
loaderPosition="center"
my={50}
radius={50}
bg={MainColor.yellow}

View File

@@ -1,4 +1,9 @@
export const apiGetMasterInvestasi = async (path?: string) => {
const response = await fetch(`/api/new/investasi/master${(path) ? path : ''}`)
return await response.json().catch(() => null)
}
export const apiGetOneInvestasiById = async (path: string) => {
const response = await fetch(`/api/new/investasi/${path}`)
return await response.json().catch(() => null)
}

View File

@@ -0,0 +1,15 @@
export interface IDataInvestasi {
id: string
title: string
targetDana: string
hargaLembar: string
totalLembar: string
roi: string
countDown: string
catatan: string
sisaLembar: string
imageId: string
masterPencarianInvestorId: string
masterPeriodeDevidenId: string
masterPembagianDevidenId: string
}

View File

@@ -0,0 +1,15 @@
"use client";
import { UIGlobal_LayoutHeaderTamplate, UIGlobal_LayoutTamplate, } from "@/app_modules/_global/ui";
import { Investasi_ViewEditInvestasiNew } from "../../_view/edit/vew_edit_investasi_new";
export function Investasi_UiEditInvestasiNew() {
return (
<>
<UIGlobal_LayoutTamplate
header={<UIGlobal_LayoutHeaderTamplate title="Edit Investasi" />}
>
<Investasi_ViewEditInvestasiNew />
</UIGlobal_LayoutTamplate>
</>
);
}

View File

@@ -24,6 +24,7 @@ import { Investasi_UiDaftarBerita } from "./detail/ui_daftar_berita";
import { Investasi_UiRekapBerita } from "./detail/ui_rekap_berita";
import { Investasi_UiCreateBerita } from "./create/ui_create_berita";
import { Investasi_UiDetailBerita } from "./detail/ui_berita";
import { Investasi_UiEditInvestasiNew } from "./edit/ui_edit_investasi_new";
export { Investasi_UiProsesPembelian };
export { Investasi_UiMetodePembayaran };
@@ -51,3 +52,4 @@ export { Investasi_UiDaftarBerita };
export { Investasi_UiRekapBerita };
export { Investasi_UiCreateBerita };
export { Investasi_UiDetailBerita };
export { Investasi_UiEditInvestasiNew }

View File

@@ -0,0 +1,23 @@
import { Box, Skeleton, Stack } from "@mantine/core";
export default function SkeletonEditInvestasi() {
return (
<>
<Box>
<Stack align="center" mb={40}>
<Skeleton height={40} width={"100%"} />
<Skeleton height={300} width={"100%"} my={"xs"} />
<Skeleton height={40} width={"40%"} radius={"lg"} />
</Stack>
<Stack align="center">
{[...Array(5)].map((_, index) => (
<Skeleton key={index} height={40} width={"100%"} my={"xs"} />
))}
<Skeleton height={40} width={"100%"} radius={"lg"} mt={30} />
</Stack>
</Box>
</>
);
}

View File

@@ -0,0 +1,367 @@
import { MainColor } from "@/app_modules/_global/color";
import { ComponentGlobal_BoxInformation, ComponentGlobal_BoxUploadImage, ComponentGlobal_LoadImage, } from "@/app_modules/_global/component";
import { AspectRatio, Box, Button, FileButton, Group, Image, Select, Stack, Text, TextInput, } from "@mantine/core";
import { useShallowEffect } from "@mantine/hooks";
import { IconCamera } from "@tabler/icons-react";
import _ from "lodash";
import { useState } from "react";
import { Investasi_ComponentButtonUpdateDataInvestasi } from "../../_component";
import { apiGetMasterInvestasi, apiGetOneInvestasiById } from "../../_lib/api_interface";
import { IDataInvestasi } from "../../_lib/type_investasi";
import { useParams } from "next/navigation";
import SkeletonEditInvestasi from "./skeleton_edit_investasi";
export function Investasi_ViewEditInvestasiNew() {
const param = useParams<{ id: string }>()
const [loading, setLoading] = useState(true)
const [loadingMasterInvestor, setLoadingMasterInvestor] = useState(true)
const [loadingMasterPeriodeDeviden, setLoadingMasterPeriodeDeviden] = useState(true)
const [loadingMasterPembagianDeviden, setLoadingMasterPembagianDeviden] = useState(true)
const [periodeDeviden, setPeriodeDeviden] = useState<any[]>([]);
const [pembagianDeviden, setPembagianDeviden] = useState<any[]>([]);
const [pencarianInvestor, setPencarianInvestor] = useState<any[]>([]);
const [data, setData] = useState<IDataInvestasi>();
const [file, setFile] = useState<File | null>(null);
const [img, setImg] = useState<any | null>();
const [target, setTarget] = useState("");
const [harga, setHarga] = useState("");
const [totalLembar, setTotalLembar] = useState<any>("");
async function onGetOneInvestasiById() {
try {
setLoading(true)
const response = await apiGetOneInvestasiById(param.id)
if (response.success) {
setData(response.data)
setTotalLembar(response.data.totalLembar)
}
} catch (error) {
console.error(error)
} finally {
setLoading(false)
}
}
async function onGetMasterInvestor() {
try {
setLoadingMasterInvestor(true)
const response = await apiGetMasterInvestasi("?cat=pencarian-investor")
if (response.success) {
setPencarianInvestor(response.data)
}
} catch (error) {
console.log(error)
} finally {
setLoadingMasterInvestor(false)
}
}
async function onGetMasterPeriodeDeviden() {
try {
setLoadingMasterPeriodeDeviden(true)
const response = await apiGetMasterInvestasi("?cat=periode-deviden")
if (response.success) {
setPeriodeDeviden(response.data)
}
} catch (error) {
console.log(error)
} finally {
setLoadingMasterPeriodeDeviden(false)
}
}
async function onGetMasterPembagianDeviden() {
try {
setLoadingMasterPembagianDeviden(true)
const response = await apiGetMasterInvestasi("?cat=pembagian-deviden")
if (response.success) {
setPembagianDeviden(response.data)
}
} catch (error) {
console.log(error)
} finally {
setLoadingMasterPembagianDeviden(false)
}
}
useShallowEffect(() => {
onGetOneInvestasiById()
onGetMasterInvestor()
onGetMasterPeriodeDeviden()
onGetMasterPembagianDeviden()
}, [])
async function onTotalLembar({ target, harga, }: { target?: number | any; harga?: number | any; }) {
if (target !== 0 && harga !== 0) {
const hasil: any = target / harga;
const result = _.floor(hasil === Infinity ? 0 : hasil);
setTotalLembar(result.toString());
}
}
return (
<>
<Stack px={"sm"}>
{
loading ?
<SkeletonEditInvestasi />
:
<>
<Stack spacing={0}>
<Box mb={"sm"}>
<ComponentGlobal_BoxInformation informasi="Gambar investasi bisa berupa ilustrasi, poster atau foto terkait investasi" />
</Box>
<ComponentGlobal_BoxUploadImage>
{img ? (
<AspectRatio ratio={1 / 1} mt={5} maw={300} mx={"auto"}>
<Image style={{ maxHeight: 250 }} alt="Avatar" src={img} />
</AspectRatio>
) : (
<ComponentGlobal_LoadImage maw={300} fileId={String(data?.imageId)} />
)}
</ComponentGlobal_BoxUploadImage>
{/* Upload Foto */}
<Group position="center">
<FileButton
onChange={async (files: any) => {
try {
const buffer = URL.createObjectURL(
new Blob([new Uint8Array(await files.arrayBuffer())])
);
setImg(buffer);
setFile(files);
} catch (error) {
console.log(error);
}
}}
accept="image/png,image/jpeg"
>
{(props) => (
<Button
{...props}
leftIcon={<IconCamera color="black" />}
radius={50}
bg={MainColor.yellow}
color="yellow"
c={"black"}
>
Upload Gambar
</Button>
)}
</FileButton>
</Group>
</Stack>
<TextInput
styles={{
label: {
color: "white",
},
}}
withAsterisk
label="Judul Investasi"
placeholder="Judul investasi"
maxLength={100}
value={data?.title}
onChange={(val) => {
setData({
...data as any,
title: val.target.value,
});
}}
/>
<TextInput
styles={{
label: {
color: "white",
},
}}
icon={<Text fw={"bold"}>Rp.</Text>}
min={0}
withAsterisk
label="Dana Dibutuhkan"
placeholder="0"
value={target ? target : data?.targetDana}
onChange={(val) => {
const match = val.currentTarget.value
.replace(/\./g, "")
.match(/^[0-9]+$/);
if (val.currentTarget.value === "") return setTarget(0 + "");
if (!match?.[0]) return null;
const nilai = val.currentTarget.value.replace(/\./g, "");
const targetNilai = Intl.NumberFormat("id-ID").format(+nilai);
onTotalLembar({
target: +nilai,
harga: +Number(data?.hargaLembar),
});
setTarget(targetNilai);
setData({
...data as any,
targetDana: nilai as string,
});
}}
/>
<TextInput
styles={{
label: {
color: "white",
},
}}
icon={<Text fw={"bold"}>Rp.</Text>}
min={0}
withAsterisk
label="Harga Per Lembar"
placeholder="0"
value={harga ? harga : data?.hargaLembar}
onChange={(val) => {
try {
const match = val.currentTarget.value
.replace(/\./g, "")
.match(/^[0-9]+$/);
if (val.currentTarget.value === "") return setHarga(0 + "");
if (!match?.[0]) return null;
const nilai = val.currentTarget.value.replace(/\./g, "");
const targetNilai = Intl.NumberFormat("id-ID").format(+nilai);
onTotalLembar({
harga: +nilai,
target: +Number(data?.targetDana),
});
setHarga(targetNilai);
setData({
...data as any,
hargaLembar: nilai as string,
});
} catch (error) {
console.log(error);
}
}}
/>
<TextInput
description="*Total lembar dihitung dari, Target Dana / Harga Perlembar"
label="Total Lembar"
value={harga === "0" ? "0" : target === "0" ? "0" : totalLembar}
readOnly
styles={{
label: {
color: "white",
},
input: {
backgroundColor: "whitesmoke",
},
}}
/>
<TextInput
styles={{
label: {
color: "white",
},
}}
rightSection={
<Text fw={"bold"} c={"gray"}>
%
</Text>
}
withAsterisk
type="number"
label={"Rasio Keuntungan / ROI %"}
placeholder="Masukan rasio keuntungan"
value={data?.roi}
onChange={(val) => {
setData({
...data as any,
roi: val.target.value,
});
}}
/>
<Select
styles={{
label: {
color: "white",
},
}}
withAsterisk
label="Pencarian Investor"
placeholder={loadingMasterInvestor ? "Loading..." : "Pilih batas waktu"}
data={pencarianInvestor.map((e) => ({
value: e.id,
label: e.name + " " + "hari",
}))}
value={data?.masterPencarianInvestorId}
onChange={(val) => {
setData({
...(data as any),
masterPencarianInvestorId: val,
});
}}
/>
<Select
styles={{
label: {
color: "white",
},
}}
withAsterisk
label="Periode Deviden"
placeholder={loadingMasterPeriodeDeviden ? "Loading..." : "Pilih batas waktu"}
data={periodeDeviden.map((e) => ({ value: e.id, label: e.name }))}
value={data?.masterPeriodeDevidenId}
onChange={(val) => {
setData({
...(data as any),
masterPeriodeDevidenId: val,
});
}}
/>
<Select
styles={{
label: {
color: "white",
},
}}
withAsterisk
label="Pembagian Deviden"
placeholder={loadingMasterPembagianDeviden ? "Loading..." : "Pilih batas waktu"}
data={pembagianDeviden.map((e) => ({
value: e.id,
label: e.name + " " + "bulan",
}))}
value={data?.masterPembagianDevidenId}
onChange={(val) => {
setData({
...(data as any),
masterPembagianDevidenId: val,
});
}}
/>
<Investasi_ComponentButtonUpdateDataInvestasi
data={data as any}
file={file as any}
totalLembar={totalLembar}
/>
</>
}
</Stack>
</>
);
}