"use client"; import { ApiHipmi } from "@/app/lib/api"; import { Warna } from "@/app/lib/warna"; import { MODEL_DEFAULT_MASTER } from "@/app_modules/models/model_default_master"; import { AspectRatio, Box, Button, Center, Divider, FileButton, Group, Image, NumberInput, Paper, Select, Stack, Text, TextInput, } from "@mantine/core"; import { IconCamera, IconPdf, IconUpload } from "@tabler/icons-react"; import _ from "lodash"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { funCreateInvestasi } from "../fun/fun_create_investasi"; import toast from "react-simple-toasts"; import { RouterInvestasi } from "@/app/lib/router_hipmi/router_investasi"; import { useAtom } from "jotai"; import { gs_StatusPortoInvestasi, gs_investasiFooter } from "../g_state"; import { useShallowEffect } from "@mantine/hooks"; export default function InvestasiCreate({ id, pencarianInvestor, periodeDeviden, pembagianDeviden, }: { id: string; pencarianInvestor: MODEL_DEFAULT_MASTER[]; periodeDeviden: MODEL_DEFAULT_MASTER[]; pembagianDeviden: MODEL_DEFAULT_MASTER[]; }) { const router = useRouter(); const [fl, setFl] = useState(null); const [img, setImg] = useState(); const [pdf, setPdf] = useState(null); const [filePdf, setFilePdf] = useState(null); const [changeColor, setChangeColor] = useAtom(gs_investasiFooter); const [activeTab, setActiveTab] = useAtom(gs_StatusPortoInvestasi); const [totalLembar, setTotalLembar] = useState(0); const [value, setValue] = useState({ title: "", targetDana: 0, hargaLembar: 0, roi: 0, pencarianInvestorId: "", periodeDevidenId: "", pembagianDevidenId: "", }); async function onSubmit() { const body = { authorId: id, title: value.title, targetDana: value.targetDana, hargaLembar: value.hargaLembar, totalLembar: totalLembar, roi: value.roi, masterPeriodeDevidenId: value.periodeDevidenId, masterPembagianDevidenId: value.pembagianDevidenId, masterPencarianInvestorId: value.pencarianInvestorId, }; // toast("Berhasil disimpan") // if (_.values(body).includes("")) return toast("Lengkapi data"); if (!fl) return toast("Gambar Kosong"); if (!pdf) return toast("File Kosong"); const gmbr = new FormData(); gmbr.append("file", fl); const flPdf = new FormData(); flPdf.append("file", pdf); await funCreateInvestasi(gmbr, flPdf, body as any).then((res) => { if (res.status === 201) { // toast(res.message); setChangeColor(1); setActiveTab("Review"); router.push(RouterInvestasi.dialog_create); } else { toast(res.message); } }); } async function onTotalLembar(target: any, harga: any) { const hasil: any = target / harga; setTotalLembar(_.floor(hasil === Infinity ? 0 : hasil)); } return ( <> {/* Inputan Create */} {img ? ( ) : ( )} {/* Upload Foto */} { const buffer = URL.createObjectURL( new Blob([new Uint8Array(await files.arrayBuffer())]) ); // console.log(files); setImg(buffer); setFl(files); }} accept="image/png,image/jpeg" > {(props) => ( )} {/* Upload File */} {!pdf ? ( Upload File Prospektus ) : ( {pdf.name} )} {/* {JSON.stringify(filePdf)} */} { const buffer = URL.createObjectURL( new Blob([new Uint8Array(await files.arrayBuffer())]) ); // console.log(files.name) setFilePdf(buffer); setPdf(files); }} > {(props) => ( )} { setValue({ ...value, title: val.target.value, }); }} /> { setValue({ ...value, targetDana: val, }); }} /> { //console.log(val) setValue({ ...value, hargaLembar: +val, }); onTotalLembar(value.targetDana, val); }} /> Total Lembar {totalLembar} *Total lembar dihitung dari, Target Dana : Harga Perlembar { setValue({ ...value, roi: val, }); }} /> ({ value: e.id, label: e.name }))} onChange={(val) => { setValue({ ...(value as any), periodeDevidenId: val, }); }} />