From 18f9cce963a3bb5c34821308a0d08ae525545548 Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Thu, 27 Feb 2025 10:27:30 +0800 Subject: [PATCH] fix invetasi create --- .../comp_button_create_new_investasi.tsx | 19 +- src/app_modules/investasi/create/view.tsx | 396 ------------------ src/app_modules/investasi/create/view_new.tsx | 183 +++----- src/app_modules/investasi/index.ts | 2 - 4 files changed, 64 insertions(+), 536 deletions(-) delete mode 100644 src/app_modules/investasi/create/view.tsx diff --git a/src/app_modules/investasi/_component/button/comp_button_create_new_investasi.tsx b/src/app_modules/investasi/_component/button/comp_button_create_new_investasi.tsx index ab202b13..319bd5f2 100644 --- a/src/app_modules/investasi/_component/button/comp_button_create_new_investasi.tsx +++ b/src/app_modules/investasi/_component/button/comp_button_create_new_investasi.tsx @@ -1,7 +1,5 @@ "use client"; -import { DIRECTORY_ID } from "@/lib"; -import { NEW_RouterInvestasi } from "@/lib/router_hipmi/router_investasi"; import { MainColor } from "@/app_modules/_global/color"; import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun"; import { @@ -10,26 +8,30 @@ import { ComponentGlobal_NotifikasiPeringatan, } from "@/app_modules/_global/notif_global"; import { notifikasiToAdmin_funCreate } from "@/app_modules/notifikasi/fun"; +import { DIRECTORY_ID } from "@/lib"; +import { IRealtimeData } from "@/lib/global_state"; +import { NEW_RouterInvestasi } from "@/lib/router_hipmi/router_investasi"; +import { clientLogger } from "@/util/clientLogger"; import { Button } from "@mantine/core"; import { useAtom } from "jotai"; import { useRouter } from "next/navigation"; import { useState } from "react"; +import { WibuRealtime } from "wibu-pkg"; import { investasi_funCreateNewInvestasi } from "../../_fun"; import { gs_investas_menu, gs_investasi_status } from "../../g_state"; -import { clientLogger } from "@/util/clientLogger"; -import { IRealtimeData } from "@/lib/global_state"; -import { WibuRealtime } from "wibu-pkg"; export function Investasi_ComponentButtonCreateNewInvestasi({ data, totalLembar, fileImage, filePdf, + isMinimalTarget, }: { data: any; totalLembar: number; fileImage: File; filePdf: File; + isMinimalTarget: boolean; }) { const router = useRouter(); const [isLoading, setIsLoading] = useState(false); @@ -114,7 +116,7 @@ export function Investasi_ComponentButtonCreateNewInvestasi({ } catch (error) { setIsLoading(false); clientLogger.error("Error create new investasi", error); - } + } } return ( @@ -135,9 +137,8 @@ export function Investasi_ComponentButtonCreateNewInvestasi({ data.periodeDevidenId === "" || data.pembagianDevidenId === "" || fileImage === null || - filePdf === null - ? true - : false + filePdf === null || + isMinimalTarget } radius={50} bg={MainColor.yellow} diff --git a/src/app_modules/investasi/create/view.tsx b/src/app_modules/investasi/create/view.tsx deleted file mode 100644 index 057162b4..00000000 --- a/src/app_modules/investasi/create/view.tsx +++ /dev/null @@ -1,396 +0,0 @@ -"use client"; - -import { MainColor } from "@/app_modules/_global/color/color_pallet"; -import { - ComponentGlobal_BoxInformation, - ComponentGlobal_BoxUploadImage, - ComponentGlobal_CardStyles, -} from "@/app_modules/_global/component"; -import { MODEL_DEFAULT_MASTER_OLD } from "@/app_modules/model_global/model_default_master"; -import { - AspectRatio, - Box, - Button, - Center, - FileButton, - Grid, - Group, - Image, - Select, - Stack, - Text, - TextInput, -} from "@mantine/core"; -import { - IconCamera, - IconCircleCheck, - IconFileTypePdf, - IconPdf, - IconUpload, -} from "@tabler/icons-react"; -import _ from "lodash"; -import { useState } from "react"; -import { Investasi_ComponentButtonCreateNewInvestasi } from "../_component"; - -export default function InvestasiCreate({ - pencarianInvestor, - periodeDeviden, - pembagianDeviden, -}: { - pencarianInvestor: MODEL_DEFAULT_MASTER_OLD[]; - periodeDeviden: MODEL_DEFAULT_MASTER_OLD[]; - pembagianDeviden: MODEL_DEFAULT_MASTER_OLD[]; -}) { - const [fileImage, setFileImage] = useState(null); - const [img, setImg] = useState(); - const [filePdf, setFilePdf] = useState(null); - const [fPdf, setFPdf] = useState(null); - const [totalLembar, setTotalLembar] = useState(0); - - const [value, setValue] = useState({ - title: "", - targetDana: 0, - hargaLembar: 0, - roi: 0, - pencarianInvestorId: "", - periodeDevidenId: "", - pembagianDevidenId: "", - }); - const [target, setTarget] = useState(""); - const [harga, setHarga] = useState(""); - - async function onTotalLembar({ - target, - harga, - }: { - target?: number | any; - harga?: number | any; - }) { - if (target !== 0 && harga !== 0) { - const hasil: any = target / harga; - setTotalLembar(_.floor(hasil === Infinity ? 0 : hasil)); - } - } - - return ( - <> - - {/* Upload Image */} - - - - - - {img ? ( - - Foto - - ) : ( - - - - Upload Gambar - - - )} - - - {/* Upload Foto */} - - { - try { - const buffer = URL.createObjectURL( - new Blob([new Uint8Array(await files.arrayBuffer())]) - ); - - setImg(buffer); - setFileImage(files); - } catch (error) { - console.log(error); - } - }} - accept="image/png,image/jpeg" - > - {(props) => ( - - )} - - - - - {/* Upload File */} - - - - {!filePdf ? ( - - Upload File Prospektus - - ) : ( - - - - - {filePdf.name} - - - -
- -
-
-
- )} -
- - - { - try { - const buffer = URL.createObjectURL( - new Blob([new Uint8Array(await files.arrayBuffer())]) - ); - setFPdf(buffer); - setFilePdf(files); - } catch (error) { - console.log(error); - } - }} - > - {(props) => ( - - )} - - -
- - - { - setValue({ - ...value, - title: val.target.value, - }); - }} - /> - - Rp.} - min={0} - withAsterisk - label="Dana Dibutuhkan" - placeholder="0" - value={target} - onChange={(val) => { - // console.log(typeof 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: +value.hargaLembar, - }); - - setTarget(targetNilai); - setValue({ - ...value, - targetDana: +nilai, - }); - }} - /> - - Rp.} - min={0} - withAsterisk - label="Harga Per Lembar" - placeholder="0" - value={harga} - onChange={(val) => { - try { - // console.log(typeof +val.currentTarget.value); - - 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: +value.targetDana, - }); - - setHarga(targetNilai); - setValue({ - ...value, - hargaLembar: +nilai, - }); - } catch (error) { - console.log(error); - } - }} - /> - - - - - % - - } - withAsterisk - type="number" - label={"Rasio Keuntungan / ROI %"} - placeholder="Masukan rasio keuntungan" - onChange={(val) => { - setValue({ - ...value, - roi: _.toNumber(val.target.value), - }); - }} - /> - - ({ value: e.id, label: e.name }))} - onChange={(val) => { - setValue({ - ...(value as any), - periodeDevidenId: val, - }); - }} - /> - -