From 1855b6df32071497668820d298521fb8a71657b3 Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Wed, 15 Jan 2025 10:25:41 +0800 Subject: [PATCH 1/4] fix ( upload image ) deksripsi: - fix upload image investasi dan file prospektus --- src/app/api/new/investasi/[id]/route.ts | 1 + src/app/dev/investasi/edit/[id]/page.tsx | 34 +- .../investasi/edit/prospektus/[id]/page.tsx | 5 +- .../investasi/edit_prospektus/[id]/layout.tsx | 21 - .../investasi/edit_prospektus/[id]/page.tsx | 12 - .../button/comp_button_upload_photo.tsx | 15 +- .../_global/component/box_information.tsx | 8 +- .../comp_button_create_new_investasi.tsx | 8 +- .../button/comp_button_update_investasi.tsx | 16 +- .../investasi/_component/skeleton_view.tsx | 35 ++ .../_ui/edit/ui_edit_investasi_new.tsx | 2 +- .../investasi/_ui/edit/ui_edit_prospektus.tsx | 8 +- .../_view/edit/vew_edit_investasi_new.tsx | 420 ---------------- .../_view/edit/view_edit_investasi_new.tsx | 462 ++++++++++++++++++ .../_view/edit/view_edit_prospektus.tsx | 173 ++++--- .../_view/transaksi/view_invoice.tsx | 34 +- src/app_modules/investasi/create/view_new.tsx | 38 +- .../investasi/edit_propektus/layout.tsx | 30 -- .../investasi/edit_propektus/view.tsx | 75 --- src/app_modules/investasi/index.ts | 4 - src/app_modules/job/edit/view.tsx | 7 - .../profile/create/view_upload_foto.tsx | 127 +---- src/middleware.ts | 5 +- xhtml/index.html | 44 ++ 24 files changed, 725 insertions(+), 859 deletions(-) delete mode 100644 src/app/dev/investasi/edit_prospektus/[id]/layout.tsx delete mode 100644 src/app/dev/investasi/edit_prospektus/[id]/page.tsx create mode 100644 src/app_modules/investasi/_component/skeleton_view.tsx delete mode 100644 src/app_modules/investasi/_view/edit/vew_edit_investasi_new.tsx create mode 100644 src/app_modules/investasi/_view/edit/view_edit_investasi_new.tsx delete mode 100644 src/app_modules/investasi/edit_propektus/layout.tsx delete mode 100644 src/app_modules/investasi/edit_propektus/view.tsx create mode 100644 xhtml/index.html diff --git a/src/app/api/new/investasi/[id]/route.ts b/src/app/api/new/investasi/[id]/route.ts index ef327393..2b7342d1 100644 --- a/src/app/api/new/investasi/[id]/route.ts +++ b/src/app/api/new/investasi/[id]/route.ts @@ -23,6 +23,7 @@ export async function GET(request: Request, context: { params: { id: string } }) catatan: true, sisaLembar: true, imageId: true, + prospektusFileId: true, masterPencarianInvestorId: true, masterPeriodeDevidenId: true, masterPembagianDevidenId: true, diff --git a/src/app/dev/investasi/edit/[id]/page.tsx b/src/app/dev/investasi/edit/[id]/page.tsx index a81633bb..76a5e468 100644 --- a/src/app/dev/investasi/edit/[id]/page.tsx +++ b/src/app/dev/investasi/edit/[id]/page.tsx @@ -1,38 +1,8 @@ -import { investasi_funGetOneInvestasiById } from "@/app_modules/investasi/_fun"; -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; - - // 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(); +import { Investasi_UiEditInvestasiNew } from "@/app_modules/investasi/_ui"; +export default async function Page() { return ( <> - {/* */} ); diff --git a/src/app/dev/investasi/edit/prospektus/[id]/page.tsx b/src/app/dev/investasi/edit/prospektus/[id]/page.tsx index 519debdf..4c09a503 100644 --- a/src/app/dev/investasi/edit/prospektus/[id]/page.tsx +++ b/src/app/dev/investasi/edit/prospektus/[id]/page.tsx @@ -1,11 +1,10 @@ import { Investasi_UiEditProspektus } from "@/app_modules/investasi/_ui"; -export default async function Page({ params }: { params: { id: string } }) { - const investasiId = params.id; +export default async function Page() { return ( <> - + ); } diff --git a/src/app/dev/investasi/edit_prospektus/[id]/layout.tsx b/src/app/dev/investasi/edit_prospektus/[id]/layout.tsx deleted file mode 100644 index 0c6a45a1..00000000 --- a/src/app/dev/investasi/edit_prospektus/[id]/layout.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import { LayoutEditProspektusInvestasi } from "@/app_modules/investasi"; -import getOneInvestasiById from "@/app_modules/investasi/fun/get_one_investasi_by_id"; -import React from "react"; - -export default async function Layout({ - children, - params, -}: { - children: React.ReactNode; - params: { id: string }; -}) { - const dataInvestasi = await getOneInvestasiById(params.id); - - return ( - <> - - {children} - - - ); -} diff --git a/src/app/dev/investasi/edit_prospektus/[id]/page.tsx b/src/app/dev/investasi/edit_prospektus/[id]/page.tsx deleted file mode 100644 index 521d1475..00000000 --- a/src/app/dev/investasi/edit_prospektus/[id]/page.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import { EditProspektusInvestasi } from "@/app_modules/investasi"; -import getOneInvestasiById from "@/app_modules/investasi/fun/get_one_investasi_by_id"; - -export default async function Page({ params }: { params: { id: string } }) { - const dataInvestasi = await getOneInvestasiById(params.id); -// console.log(dataInvestasi); - return ( - <> - - - ); -} diff --git a/src/app_modules/_global/button/comp_button_upload_photo.tsx b/src/app_modules/_global/button/comp_button_upload_photo.tsx index 2d6f1a6f..59103c6c 100644 --- a/src/app_modules/_global/button/comp_button_upload_photo.tsx +++ b/src/app_modules/_global/button/comp_button_upload_photo.tsx @@ -10,9 +10,15 @@ import { ComponentGlobal_NotifikasiPeringatan } from "../notif_global"; export function ComponentGlobal_ButtonUploadFileImage({ onSetFile, onSetImage, + text, + icon, + accept, }: { onSetFile: File | null | any; - onSetImage: any | null; + onSetImage?: any | null; + text?: string; + icon?: string | any + accept?: string; }) { const [isLoading, setIsLoading] = useState(false); @@ -28,6 +34,7 @@ export function ComponentGlobal_ButtonUploadFileImage({ if (files.size > 100 * 1024 * 1024) { setIsLoading(false); ComponentGlobal_NotifikasiPeringatan("File terlalu besar"); + return } onSetFile(files); @@ -38,7 +45,7 @@ export function ComponentGlobal_ButtonUploadFileImage({ setIsLoading(false); } }} - accept="image/png,image/png,image/jpeg,image/gif" + accept={accept ? accept : "image/png,image/png,image/jpeg,image/gif"} > {(props) => ( )} diff --git a/src/app_modules/_global/component/box_information.tsx b/src/app_modules/_global/component/box_information.tsx index 8dbe0a0b..94afb1f2 100644 --- a/src/app_modules/_global/component/box_information.tsx +++ b/src/app_modules/_global/component/box_information.tsx @@ -42,7 +42,13 @@ export default function ComponentGlobal_BoxInformation({ - + {informasi} 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 8dbb877b..2e37d8e4 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 @@ -65,6 +65,7 @@ export function Investasi_ComponentButtonCreateNewInvestasi({ dirId: DIRECTORY_ID.investasi_prospektus, }); if (!uploadFilePdf.success) { + setIsLoading(false); ComponentGlobal_NotifikasiPeringatan("Gagal upload file pdf"); return; } @@ -104,17 +105,16 @@ export function Investasi_ComponentButtonCreateNewInvestasi({ router.push(NEW_RouterInvestasi.portofolio({ id: "2" })); setActiveTab("Review"); setHotMenu(1); - setIsLoading(true); ComponentGlobal_NotifikasiBerhasil(res.message); } } else { + setIsLoading(false); ComponentGlobal_NotifikasiGagal(res.message); } } catch (error) { - clientLogger.error("Error create new investasi", error); - } finally { setIsLoading(false); - } + clientLogger.error("Error create new investasi", error); + } } return ( diff --git a/src/app_modules/investasi/_component/button/comp_button_update_investasi.tsx b/src/app_modules/investasi/_component/button/comp_button_update_investasi.tsx index c2cc815e..8487ced8 100644 --- a/src/app_modules/investasi/_component/button/comp_button_update_investasi.tsx +++ b/src/app_modules/investasi/_component/button/comp_button_update_investasi.tsx @@ -6,11 +6,15 @@ import { ComponentGlobal_NotifikasiPeringatan, } from "@/app_modules/_global/notif_global"; import { DIRECTORY_ID } from "@/app/lib"; -import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun"; +import { + funGlobal_DeleteFileById, + funGlobal_UploadToStorage, +} from "@/app_modules/_global/fun"; import _ from "lodash"; import { investasi_funUpdateInvestasi } from "../../_fun"; import { useRouter } from "next/navigation"; import { useState } from "react"; +import { clientLogger } from "@/util/clientLogger"; export function Investasi_ComponentButtonUpdateDataInvestasi({ data, @@ -37,11 +41,21 @@ export function Investasi_ComponentButtonUpdateDataInvestasi({ file: file as any, dirId: DIRECTORY_ID.investasi_image, }); + if (!uploadImage.success) { setIsLoading(false); return ComponentGlobal_NotifikasiPeringatan("Gagal upload file gambar"); } + const deleteFile = await funGlobal_DeleteFileById({ + fileId: data.imageId, + }); + + if (!deleteFile.success) { + setIsLoading(false); + clientLogger.error("Error delete file:", deleteFile.message); + } + const updtWithImage = await investasi_funUpdateInvestasi({ data: data, imageId: uploadImage.data.id, diff --git a/src/app_modules/investasi/_component/skeleton_view.tsx b/src/app_modules/investasi/_component/skeleton_view.tsx new file mode 100644 index 00000000..8f03289b --- /dev/null +++ b/src/app_modules/investasi/_component/skeleton_view.tsx @@ -0,0 +1,35 @@ +import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; +import { Box, Center, Stack } from "@mantine/core"; + +export { Investasi_SkeletonEditProspektus }; + +function Investasi_SkeletonEditProspektus() { + return ( + <> + + + +
+ +
+ + + + + +
+ + ); +} diff --git a/src/app_modules/investasi/_ui/edit/ui_edit_investasi_new.tsx b/src/app_modules/investasi/_ui/edit/ui_edit_investasi_new.tsx index bbd22683..e0edfa1e 100644 --- a/src/app_modules/investasi/_ui/edit/ui_edit_investasi_new.tsx +++ b/src/app_modules/investasi/_ui/edit/ui_edit_investasi_new.tsx @@ -1,6 +1,6 @@ "use client"; import { UIGlobal_LayoutHeaderTamplate, UIGlobal_LayoutTamplate, } from "@/app_modules/_global/ui"; -import { Investasi_ViewEditInvestasiNew } from "../../_view/edit/vew_edit_investasi_new"; +import { Investasi_ViewEditInvestasiNew } from "../../_view/edit/view_edit_investasi_new"; export function Investasi_UiEditInvestasiNew() { return ( diff --git a/src/app_modules/investasi/_ui/edit/ui_edit_prospektus.tsx b/src/app_modules/investasi/_ui/edit/ui_edit_prospektus.tsx index d4aea25c..92f02d46 100644 --- a/src/app_modules/investasi/_ui/edit/ui_edit_prospektus.tsx +++ b/src/app_modules/investasi/_ui/edit/ui_edit_prospektus.tsx @@ -6,17 +6,13 @@ import { } from "@/app_modules/_global/ui"; import { Investasi_ViewEditProspektus } from "../../_view"; -export function Investasi_UiEditProspektus({ - investasiId, -}: { - investasiId: string; -}) { +export function Investasi_UiEditProspektus() { return ( <> } > - + ); diff --git a/src/app_modules/investasi/_view/edit/vew_edit_investasi_new.tsx b/src/app_modules/investasi/_view/edit/vew_edit_investasi_new.tsx deleted file mode 100644 index 54f11867..00000000 --- a/src/app_modules/investasi/_view/edit/vew_edit_investasi_new.tsx +++ /dev/null @@ -1,420 +0,0 @@ -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([]); - const [pembagianDeviden, setPembagianDeviden] = useState([]); - const [pencarianInvestor, setPencarianInvestor] = useState([]); - const [data, setData] = useState(); - const [file, setFile] = useState(null); - const [img, setImg] = useState(); - const [target, setTarget] = useState(""); - const [harga, setHarga] = useState(""); - const [totalLembar, setTotalLembar] = useState(""); - - - 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 ( - <> - - { - loading ? - - : - <> - - - - - - {img ? ( - - Avatar - - ) : ( - - )} - - {/* Upload Foto */} - - { - 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) => ( - - )} - - - - - - { - setData({ - ...data as any, - title: val.target.value, - }); - }} - /> - - Rp.} - 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, - }); - }} - /> - - Rp.} - 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); - } - }} - /> - - - - - % - - } - withAsterisk - type="number" - label={"Rasio Keuntungan / ROI %"} - placeholder="Masukan rasio keuntungan" - value={data?.roi} - onChange={(val) => { - setData({ - ...data as any, - roi: val.target.value, - }); - }} - /> - - ({ value: e.id, label: e.name }))} - value={data?.masterPeriodeDevidenId} - onChange={(val) => { - setData({ - ...(data as any), - masterPeriodeDevidenId: val, - }); - }} - /> - - ({ + value: e.id, + label: e.name + " " + "hari", + }))} + value={data?.masterPencarianInvestorId} + onChange={(val) => { + setData({ + ...(data as any), + masterPencarianInvestorId: val, + }); + }} + /> + + ({ + value: e.id, + label: e.name + " " + "bulan", + }))} + value={data?.masterPembagianDevidenId} + onChange={(val) => { + setData({ + ...(data as any), + masterPembagianDevidenId: val, + }); + }} + /> + + + + )} + + + ); +} diff --git a/src/app_modules/investasi/_view/edit/view_edit_prospektus.tsx b/src/app_modules/investasi/_view/edit/view_edit_prospektus.tsx index 6b7ea3b0..caf1c5f1 100644 --- a/src/app_modules/investasi/_view/edit/view_edit_prospektus.tsx +++ b/src/app_modules/investasi/_view/edit/view_edit_prospektus.tsx @@ -1,82 +1,118 @@ import { MainColor } from "@/app_modules/_global/color"; import { ComponentGlobal_BoxInformation, + ComponentGlobal_ButtonUploadFileImage, ComponentGlobal_CardStyles, } from "@/app_modules/_global/component"; import { + Box, Button, Center, - FileButton, Grid, - Group, Stack, Text } from "@mantine/core"; import { - IconCamera, - IconCircleCheck + IconCircleCheck, + IconFileTypePdf } from "@tabler/icons-react"; import { DIRECTORY_ID } from "@/app/lib"; -import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun"; +import { + funGlobal_DeleteFileById, + funGlobal_UploadToStorage, +} from "@/app_modules/_global/fun"; import { ComponentGlobal_NotifikasiBerhasil, ComponentGlobal_NotifikasiPeringatan, } from "@/app_modules/_global/notif_global"; -import { useRouter } from "next/navigation"; +import { clientLogger } from "@/util/clientLogger"; +import { useShallowEffect } from "@mantine/hooks"; +import { useParams, useRouter } from "next/navigation"; import { useState } from "react"; +import { Investasi_SkeletonEditProspektus } from "../../_component/skeleton_view"; import { investasi_funUpdateProspektus } from "../../_fun"; +import { apiGetOneInvestasiById } from "../../_lib/api_interface"; -export function Investasi_ViewEditProspektus({ - investasiId, -}: { - investasiId: string; -}) { +export function Investasi_ViewEditProspektus() { + const params = useParams<{ id: string }>(); + const investasiId = params.id; const router = useRouter(); const [filePdf, setFilePdf] = useState(null); const [isLoading, setIsLoading] = useState(false); + const [fileRemoveId, setFileRemoveId] = useState(null); + + useShallowEffect(() => { + onLoadData(); + }, []); + + async function onLoadData() { + try { + const respone = await apiGetOneInvestasiById(investasiId); + if (respone.success) { + setFileRemoveId(respone.data.prospektusFileId); + } + } catch (error) { + clientLogger.error("Error get data investasi:", error); + } + } async function onUpload() { - setIsLoading(true); - const uploadFilePdf = await funGlobal_UploadToStorage({ - file: filePdf as any, - dirId: DIRECTORY_ID.investasi_prospektus, - }); - - if (!uploadFilePdf.success) { - setIsLoading(false); - return ComponentGlobal_NotifikasiPeringatan("Gagal upload file pdf"); - } - try { + setIsLoading(true); + const uploadFilePdf = await funGlobal_UploadToStorage({ + file: filePdf as any, + dirId: DIRECTORY_ID.investasi_prospektus, + }); + + if (!uploadFilePdf.success) { + setIsLoading(false); + ComponentGlobal_NotifikasiPeringatan("Gagal upload file pdf"); + return; + } + + const deleteFile = await funGlobal_DeleteFileById({ + fileId: fileRemoveId as string, + dirId: DIRECTORY_ID.investasi_prospektus, + }); + + if (!deleteFile.success) { + setIsLoading(false); + clientLogger.error("Error delete file:", deleteFile.message); + } + const updte = await investasi_funUpdateProspektus({ fileId: uploadFilePdf.data.id, investasiId: investasiId, }); if (updte.status !== 200) { - return ComponentGlobal_NotifikasiPeringatan("Gagal update prospektus"); + setIsLoading(false); + ComponentGlobal_NotifikasiPeringatan("Gagal update prospektus"); + return; } + ComponentGlobal_NotifikasiBerhasil(updte.message); router.back(); - - return ComponentGlobal_NotifikasiBerhasil(updte.message); } catch (error) { - console.log(error); - } finally { setIsLoading(false); + clientLogger.error("Error update prospektus:", error); } } + if (fileRemoveId == null) { + return ; + } + return ( <> - + {!filePdf ? ( - - Upload File Prospektus - + + + ) : ( @@ -94,54 +130,43 @@ export function Investasi_ViewEditProspektus({ )} - - + { - try { - const buffer = URL.createObjectURL( - new Blob([new Uint8Array(await files.arrayBuffer())]) - ); + text="Upload File" + /> + - setFilePdf(files); - } catch (error) { - console.log(error); - } - }} - > - {(props) => ( - - )} - - - - + + ); diff --git a/src/app_modules/investasi/_view/transaksi/view_invoice.tsx b/src/app_modules/investasi/_view/transaksi/view_invoice.tsx index 22b21722..17b5f793 100644 --- a/src/app_modules/investasi/_view/transaksi/view_invoice.tsx +++ b/src/app_modules/investasi/_view/transaksi/view_invoice.tsx @@ -32,6 +32,7 @@ import { IRealtimeData } from "@/app/lib/global_state"; import { notifikasiToAdmin_funCreate } from "@/app_modules/notifikasi/fun"; import { WibuRealtime } from "wibu-pkg"; import { clientLogger } from "@/util/clientLogger"; +import { ComponentGlobal_ButtonUploadFileImage } from "@/app_modules/_global/component"; export function Investasi_ViewInvoice({ dataInvoice, @@ -42,6 +43,7 @@ export function Investasi_ViewInvoice({ const [isLoading, setLoading] = useState(false); const [data, setData] = useState(dataInvoice); const [file, setFile] = useState(null); + const [img, setImg] = useState(null); async function onUpload() { try { @@ -52,6 +54,7 @@ export function Investasi_ViewInvoice({ }); if (!uploadFileToStorage.success) { + setLoading(false); ComponentGlobal_NotifikasiPeringatan("Gagal upload bukti transfer"); return; } @@ -62,6 +65,7 @@ export function Investasi_ViewInvoice({ }); if (res.status != 200) { + setLoading(false); ComponentGlobal_NotifikasiGagal(res.message); return; } @@ -93,9 +97,8 @@ export function Investasi_ViewInvoice({ }); } } catch (error) { - clientLogger.error(" Error upload invoice", error); - } finally { setLoading(false); + clientLogger.error(" Error upload invoice", error); } } @@ -245,29 +248,10 @@ export function Investasi_ViewInvoice({ >
- { - try { - setFile(files); - } catch (error) { - console.log(error); - } - }} - accept="image/png,image/jpeg" - > - {(props) => ( - - )} - +
{file ? (
diff --git a/src/app_modules/investasi/create/view_new.tsx b/src/app_modules/investasi/create/view_new.tsx index 0459787c..b0f1c46e 100644 --- a/src/app_modules/investasi/create/view_new.tsx +++ b/src/app_modules/investasi/create/view_new.tsx @@ -3,6 +3,7 @@ import { MainColor } from "@/app_modules/_global/color/color_pallet"; import { ComponentGlobal_BoxInformation, ComponentGlobal_BoxUploadImage, + ComponentGlobal_ButtonUploadFileImage, ComponentGlobal_CardStyles, } from "@/app_modules/_global/component"; import { MAX_SIZE } from "@/app_modules/_global/lib"; @@ -131,7 +132,7 @@ export default function InvestasiCreateNew() { {/* Upload Image */} - + {isLoadingImg ? ( @@ -155,7 +156,13 @@ export default function InvestasiCreateNew() { {/* Upload Foto */} - +
+ +
+ {/* { try { @@ -196,12 +203,12 @@ export default function InvestasiCreateNew() { )} - +
*/}
{/* Upload File */} - + {isLoadingPdf ? ( @@ -228,7 +235,16 @@ export default function InvestasiCreateNew() { )} - +
+ } + /> +
+ {/* { @@ -269,7 +285,7 @@ export default function InvestasiCreateNew() { )} - +
*/}
@@ -283,7 +299,7 @@ export default function InvestasiCreateNew() { }, input: { backgroundColor: MainColor.white, - } + }, }} withAsterisk label="Judul Investasi" @@ -307,7 +323,7 @@ export default function InvestasiCreateNew() { }, input: { backgroundColor: MainColor.white, - } + }, }} icon={Rp.} min={0} @@ -350,7 +366,7 @@ export default function InvestasiCreateNew() { }, input: { backgroundColor: MainColor.white, - } + }, }} icon={Rp.} min={0} @@ -403,7 +419,7 @@ export default function InvestasiCreateNew() { }, input: { backgroundColor: MainColor.white, - } + }, }} /> @@ -417,7 +433,7 @@ export default function InvestasiCreateNew() { }, input: { backgroundColor: MainColor.white, - } + }, }} rightSection={ diff --git a/src/app_modules/investasi/edit_propektus/layout.tsx b/src/app_modules/investasi/edit_propektus/layout.tsx deleted file mode 100644 index eb70c31c..00000000 --- a/src/app_modules/investasi/edit_propektus/layout.tsx +++ /dev/null @@ -1,30 +0,0 @@ -"use client"; - -import UIGlobal_LayoutHeaderTamplate from "@/app_modules/_global/ui/ui_header_tamplate"; -import UIGlobal_LayoutTamplate from "@/app_modules/_global/ui/ui_layout_tamplate"; -import React from "react"; -import { MODEL_INVESTASI } from "../_lib/interface"; - -export default function LayoutEditProspektusInvestasi({ - children, - dataInvestasi, -}: { - children: React.ReactNode; - dataInvestasi: MODEL_INVESTASI; -}) { - return ( - <> - } - // route2={RouterInvestasi.upload_prospektus + `${dataInvestasi.id}`} - /> - } - > - {children} - - - ); -} diff --git a/src/app_modules/investasi/edit_propektus/view.tsx b/src/app_modules/investasi/edit_propektus/view.tsx deleted file mode 100644 index 276c1f05..00000000 --- a/src/app_modules/investasi/edit_propektus/view.tsx +++ /dev/null @@ -1,75 +0,0 @@ -"use client"; - -import { - Paper, - Grid, - Center, - Title, - Divider, - Button, - Text, - Group, - FileButton, - FileInput, - Image, - AspectRatio, - Flex, - Stack, - Box, -} from "@mantine/core"; -import { IconChevronRight, IconFileTypePdf } from "@tabler/icons-react"; -import Link from "next/link"; -import { useState } from "react"; -import { MODEL_INVESTASI } from "../_lib/interface"; -import { RouterInvestasi_OLD } from "@/app/lib/router_hipmi/router_investasi"; - -export default function EditProspektusInvestasi({ - dataInvestasi, -}: { - dataInvestasi: MODEL_INVESTASI; -}) { - const [prospek, setProspek] = useState(dataInvestasi); - - return ( - <> - {/*
{JSON.stringify(prospek, null, 2)}
*/} - - - {prospek.ProspektusInvestasi != null ? ( - - - ""} - > - - - {/* */} - Prospektus_{prospek.title} - - - -
- -
-
-
-
- - ) : ( -
- Tidak ada file -
- )} - {/* */} -
- - ); -} diff --git a/src/app_modules/investasi/index.ts b/src/app_modules/investasi/index.ts index 1881634e..96964af3 100644 --- a/src/app_modules/investasi/index.ts +++ b/src/app_modules/investasi/index.ts @@ -7,8 +7,6 @@ import PortofolioInvestasi from "./portofolio/view"; import LayoutPortofolioInvestasi from "./portofolio/layout"; import EditIntroInvestasi from "./edit_intro/view"; import LayoutEditIntroInvestasi from "./edit_intro/layout"; -import EditProspektusInvestasi from "./edit_propektus/view"; -import LayoutEditProspektusInvestasi from "./edit_propektus/layout"; import EditDokumenInvestasi from "./edit_dokumen/view"; import LayoutEditDokumenInvestasi from "./edit_dokumen/layout"; import EditBeritaInvestasi from "./edit_berita/view"; @@ -58,8 +56,6 @@ export { LayoutPortofolioInvestasi, EditIntroInvestasi, LayoutEditIntroInvestasi, - EditProspektusInvestasi, - LayoutEditProspektusInvestasi, EditDokumenInvestasi, LayoutEditDokumenInvestasi, EditBeritaInvestasi, diff --git a/src/app_modules/job/edit/view.tsx b/src/app_modules/job/edit/view.tsx index 9556a825..b41fb92d 100644 --- a/src/app_modules/job/edit/view.tsx +++ b/src/app_modules/job/edit/view.tsx @@ -2,22 +2,15 @@ import { AspectRatio, - Button, Center, - FileButton, Image, Stack, Text, TextInput, } from "@mantine/core"; -import { IconCamera } from "@tabler/icons-react"; import { useState } from "react"; import { MODEL_JOB } from "../model/interface"; -import { - AccentColor, - MainColor, -} from "@/app_modules/_global/color/color_pallet"; import { ComponentGlobal_BoxUploadImage, ComponentGlobal_ButtonUploadFileImage, diff --git a/src/app_modules/katalog/profile/create/view_upload_foto.tsx b/src/app_modules/katalog/profile/create/view_upload_foto.tsx index 6e4cfa0c..2163dd53 100644 --- a/src/app_modules/katalog/profile/create/view_upload_foto.tsx +++ b/src/app_modules/katalog/profile/create/view_upload_foto.tsx @@ -3,13 +3,7 @@ import { ComponentGlobal_BoxInformation, ComponentGlobal_ButtonUploadFileImage, } from "@/app_modules/_global/component"; -import { - Avatar, - Box, - Center, - Paper, - Stack -} from "@mantine/core"; +import { Avatar, Box, Center, Paper, Stack } from "@mantine/core"; import { useState } from "react"; export default function Profile_ViewUploadFoto({ @@ -68,125 +62,6 @@ export default function Profile_ViewUploadFoto({ onSetImage={onSetImgPP} />
- - {/*
- { - try { - setLoadingButton(true); - const buffer = URL.createObjectURL( - new Blob([new Uint8Array(await files.arrayBuffer())]) - ); - - // if (files.size > MAX_SIZE) { - // ComponentGlobal_NotifikasiPeringatan( - // PemberitahuanMaksimalFile - // ); - // onSetImgPP(null); - - // return; - // } - - if (fotoProfileId != "") { - try { - const deleteFotoProfile = await funGlobal_DeleteFileById({ - fileId: fotoProfileId, - dirId: DIRECTORY_ID.profile_foto, - }); - - if (!deleteFotoProfile.success) { - clientLogger.error( - "Client failed delete photo profile:" + - deleteFotoProfile.message - ); - - return; - } - - if (deleteFotoProfile.success) { - onSetFotoProfileId(""); - onSetImgPP(null); - - const uploadPhoto = await funGlobal_UploadToStorage({ - file: files, - dirId: DIRECTORY_ID.profile_foto, - }); - - if (!uploadPhoto.success) { - clientLogger.error( - "Client failed upload photo profile::" + - uploadPhoto.message - ); - return; - } - - if (uploadPhoto.success) { - clientLogger.info( - "Client success upload foto profile" - ); - onSetFotoProfileId(uploadPhoto.data.id); - onSetImgPP(buffer); - } else { - clientLogger.error( - "Client failed upload foto:", - uploadPhoto.message - ); - ComponentGlobal_NotifikasiPeringatan( - "Gagal upload foto profile" - ); - } - } - } catch (error) { - clientLogger.error("Client error upload foto:", error); - } - } else { - try { - const uploadPhoto = await funGlobal_UploadToStorage({ - file: files, - dirId: DIRECTORY_ID.profile_foto, - }); - - if (uploadPhoto.success) { - clientLogger.info("Client success upload foto profile"); - onSetFotoProfileId(uploadPhoto.data.id); - onSetImgPP(buffer); - } else { - clientLogger.error( - "Client failed upload foto:", - uploadPhoto.message - ); - ComponentGlobal_NotifikasiPeringatan( - "Gagal upload foto profile" - ); - } - } catch (error) { - clientLogger.error("Client error upload foto:", error); - } - } - } catch (error) { - clientLogger.error("Client error upload foto:", error); - } finally { - setLoadingButton(false); - } - }} - accept="image/png,image/jpeg" - > - {(props) => ( - - )} - -
*/}
diff --git a/src/middleware.ts b/src/middleware.ts index bbabbb1d..d06f99e2 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -29,12 +29,13 @@ const middlewareConfig: MiddlewareConfig = { "/api/collaboration/*", "/api/notifikasi/*", "/api/logs/*", - // "/api/image/*", "/api/job/*", "/api/auth/*", "/api/origin-url", - // "/api/user", "/api/event/*", + // "/api/image/*", + // "/api/user", + // "/api/new/*", // Akses awal "/api/get-cookie", "/api/user/activation", diff --git a/xhtml/index.html b/xhtml/index.html new file mode 100644 index 00000000..23e750a9 --- /dev/null +++ b/xhtml/index.html @@ -0,0 +1,44 @@ + + + + + + Document + + + +
+ + + From 60ea92cbb521ded2773d307ddf50198beec5db12 Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Wed, 15 Jan 2025 15:16:52 +0800 Subject: [PATCH 2/4] fix ( upload image & api ) deskripsi: - fix upload dokumen investasi - fix api investasi --- src/app/api/new/investasi/[id]/route.ts | 77 +++++---- .../api/new/investasi/dokumen/[id]/route.ts | 61 +++++++ .../investasi/create/dokumen/[id]/page.tsx | 6 +- .../investasi/detail/portofolio/[id]/page.tsx | 16 +- .../investasi/dokumen/daftar/[id]/page.tsx | 16 +- .../dev/investasi/dokumen/rekap/[id]/page.tsx | 14 +- .../dev/investasi/edit/dokumen/[id]/page.tsx | 9 +- .../investasi/edit_dokumen/[id]/layout.tsx | 8 - .../dev/investasi/edit_dokumen/[id]/page.tsx | 10 -- src/app/lib/prisma.ts | 6 +- .../detail/comp_card_rekap_document.tsx | 21 ++- .../investasi/_component/skeleton_view.tsx | 13 +- .../_fun/get/fun_get_one_document_by_id.tsx | 24 +-- .../investasi/_lib/api_interface.ts | 56 +++++-- .../_ui/create/ui_create_document.tsx | 4 +- .../_ui/detail/ui_daftar_dokumen.tsx | 13 +- .../_ui/detail/ui_detail_portofolio.tsx | 84 ++++++---- .../investasi/_ui/detail/ui_rekap_dokumen.tsx | 15 +- .../investasi/_ui/edit/ui_edit_dokumen.tsx | 4 +- .../_ui/edit/ui_edit_investasi_new.tsx | 1 + .../_view/create/view_create_document.tsx | 155 +++++++++--------- .../_view/detail/view_daftar_dokemen.tsx | 63 +++++-- .../_view/detail/view_rekap_dokumen.tsx | 61 +++++-- .../_view/edit/view_edit_dokumen.tsx | 145 +++++++++++----- .../_view/edit/view_edit_investasi_new.tsx | 5 +- .../_view/edit/view_edit_prospektus.tsx | 6 +- .../investasi/edit_dokumen/layout.tsx | 60 ------- .../investasi/edit_dokumen/view.tsx | 87 ---------- src/app_modules/investasi/index.ts | 4 - 29 files changed, 543 insertions(+), 501 deletions(-) create mode 100644 src/app/api/new/investasi/dokumen/[id]/route.ts delete mode 100644 src/app/dev/investasi/edit_dokumen/[id]/layout.tsx delete mode 100644 src/app/dev/investasi/edit_dokumen/[id]/page.tsx delete mode 100644 src/app_modules/investasi/edit_dokumen/layout.tsx delete mode 100644 src/app_modules/investasi/edit_dokumen/view.tsx diff --git a/src/app/api/new/investasi/[id]/route.ts b/src/app/api/new/investasi/[id]/route.ts index 2b7342d1..bb4431f9 100644 --- a/src/app/api/new/investasi/[id]/route.ts +++ b/src/app/api/new/investasi/[id]/route.ts @@ -2,39 +2,48 @@ 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, - prospektusFileId: true, - masterPencarianInvestorId: true, - masterPeriodeDevidenId: true, - masterPembagianDevidenId: true, - } - }); +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 }); - } -} \ No newline at end of file + 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 } + ); + } +} diff --git a/src/app/api/new/investasi/dokumen/[id]/route.ts b/src/app/api/new/investasi/dokumen/[id]/route.ts new file mode 100644 index 00000000..69fc027b --- /dev/null +++ b/src/app/api/new/investasi/dokumen/[id]/route.ts @@ -0,0 +1,61 @@ +import { prisma } from "@/app/lib"; +import backendLogger from "@/util/backendLogger"; +import { NextResponse } from "next/server"; + +export async function GET( + request: Request, + context: { params: { id: string } } +) { + if (request.method === "GET") { + try { + let fixData; + const { id } = context.params; + const { searchParams } = new URL(request.url); + const kategori = searchParams.get("kategori"); + const page = searchParams.get("page"); + const takeData = 10; + const skipData = Number(page) * takeData - takeData; + + if (kategori == null) { + fixData = await prisma.dokumenInvestasi.findFirst({ + where: { + id: id, + }, + }); + } else if (kategori == "get-all") { + fixData = await prisma.dokumenInvestasi.findMany({ + take: takeData, + skip: skipData, + orderBy: { + updatedAt: "desc", + }, + where: { + investasiId: id, + active: true, + }, + }); + } + + await prisma.$disconnect(); + + return NextResponse.json( + { success: true, message: "Success get data document", data: fixData }, + { status: 200 } + ); + } catch (error) { + backendLogger.error("Error get data document", error); + return NextResponse.json( + { + success: false, + message: "Failed to get data, try again later", + reason: (error as Error).message, + }, + { status: 500 } + ); + } + } + return NextResponse.json( + { success: false, message: "Method not allowed" }, + { status: 405 } + ); +} diff --git a/src/app/dev/investasi/create/dokumen/[id]/page.tsx b/src/app/dev/investasi/create/dokumen/[id]/page.tsx index 66a66f7c..92255f76 100644 --- a/src/app/dev/investasi/create/dokumen/[id]/page.tsx +++ b/src/app/dev/investasi/create/dokumen/[id]/page.tsx @@ -1,11 +1,9 @@ import { Investasi_UiCreateDocument } from "@/app_modules/investasi/_ui"; -export default async function Page({ params }: { params: { id: string } }) { - const investasiId = params.id; - +export default async function Page() { return ( <> - + ); } diff --git a/src/app/dev/investasi/detail/portofolio/[id]/page.tsx b/src/app/dev/investasi/detail/portofolio/[id]/page.tsx index 5b9ff1a6..b4251bf8 100644 --- a/src/app/dev/investasi/detail/portofolio/[id]/page.tsx +++ b/src/app/dev/investasi/detail/portofolio/[id]/page.tsx @@ -1,21 +1,9 @@ -import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; -import { investasi_funGetOneInvestasiById } from "@/app_modules/investasi/_fun"; import { Investasi_UiDetailPortofolio } from "@/app_modules/investasi/_ui"; -export default async function Page({ params }: { params: { id: string } }) { - const investasiId = params.id; - const userLoginId = await funGetUserIdByToken(); - - const dataPortofolio = await investasi_funGetOneInvestasiById({ - investasiId, - }); - +export default async function Page() { return ( <> - + ); } diff --git a/src/app/dev/investasi/dokumen/daftar/[id]/page.tsx b/src/app/dev/investasi/dokumen/daftar/[id]/page.tsx index e9337215..2478ddae 100644 --- a/src/app/dev/investasi/dokumen/daftar/[id]/page.tsx +++ b/src/app/dev/investasi/dokumen/daftar/[id]/page.tsx @@ -1,21 +1,9 @@ -import { - investasi_funGetAllDocumentById -} from "@/app_modules/investasi/_fun"; import { Investasi_UiDaftarDokmen } from "@/app_modules/investasi/_ui"; -export default async function Page({ params }: { params: { id: string } }) { - const investasiId = params.id; - const dataDokumen = await investasi_funGetAllDocumentById({ - investasiId: investasiId, - page: 1, - }); - +export default async function Page() { return ( <> - + ); } diff --git a/src/app/dev/investasi/dokumen/rekap/[id]/page.tsx b/src/app/dev/investasi/dokumen/rekap/[id]/page.tsx index 074777ab..596336ea 100644 --- a/src/app/dev/investasi/dokumen/rekap/[id]/page.tsx +++ b/src/app/dev/investasi/dokumen/rekap/[id]/page.tsx @@ -1,19 +1,9 @@ -import { investasi_funGetAllDocumentById } from "@/app_modules/investasi/_fun"; import { Investasi_UiRekapDokumen } from "@/app_modules/investasi/_ui"; -export default async function Page({ params }: { params: { id: string } }) { - const investasiId = params.id; - const dataDokumen = await investasi_funGetAllDocumentById({ - investasiId, - page: 1, - }); - +export default async function Page() { return ( <> - + ); } diff --git a/src/app/dev/investasi/edit/dokumen/[id]/page.tsx b/src/app/dev/investasi/edit/dokumen/[id]/page.tsx index 95da1b64..6be72e19 100644 --- a/src/app/dev/investasi/edit/dokumen/[id]/page.tsx +++ b/src/app/dev/investasi/edit/dokumen/[id]/page.tsx @@ -1,14 +1,9 @@ -import { investasi_funGetOneDocumentById } from "@/app_modules/investasi/_fun"; import { Investasi_UiEditDokumen } from "@/app_modules/investasi/_ui"; -export default async function Page({ params }: { params: { id: string } }) { - const documentId = params.id; - const dataDokumen = await investasi_funGetOneDocumentById({ documentId }); - - +export default async function Page() { return ( <> - + ); } diff --git a/src/app/dev/investasi/edit_dokumen/[id]/layout.tsx b/src/app/dev/investasi/edit_dokumen/[id]/layout.tsx deleted file mode 100644 index e051bfc5..00000000 --- a/src/app/dev/investasi/edit_dokumen/[id]/layout.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import { LayoutEditDokumenInvestasi } from "@/app_modules/investasi"; -import React from "react"; - -export default async function Layout({children, params}: {children: React.ReactNode, params: {id: string}}) { - return<> - {children} - -} \ No newline at end of file diff --git a/src/app/dev/investasi/edit_dokumen/[id]/page.tsx b/src/app/dev/investasi/edit_dokumen/[id]/page.tsx deleted file mode 100644 index b7100cfe..00000000 --- a/src/app/dev/investasi/edit_dokumen/[id]/page.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import { EditDokumenInvestasi } from "@/app_modules/investasi"; -import getOneInvestasiById from "@/app_modules/investasi/fun/get_one_investasi_by_id"; - -export default async function Page({params}: {params: {id: string}}) { - const dataInvestasi = await getOneInvestasiById(params.id) - // console.log(dataInvestasi) - return<> - - -} \ No newline at end of file diff --git a/src/app/lib/prisma.ts b/src/app/lib/prisma.ts index 69fef907..bb2d1af0 100644 --- a/src/app/lib/prisma.ts +++ b/src/app/lib/prisma.ts @@ -1,3 +1,4 @@ +import { useDisclosure } from "@mantine/hooks"; import { PrismaClient } from "@prisma/client"; // Singleton PrismaClient untuk pengembangan @@ -20,8 +21,9 @@ if (process.env.NODE_ENV !== "production") { } process.on("SIGINT", async () => { - // console.log("Disconnecting PrismaClient..."); - await prisma.$disconnect(); + console.log("Start in Disconnecting PrismaClient..."); + const disconnect = await prisma.$disconnect(); + console.log("End of Disconnecting PrismaClient...", disconnect); process.exit(0); }); diff --git a/src/app_modules/investasi/_component/detail/comp_card_rekap_document.tsx b/src/app_modules/investasi/_component/detail/comp_card_rekap_document.tsx index 5e62a0f2..af2507bc 100644 --- a/src/app_modules/investasi/_component/detail/comp_card_rekap_document.tsx +++ b/src/app_modules/investasi/_component/detail/comp_card_rekap_document.tsx @@ -17,7 +17,7 @@ import { Text, } from "@mantine/core"; import { IconDots, IconEdit, IconTrash } from "@tabler/icons-react"; -import { useRouter } from "next/navigation"; +import { useParams, useRouter } from "next/navigation"; import { useState } from "react"; import { MODEL_INVESTASI_DOKUMEN } from "../../_lib/interface"; import ComponentGlobal_Loader from "@/app_modules/_global/component/loader"; @@ -30,6 +30,8 @@ import { ComponentGlobal_NotifikasiBerhasil, ComponentGlobal_NotifikasiPeringatan, } from "@/app_modules/_global/notif_global"; +import { apiGetDokumenInvestasiById } from "../../_lib/api_interface"; +import { clientLogger } from "@/util/clientLogger"; export function Investasi_ComponentCardRekapDocument({ data, @@ -38,6 +40,9 @@ export function Investasi_ComponentCardRekapDocument({ data: MODEL_INVESTASI_DOKUMEN; onSetData: (val: any) => any[]; }) { + const params = useParams<{ id: string }>(); + const investasiId = params.id; + const router = useRouter(); const [openDrawer, setOpenDrawer] = useState(false); const [isLoadingEdit, setIsLoadingEdit] = useState(false); @@ -63,18 +68,22 @@ export function Investasi_ComponentCardRekapDocument({ if (deleteFromDB.status !== 200) { ComponentGlobal_NotifikasiPeringatan(deleteFromDB.message); + return; } ComponentGlobal_NotifikasiBerhasil(deleteFromDB.message); setOpenModal(false); - const loadData = await investasi_funGetAllDocumentById({ - investasiId: data.investasiId, - page: 1, + const respone = await apiGetDokumenInvestasiById({ + id: investasiId, + kategori: "get-all", + page: "1", }); - onSetData(loadData); + if (respone.success) { + onSetData(respone.data); + } } catch (error) { - console.log(error); + clientLogger.error("Error hapus dokumen", error); } finally { setIsLoadingDelete(false); } diff --git a/src/app_modules/investasi/_component/skeleton_view.tsx b/src/app_modules/investasi/_component/skeleton_view.tsx index 8f03289b..bb2db917 100644 --- a/src/app_modules/investasi/_component/skeleton_view.tsx +++ b/src/app_modules/investasi/_component/skeleton_view.tsx @@ -1,7 +1,7 @@ import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; import { Box, Center, Stack } from "@mantine/core"; -export { Investasi_SkeletonEditProspektus }; +export { Investasi_SkeletonEditProspektus, Investasi_SkeletonListDokumen }; function Investasi_SkeletonEditProspektus() { return ( @@ -33,3 +33,14 @@ function Investasi_SkeletonEditProspektus() { ); } + +function Investasi_SkeletonListDokumen() { + return ( + <> + + + + + + ); +} diff --git a/src/app_modules/investasi/_fun/get/fun_get_one_document_by_id.tsx b/src/app_modules/investasi/_fun/get/fun_get_one_document_by_id.tsx index e31ef426..f44b4b6c 100644 --- a/src/app_modules/investasi/_fun/get/fun_get_one_document_by_id.tsx +++ b/src/app_modules/investasi/_fun/get/fun_get_one_document_by_id.tsx @@ -1,13 +1,17 @@ -"use server" +"use server"; -import { prisma } from "@/app/lib" +import { prisma } from "@/app/lib"; -export async function investasi_funGetOneDocumentById({ documentId }: { documentId: string }) { - const data = await prisma.dokumenInvestasi.findFirst({ - where: { - id: documentId - } - }) +export async function investasi_funGetOneDocumentById({ + documentId, +}: { + documentId: string; +}) { + const data = await prisma.dokumenInvestasi.findFirst({ + where: { + id: documentId, + }, + }); - return data -} \ No newline at end of file + return data; +} diff --git a/src/app_modules/investasi/_lib/api_interface.ts b/src/app_modules/investasi/_lib/api_interface.ts index a31133b6..1d400aee 100644 --- a/src/app_modules/investasi/_lib/api_interface.ts +++ b/src/app_modules/investasi/_lib/api_interface.ts @@ -1,3 +1,18 @@ +export const apiGetOneInvestasiById = async ({ id }: { id: string }) => { + const { token } = await fetch("/api/get-cookie").then((res) => res.json()); + if (!token) return await token.json().catch(() => null); + + const response = await fetch(`/api/new/investasi/${id}`, { + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "Access-Control-Allow-Origin": "*", + Authorization: `Bearer ${token}`, + }, + }); + return await response.json().catch(() => null); +}; + export const apiGetMasterInvestasi = async (path?: string) => { const { token } = await fetch("/api/get-cookie").then((res) => res.json()); if (!token) return await token.json().catch(() => null); @@ -14,21 +29,6 @@ export const apiGetMasterInvestasi = async (path?: string) => { return await response.json().catch(() => null); }; -export const apiGetOneInvestasiById = async (path: string) => { - const { token } = await fetch("/api/get-cookie").then((res) => res.json()); - if (!token) return await token.json().catch(() => null); - - const response = await fetch(`/api/new/investasi/${path}`, { - headers: { - "Content-Type": "application/json", - Accept: "application/json", - "Access-Control-Allow-Origin": "*", - Authorization: `Bearer ${token}`, - }, - }); - return await response.json().catch(() => null); -}; - export const apiGetAllInvestasi = async (path?: string) => { const { token } = await fetch("/api/get-cookie").then((res) => res.json()); if (!token) return await token.json().catch(() => null); @@ -62,3 +62,29 @@ export const apiGetAllSahamSaya = async (path?: string) => { ); return await response.json().catch(() => null); }; + +export const apiGetDokumenInvestasiById = async ({ + id, + kategori, + page, +}: { + id: string; + kategori?: undefined | "get-all"; + page?: string; +}) => { + const { token } = await fetch("/api/get-cookie").then((res) => res.json()); + if (!token) return await token.json().catch(() => null); + + const response = await fetch( + `/api/new/investasi/dokumen/${id}${kategori ? `?kategori=${kategori}&page=${page}` : ""}`, + { + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "Access-Control-Allow-Origin": "*", + Authorization: `Bearer ${token}`, + }, + } + ); + return await response.json().catch(() => null); +}; diff --git a/src/app_modules/investasi/_ui/create/ui_create_document.tsx b/src/app_modules/investasi/_ui/create/ui_create_document.tsx index ada8bef7..2404f3b1 100644 --- a/src/app_modules/investasi/_ui/create/ui_create_document.tsx +++ b/src/app_modules/investasi/_ui/create/ui_create_document.tsx @@ -3,13 +3,13 @@ import { UIGlobal_LayoutHeaderTamplate, UIGlobal_LayoutTamplate } from "@/app_modules/_global/ui" import { Investasi_ViewCreateDocument } from "../../_view"; -export function Investasi_UiCreateDocument({ investasiId }: { investasiId : string}) { +export function Investasi_UiCreateDocument() { return ( <> } > - + ); diff --git a/src/app_modules/investasi/_ui/detail/ui_daftar_dokumen.tsx b/src/app_modules/investasi/_ui/detail/ui_daftar_dokumen.tsx index becc1705..6784f724 100644 --- a/src/app_modules/investasi/_ui/detail/ui_daftar_dokumen.tsx +++ b/src/app_modules/investasi/_ui/detail/ui_daftar_dokumen.tsx @@ -6,22 +6,13 @@ import { } from "@/app_modules/_global/ui"; import { Investasi_ViewDaftarDokumen } from "../../_view"; -export function Investasi_UiDaftarDokmen({ - dataDokumen, - investasiId, -}: { - dataDokumen: any[]; - investasiId: string -}) { +export function Investasi_UiDaftarDokmen() { return ( <> } > - + ); diff --git a/src/app_modules/investasi/_ui/detail/ui_detail_portofolio.tsx b/src/app_modules/investasi/_ui/detail/ui_detail_portofolio.tsx index 1399f467..c02a2563 100644 --- a/src/app_modules/investasi/_ui/detail/ui_detail_portofolio.tsx +++ b/src/app_modules/investasi/_ui/detail/ui_detail_portofolio.tsx @@ -1,63 +1,93 @@ "use client"; import { NEW_RouterInvestasi } from "@/app/lib/router_hipmi/router_investasi"; +import { MainColor } from "@/app_modules/_global/color"; +import ComponentGlobal_Loader from "@/app_modules/_global/component/loader"; import { - UIGlobal_Drawer, UIGlobal_DrawerCustom, UIGlobal_LayoutHeaderTamplate, UIGlobal_LayoutTamplate, } from "@/app_modules/_global/ui"; -import { ActionIcon, Box, SimpleGrid, Stack, Text } from "@mantine/core"; +import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; +import { clientLogger } from "@/util/clientLogger"; +import { ActionIcon, SimpleGrid, Stack, Text } from "@mantine/core"; +import { useShallowEffect } from "@mantine/hooks"; import { IconCategoryPlus, IconDotsVertical, IconEdit, IconFilePencil, } from "@tabler/icons-react"; -import { useRouter } from "next/navigation"; +import { useParams, useRouter } from "next/navigation"; import { useState } from "react"; +import { apiGetOneInvestasiById } from "../../_lib/api_interface"; import { MODEL_INVESTASI } from "../../_lib/interface"; import { Investasi_ViewDetailDraft, Investasi_ViewDetailReject, Investasi_ViewDetailReview, } from "../../_view"; -import ComponentGlobal_Loader from "@/app_modules/_global/component/loader"; -import { MainColor } from "@/app_modules/_global/color"; -export function Investasi_UiDetailPortofolio({ - dataInvestasi, - userLoginId, -}: { - dataInvestasi: MODEL_INVESTASI; - userLoginId: string; -}) { +export function Investasi_UiDetailPortofolio() { + const params = useParams<{ id: string }>(); + const investasiId = params.id; + const router = useRouter(); const [isLoading, setLoading] = useState(false); const [pageId, setPageId] = useState(""); const [openDrawer, setOpenDrawer] = useState(false); - const [data, setData] = useState(dataInvestasi); + const [data, setData] = useState(null); const listPage = [ { id: "1", name: "Edit Investasi", icon: , - path: NEW_RouterInvestasi.edit_investasi({ id: data.id }), + path: NEW_RouterInvestasi.edit_investasi({ id: investasiId }), }, { id: "2", name: "Edit Prospektus", icon: , - path: NEW_RouterInvestasi.edit_prospektus({ id: data.id }), + path: NEW_RouterInvestasi.edit_prospektus({ id: investasiId }), }, { id: "3", name: "Tambah & Edit Dokumen", icon: , - path: NEW_RouterInvestasi.rekap_dokumen({ id: data.id }), + path: NEW_RouterInvestasi.rekap_dokumen({ id: investasiId }), }, ]; + useShallowEffect(() => { + onLoadData(); + }, []); + + async function onLoadData() { + try { + const respone = await apiGetOneInvestasiById({ + id: investasiId, + }); + + if (respone.success) { + setData(respone.data); + } + } catch (error) { + clientLogger.error("Error get detail investasi:", error); + } + } + + if (data === null) { + return ( + <> + } + > + + + + ); + } + if (data.masterStatusInvestasiId == "3") return ( <> @@ -76,15 +106,9 @@ export function Investasi_UiDetailPortofolio({ /> } > - + - {/* setOpenDrawer(false)} - component={listPage} - /> */} - setOpenDrawer(false)} @@ -98,9 +122,7 @@ export function Investasi_UiDetailPortofolio({ onClick={() => { setPageId(e?.id); setLoading(true); - if (e.id === "1") { - setData({}); - } + router.push(e?.path, { scroll: false }); }} > @@ -125,16 +147,16 @@ export function Investasi_UiDetailPortofolio({ } > - {dataInvestasi.masterStatusInvestasiId === "2" && ( - + {data.masterStatusInvestasiId === "2" && ( + )} - {dataInvestasi.masterStatusInvestasiId === "4" && ( - + {data.masterStatusInvestasiId === "4" && ( + )} ); diff --git a/src/app_modules/investasi/_ui/detail/ui_rekap_dokumen.tsx b/src/app_modules/investasi/_ui/detail/ui_rekap_dokumen.tsx index 9d66d28d..81e8c40d 100644 --- a/src/app_modules/investasi/_ui/detail/ui_rekap_dokumen.tsx +++ b/src/app_modules/investasi/_ui/detail/ui_rekap_dokumen.tsx @@ -10,16 +10,13 @@ import { ActionIcon } from "@mantine/core"; import { IconCirclePlus, IconDotsVertical } from "@tabler/icons-react"; import { useState } from "react"; import { Investasi_ViewRekapDokumen } from "../../_view"; +import { useParams } from "next/navigation"; + +export function Investasi_UiRekapDokumen() { + const params = useParams<{ id: string }>(); + const investasiId = params.id; -export function Investasi_UiRekapDokumen({ - investasiId, - dataDokumen, -}: { - investasiId: string; - dataDokumen: any[] -}) { const [openDrawer, setOpenDrawer] = useState(false); - const listPage = [ { id: "1", @@ -47,8 +44,6 @@ export function Investasi_UiRekapDokumen({ } > diff --git a/src/app_modules/investasi/_ui/edit/ui_edit_dokumen.tsx b/src/app_modules/investasi/_ui/edit/ui_edit_dokumen.tsx index 5b53fada..6d53644c 100644 --- a/src/app_modules/investasi/_ui/edit/ui_edit_dokumen.tsx +++ b/src/app_modules/investasi/_ui/edit/ui_edit_dokumen.tsx @@ -6,13 +6,13 @@ import { } from "@/app_modules/_global/ui"; import { Investasi_ViewEditDokumen } from "../../_view"; -export function Investasi_UiEditDokumen({ dataDokumen }: { dataDokumen: any }) { +export function Investasi_UiEditDokumen() { return ( <> } > - + ); diff --git a/src/app_modules/investasi/_ui/edit/ui_edit_investasi_new.tsx b/src/app_modules/investasi/_ui/edit/ui_edit_investasi_new.tsx index e0edfa1e..ec214403 100644 --- a/src/app_modules/investasi/_ui/edit/ui_edit_investasi_new.tsx +++ b/src/app_modules/investasi/_ui/edit/ui_edit_investasi_new.tsx @@ -1,4 +1,5 @@ "use client"; + import { UIGlobal_LayoutHeaderTamplate, UIGlobal_LayoutTamplate, } from "@/app_modules/_global/ui"; import { Investasi_ViewEditInvestasiNew } from "../../_view/edit/view_edit_investasi_new"; diff --git a/src/app_modules/investasi/_view/create/view_create_document.tsx b/src/app_modules/investasi/_view/create/view_create_document.tsx index 975f57d0..b94290f4 100644 --- a/src/app_modules/investasi/_view/create/view_create_document.tsx +++ b/src/app_modules/investasi/_view/create/view_create_document.tsx @@ -1,51 +1,53 @@ +import { DIRECTORY_ID } from "@/app/lib"; import { MainColor } from "@/app_modules/_global/color"; import { ComponentGlobal_BoxInformation, + ComponentGlobal_ButtonUploadFileImage, ComponentGlobal_CardStyles, } from "@/app_modules/_global/component"; -import { - Stack, - Grid, - Center, - Group, - FileButton, - Button, - Text, - TextInput, -} from "@mantine/core"; -import { IconCircleCheck, IconCamera } from "@tabler/icons-react"; -import { useRouter } from "next/navigation"; -import { useState } from "react"; -import { investasi_funCreateDocument } from "../../_fun"; import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun"; -import { DIRECTORY_ID } from "@/app/lib"; import { ComponentGlobal_NotifikasiBerhasil, ComponentGlobal_NotifikasiPeringatan, } from "@/app_modules/_global/notif_global"; +import { clientLogger } from "@/util/clientLogger"; +import { + Box, + Button, + Center, + Grid, + Stack, + Text, + TextInput, +} from "@mantine/core"; +import { IconCircleCheck, IconFileTypePdf } from "@tabler/icons-react"; +import { useParams, useRouter } from "next/navigation"; +import { useState } from "react"; +import { investasi_funCreateDocument } from "../../_fun"; + +export function Investasi_ViewCreateDocument() { + const params = useParams<{ id: string }>(); + const investasiId = params.id; -export function Investasi_ViewCreateDocument({ - investasiId, -}: { - investasiId: string; -}) { const router = useRouter(); const [filePdf, setFilePdf] = useState(null); const [isLoading, setIsLoading] = useState(false); const [title, setTitle] = useState(""); async function onCreate() { - setIsLoading(true); - const uploadFileDokumen = await funGlobal_UploadToStorage({ - file: filePdf as any, - dirId: DIRECTORY_ID.investasi_dokumen, - }); - if (!uploadFileDokumen.success) { - setIsLoading(false); - ComponentGlobal_NotifikasiPeringatan("Gagal upload file pdf"); - } - try { + setIsLoading(true); + const uploadFileDokumen = await funGlobal_UploadToStorage({ + file: filePdf as any, + dirId: DIRECTORY_ID.investasi_dokumen, + }); + + if (!uploadFileDokumen.success) { + setIsLoading(false); + ComponentGlobal_NotifikasiPeringatan("Gagal upload file pdf"); + return; + } + const create = await investasi_funCreateDocument({ data: { investasiId: investasiId, @@ -54,15 +56,17 @@ export function Investasi_ViewCreateDocument({ }, }); - if (create.status !== 201) + if (create.status !== 201) { + setIsLoading(false); ComponentGlobal_NotifikasiPeringatan(create.message); + return; + } - router.back(); ComponentGlobal_NotifikasiBerhasil(create.message); + router.back(); } catch (error) { - console.log(error); - } finally { setIsLoading(false); + clientLogger.error("Error create document", error); } } @@ -73,6 +77,7 @@ export function Investasi_ViewCreateDocument({ {!filePdf ? ( - - Upload Dokumen - + + + ) : ( @@ -104,55 +109,43 @@ export function Investasi_ViewCreateDocument({ )} - - { - try { - const buffer = URL.createObjectURL( - new Blob([new Uint8Array(await files.arrayBuffer())]) - ); - - setFilePdf(files); - } catch (error) { - console.log(error); - } - }} - > - {(props) => ( - - )} - - +
+ +
- + + ); diff --git a/src/app_modules/investasi/_view/detail/view_daftar_dokemen.tsx b/src/app_modules/investasi/_view/detail/view_daftar_dokemen.tsx index 979f3430..4080d735 100644 --- a/src/app_modules/investasi/_view/detail/view_daftar_dokemen.tsx +++ b/src/app_modules/investasi/_view/detail/view_daftar_dokemen.tsx @@ -7,17 +7,43 @@ import { useState } from "react"; import { Investasi_ComponentCardDaftarDocument } from "../../_component"; import { investasi_funGetAllDocumentById } from "../../_fun"; import { MODEL_INVESTASI_DOKUMEN } from "../../_lib/interface"; +import { useParams } from "next/navigation"; +import { Investasi_SkeletonListDokumen } from "../../_component/skeleton_view"; +import { clientLogger } from "@/util/clientLogger"; +import { apiGetDokumenInvestasiById } from "../../_lib/api_interface"; +import { useShallowEffect } from "@mantine/hooks"; -export function Investasi_ViewDaftarDokumen({ - dataDokumen, - investasiId, -}: { - dataDokumen: any[]; - investasiId: string; -}) { - const [data, setData] = useState(dataDokumen); +export function Investasi_ViewDaftarDokumen() { + const params = useParams<{ id: string }>(); + const investasiId = params.id; + + const [data, setData] = useState(null); const [activePage, setActivePage] = useState(1); + useShallowEffect(() => { + onLoadData(); + }, []); + + async function onLoadData() { + try { + const respone = await apiGetDokumenInvestasiById({ + id: investasiId, + kategori: "get-all", + page: `${activePage}`, + }); + + if (respone.success) { + setData(respone.data); + } + } catch (error) { + clientLogger.error("Error get data dokumen", error); + } + } + + if (data === null) { + return ; + } + return ( <> @@ -34,16 +60,23 @@ export function Investasi_ViewDaftarDokumen({ )} data={data} - setData={setData} + setData={setData as any} moreData={async () => { - const loadData = await investasi_funGetAllDocumentById({ - investasiId: investasiId, - page: activePage + 1, - }); + try { + const respone = await apiGetDokumenInvestasiById({ + id: investasiId, + kategori: "get-all", + page: `${activePage + 1}`, + }); - setActivePage((val) => val + 1); + if (respone.success) { + setActivePage((val) => val + 1); - return loadData; + return respone.data; + } + } catch (error) { + clientLogger.error("Error load data dokumen:", error); + } }} > {(item) => ( diff --git a/src/app_modules/investasi/_view/detail/view_rekap_dokumen.tsx b/src/app_modules/investasi/_view/detail/view_rekap_dokumen.tsx index 5b0e0285..d1f573b8 100644 --- a/src/app_modules/investasi/_view/detail/view_rekap_dokumen.tsx +++ b/src/app_modules/investasi/_view/detail/view_rekap_dokumen.tsx @@ -8,17 +8,41 @@ import { Investasi_ComponentCardRekapDocument } from "../../_component"; import { investasi_funGetAllDocumentById } from "../../_fun"; import { MODEL_INVESTASI_DOKUMEN } from "../../_lib/interface"; import { useShallowEffect } from "@mantine/hooks"; +import { useParams } from "next/navigation"; +import { apiGetDokumenInvestasiById } from "../../_lib/api_interface"; +import { Investasi_SkeletonListDokumen } from "../../_component/skeleton_view"; +import { clientLogger } from "@/util/clientLogger"; -export function Investasi_ViewRekapDokumen({ - dataDokumen, - investasiId, -}: { - dataDokumen: any[]; - investasiId: string; -}) { - const [data, setData] = useState(dataDokumen); +export function Investasi_ViewRekapDokumen() { + const params = useParams<{ id: string }>(); + const investasiId = params.id; + + const [data, setData] = useState(null); const [activePage, setActivePage] = useState(1); + useShallowEffect(() => { + onLoadData(); + }, []); + + async function onLoadData() { + try { + const respone = await apiGetDokumenInvestasiById({ + id: investasiId, + kategori: "get-all", + page: `${activePage}`, + }); + + if (respone.success) { + setData(respone.data); + } + } catch (error) { + clientLogger.error("Error get data dokumen", error); + } + } + + if (data === null) { + return ; + } return ( <> @@ -34,16 +58,23 @@ export function Investasi_ViewRekapDokumen({ )} data={data} - setData={setData} + setData={setData as any} moreData={async () => { - const loadData = await investasi_funGetAllDocumentById({ - investasiId: investasiId, - page: activePage + 1, - }); + try { + const respone = await apiGetDokumenInvestasiById({ + id: investasiId, + kategori: "get-all", + page: `${activePage + 1}`, + }); - setActivePage((val) => val + 1); + if (respone.success) { + setActivePage((val) => val + 1); - return loadData; + return respone.data; + } + } catch (error) { + clientLogger.error("Error load data dokumen:", error); + } }} > {(item) => ( diff --git a/src/app_modules/investasi/_view/edit/view_edit_dokumen.tsx b/src/app_modules/investasi/_view/edit/view_edit_dokumen.tsx index 802b36ec..3cdaa386 100644 --- a/src/app_modules/investasi/_view/edit/view_edit_dokumen.tsx +++ b/src/app_modules/investasi/_view/edit/view_edit_dokumen.tsx @@ -1,7 +1,8 @@ import { DIRECTORY_ID } from "@/app/lib"; import { MainColor } from "@/app_modules/_global/color"; import { - ComponentGlobal_CardStyles + ComponentGlobal_ButtonUploadFileImage, + ComponentGlobal_CardStyles, } from "@/app_modules/_global/component"; import { funGlobal_DeleteFileById, @@ -11,44 +12,62 @@ import { ComponentGlobal_NotifikasiBerhasil, ComponentGlobal_NotifikasiPeringatan, } from "@/app_modules/_global/notif_global"; +import { clientLogger } from "@/util/clientLogger"; import { + Box, Button, Center, - FileButton, Grid, - Group, Stack, Text, TextInput, } from "@mantine/core"; -import { IconCamera, IconCircleCheck } from "@tabler/icons-react"; +import { useShallowEffect } from "@mantine/hooks"; +import { IconCircleCheck } from "@tabler/icons-react"; import _ from "lodash"; -import { useRouter } from "next/navigation"; +import { useParams, useRouter } from "next/navigation"; import { useState } from "react"; +import { Investasi_SkeletonEditProspektus } from "../../_component/skeleton_view"; import { investasi_funUpdateDocument } from "../../_fun"; +import { apiGetDokumenInvestasiById } from "../../_lib/api_interface"; import { MODEL_INVESTASI_DOKUMEN } from "../../_lib/interface"; -export function Investasi_ViewEditDokumen({ - dataDokumen, -}: { - dataDokumen: MODEL_INVESTASI_DOKUMEN; -}) { +export function Investasi_ViewEditDokumen() { + const params = useParams<{ id: string }>(); + const dokumenId = params.id; + const router = useRouter(); const [filePdf, setFilePdf] = useState(null); const [isLoading, setIsLoading] = useState(false); - const [data, setData] = useState(dataDokumen); - const [title, setTitle] = useState(data.title); + const [data, setData] = useState(null); + // const [title, setTitle] = useState(data.title); + const [loading, setLoading] = useState(true); + + useShallowEffect(() => { + onGetDataDokumenById(); + }, []); + + async function onGetDataDokumenById() { + try { + setLoading(true); + const response = await apiGetDokumenInvestasiById({ + id: dokumenId, + }); + if (response.success) { + console.log(response.data); + setData(response.data); + } + } catch (error) { + console.error(error); + } finally { + setLoading(false); + } + } async function onUpdate() { try { setIsLoading(true); if (filePdf) { - const delfile = await funGlobal_DeleteFileById({ fileId: data.fileId }); - - if (!delfile.success) { - ComponentGlobal_NotifikasiPeringatan("Gagal hapus file lama"); - } - const uploadFile = await funGlobal_UploadToStorage({ file: filePdf, dirId: DIRECTORY_ID.investasi_dokumen, @@ -57,35 +76,52 @@ export function Investasi_ViewEditDokumen({ if (!uploadFile.success) { setIsLoading(false); ComponentGlobal_NotifikasiPeringatan("Gagal upload file dokumen"); + return; + } + + const delfile = await funGlobal_DeleteFileById({ + fileId: data?.fileId as any, + dirId: DIRECTORY_ID.investasi_dokumen, + }); + + if (!delfile.success) { + setIsLoading(false); + clientLogger.error("Gagal hapus file lama", delfile.message); } const updateWithFile = await investasi_funUpdateDocument({ - data: data, + data: data as any, fileId: uploadFile.data.id, }); if (updateWithFile.status !== 200) { + setIsLoading(false); ComponentGlobal_NotifikasiPeringatan(updateWithFile.message); } + ComponentGlobal_NotifikasiBerhasil(updateWithFile.message); + router.back(); } else { const updateNoFile = await investasi_funUpdateDocument({ - data: data, + data: data as any, }); if (updateNoFile.status !== 200) { + setIsLoading(false); ComponentGlobal_NotifikasiPeringatan(updateNoFile.message); } ComponentGlobal_NotifikasiBerhasil(updateNoFile.message); } } catch (error) { - console.log(error); - } finally { - router.back(); setIsLoading(false); + clientLogger.error(" Error update dokumen", error); } } + if (loading) { + return ; + } + return ( <> @@ -95,18 +131,23 @@ export function Investasi_ViewEditDokumen({ setData({ ...data, title: val.target.value })} + onChange={(val) => + setData({ + ...(data as any), + title: val.target.value, + }) + } /> {!filePdf ? ( - Dokumen {_.startCase(title)}.pdf + {_.startCase(data?.title)}.pdf ) : ( @@ -125,7 +166,15 @@ export function Investasi_ViewEditDokumen({ )} - +
+ +
+ + {/* { @@ -153,27 +202,37 @@ export function Investasi_ViewEditDokumen({ )} - +
*/}
- + +
); diff --git a/src/app_modules/investasi/_view/edit/view_edit_investasi_new.tsx b/src/app_modules/investasi/_view/edit/view_edit_investasi_new.tsx index c6ac403f..fc474b77 100644 --- a/src/app_modules/investasi/_view/edit/view_edit_investasi_new.tsx +++ b/src/app_modules/investasi/_view/edit/view_edit_investasi_new.tsx @@ -52,7 +52,10 @@ export function Investasi_ViewEditInvestasiNew() { async function onGetOneInvestasiById() { try { setLoading(true); - const response = await apiGetOneInvestasiById(param.id); + const response = await apiGetOneInvestasiById({ + id: param.id, + + }); if (response.success) { setData(response.data); setTotalLembar(response.data.totalLembar); diff --git a/src/app_modules/investasi/_view/edit/view_edit_prospektus.tsx b/src/app_modules/investasi/_view/edit/view_edit_prospektus.tsx index caf1c5f1..2bd3f364 100644 --- a/src/app_modules/investasi/_view/edit/view_edit_prospektus.tsx +++ b/src/app_modules/investasi/_view/edit/view_edit_prospektus.tsx @@ -48,7 +48,9 @@ export function Investasi_ViewEditProspektus() { async function onLoadData() { try { - const respone = await apiGetOneInvestasiById(investasiId); + const respone = await apiGetOneInvestasiById({ + id: investasiId, + }); if (respone.success) { setFileRemoveId(respone.data.prospektusFileId); } @@ -111,7 +113,7 @@ export function Investasi_ViewEditProspektus() { {!filePdf ? ( - + ) : ( diff --git a/src/app_modules/investasi/edit_dokumen/layout.tsx b/src/app_modules/investasi/edit_dokumen/layout.tsx deleted file mode 100644 index 3d740136..00000000 --- a/src/app_modules/investasi/edit_dokumen/layout.tsx +++ /dev/null @@ -1,60 +0,0 @@ -"use client"; - -import { RouterInvestasi_OLD } from "@/app/lib/router_hipmi/router_investasi"; -import UIGlobal_Drawer from "@/app_modules/_global/ui/ui_drawer"; -import UIGlobal_LayoutHeaderTamplate from "@/app_modules/_global/ui/ui_header_tamplate"; -import UIGlobal_LayoutTamplate from "@/app_modules/_global/ui/ui_layout_tamplate"; -import { ActionIcon } from "@mantine/core"; -import { IconDotsVertical, IconFilePlus } from "@tabler/icons-react"; -import { useRouter } from "next/navigation"; -import React from "react"; - -export default function LayoutEditDokumenInvestasi({ - children, - idInves, -}: { - children: React.ReactNode; - idInves: string; -}) { - const router = useRouter(); - const [isOpenDrawer, setIsOpenDrawer] = React.useState(false); - - const listPage = [ - { - id: "1", - name: "Tambah Dokumen", - icon: , - path: RouterInvestasi_OLD.upload_dokumen + `${idInves}`, - }, - ]; - - return ( - <> - } - // routerRight={RouterInvestasi.upload_dokumen + `${idInves}`} - customButtonRight={ - setIsOpenDrawer(true)} - > - - - } - /> - } - > - {children} - - - setIsOpenDrawer(false)} - component={listPage} - /> - - ); -} diff --git a/src/app_modules/investasi/edit_dokumen/view.tsx b/src/app_modules/investasi/edit_dokumen/view.tsx deleted file mode 100644 index ad41b4fa..00000000 --- a/src/app_modules/investasi/edit_dokumen/view.tsx +++ /dev/null @@ -1,87 +0,0 @@ -"use client"; - -import { - AccentColor, - MainColor, -} from "@/app_modules/_global/color/color_pallet"; -import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data"; -import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil"; -import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal"; -import { ActionIcon, Group, Paper, Text } from "@mantine/core"; -import { IconFolderOpen, IconTrash, IconWorldShare } from "@tabler/icons-react"; -import _ from "lodash"; -import Link from "next/link"; -import { useState } from "react"; -import funDeleteDokumenInvestasi from "../fun/fun_delete_dokumen"; -import funLoadDataInvestasi from "../fun/fun_load_data"; -import { MODEL_INVESTASI } from "../_lib/interface"; -import { IconFile } from "@tabler/icons-react"; -import { IconFileTypePdf } from "@tabler/icons-react"; - -export default function EditDokumenInvestasi({ - dataInvestasi, -}: { - dataInvestasi: MODEL_INVESTASI; -}) { - const [dokumen, setDokumen] = useState(dataInvestasi); - - async function onDelete(id: string) { - await funDeleteDokumenInvestasi(id).then(async (res) => { - if (res.status === 200) { - ComponentGlobal_NotifikasiBerhasil(res.message); - - const load = await funLoadDataInvestasi(dokumen.id); - setDokumen(load as any); - } else { - ComponentGlobal_NotifikasiGagal(res.message); - } - }); - } - - return ( - <> - {!_.isEmpty(dokumen.DokumenInvestasi) ? ( - dokumen.DokumenInvestasi.map((e) => ( - - - {e.title} - - - - - - - { - onDelete(e.id); - }} - > - - - - - - )) - ) : ( - - )} - - {/* */} - - ); -} diff --git a/src/app_modules/investasi/index.ts b/src/app_modules/investasi/index.ts index 96964af3..e5102391 100644 --- a/src/app_modules/investasi/index.ts +++ b/src/app_modules/investasi/index.ts @@ -7,8 +7,6 @@ import PortofolioInvestasi from "./portofolio/view"; import LayoutPortofolioInvestasi from "./portofolio/layout"; import EditIntroInvestasi from "./edit_intro/view"; import LayoutEditIntroInvestasi from "./edit_intro/layout"; -import EditDokumenInvestasi from "./edit_dokumen/view"; -import LayoutEditDokumenInvestasi from "./edit_dokumen/layout"; import EditBeritaInvestasi from "./edit_berita/view"; import LayoutEditBeritaInvestasi from "./edit_berita/layout"; import DetailPropektus from "./detail_prospektus/view"; @@ -56,8 +54,6 @@ export { LayoutPortofolioInvestasi, EditIntroInvestasi, LayoutEditIntroInvestasi, - EditDokumenInvestasi, - LayoutEditDokumenInvestasi, EditBeritaInvestasi, LayoutEditBeritaInvestasi, DetailPropektus, From cb0691c7f28c80259ef04718ee4ebcc3fb8a8213 Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Thu, 16 Jan 2025 12:23:16 +0800 Subject: [PATCH 3/4] chore(release): 1.2.40 --- CHANGELOG.md | 2 ++ package.json | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c54941f0..4f1df440 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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.40](https://github.com/bipproduction/hipmi/compare/v1.2.39...v1.2.40) (2025-01-16) + ## [1.2.39](https://github.com/bipproduction/hipmi/compare/v1.2.38...v1.2.39) (2025-01-12) ## [1.2.38](https://github.com/bipproduction/hipmi/compare/v1.2.37...v1.2.38) (2025-01-03) diff --git a/package.json b/package.json index ded3f924..5b97338f 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,16 @@ { "name": "hipmi", - "version": "1.2.39", + "version": "1.2.40", "private": true, "prisma": { - "seed": "npx tsx prisma/seed.ts --yes" + "seed": "bun prisma/seed.ts" }, "scripts": { - "dev": "bun --bun run next dev --experimental-https", - "build": "NODE_OPTIONS='--max-old-space-size=2048' bun --bun run next build", - "build:dev": "bun --bun run next build", - "start": "bun --bun run next start", - "lint": "bun --bun run next lint", + "dev": "next dev --experimental-https", + "build": "next build", + "build:dev": "next build", + "start": "next start", + "lint": "next lint", "ver": "bunx commit-and-tag-version -- --prerelease" }, "dependencies": { From cdc8ff6d181ad7044884075aaf6ef86fe0a071a7 Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Thu, 16 Jan 2025 12:28:39 +0800 Subject: [PATCH 4/4] fix ( upload & api ) deksripsi: - fix upload image pada berita investasi - fix api berita investasi --- .../api/new/investasi/berita/[id]/route.ts | 85 +++++++++++ src/app/dev/investasi/berita/[id]/page.tsx | 10 +- .../dev/investasi/berita/daftar/[id]/page.tsx | 9 +- .../dev/investasi/berita/rekap/[id]/page.tsx | 12 +- .../dev/investasi/create/berita/[id]/page.tsx | 5 +- src/app/lib/prisma.ts | 4 +- .../fun/delete/fun_delete_file_by_id.tsx | 2 +- .../investasi/_lib/api_interface.ts | 27 ++++ .../investasi/_ui/create/ui_create_berita.tsx | 8 +- .../investasi/_ui/detail/ui_berita.tsx | 98 +++++++++---- .../investasi/_ui/detail/ui_daftar_berita.tsx | 8 +- .../investasi/_ui/detail/ui_rekap_berita.tsx | 57 ++++---- .../_view/create/view_create_berita.tsx | 133 ++++++++---------- .../investasi/_view/detail/view_berita.tsx | 50 +++++-- .../_view/detail/view_daftar_berita.tsx | 113 +++++++++++---- .../_view/detail/view_rekap_berita.tsx | 117 +++++++++++---- src/middleware.ts | 5 +- 17 files changed, 502 insertions(+), 241 deletions(-) create mode 100644 src/app/api/new/investasi/berita/[id]/route.ts diff --git a/src/app/api/new/investasi/berita/[id]/route.ts b/src/app/api/new/investasi/berita/[id]/route.ts new file mode 100644 index 00000000..32fc8fbc --- /dev/null +++ b/src/app/api/new/investasi/berita/[id]/route.ts @@ -0,0 +1,85 @@ +import { prisma } from "@/app/lib"; +import backendLogger from "@/util/backendLogger"; +import { NextResponse } from "next/server"; + +export async function GET( + request: Request, + context: { params: { id: string } } +) { + // if (request.method === "GET") { + // return NextResponse.json( + // { success: false, message: "Method not allowed" }, + // { status: 405 } + // ); + // } + + try { + let fixData; + const { id } = context.params; + const { searchParams } = new URL(request.url); + const kategori: string | null = searchParams.get("kategori"); + const page = searchParams.get("page"); + const takeData = 10; + const skipData = Number(page) * takeData - takeData; + + if (!kategori) { + fixData = await prisma.beritaInvestasi.findFirst({ + where: { + id: id, + }, + include: { + investasi: { + select: { + authorId: true, + }, + }, + }, + }); + } else if (kategori == "get-all") { + fixData = await prisma.beritaInvestasi.findMany({ + take: takeData, + skip: skipData, + orderBy: { + updatedAt: "desc", + }, + where: { + investasiId: id, + active: true, + }, + }); + } + + await prisma.$disconnect(); + + return NextResponse.json( + { success: true, message: "Success get data news", data: fixData }, + { status: 200 } + ); + } catch (error) { + await prisma.$disconnect(); + backendLogger.error("Error get data news", error); + return NextResponse.json( + { + success: false, + message: "Failed to get data, try again later", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} + +async function main({ id }: { id: string }) { + const fixData = await prisma.beritaInvestasi.findMany({ + take: 10, + skip: 0, + orderBy: { + updatedAt: "desc", + }, + where: { + investasiId: id.trim(), + active: true, + }, + }); + console.log("data sebelum disconnect>>", fixData); +} diff --git a/src/app/dev/investasi/berita/[id]/page.tsx b/src/app/dev/investasi/berita/[id]/page.tsx index 6e6e573d..2d0754e5 100644 --- a/src/app/dev/investasi/berita/[id]/page.tsx +++ b/src/app/dev/investasi/berita/[id]/page.tsx @@ -1,12 +1,12 @@ -import { investasi_funGetOneBeritaById } from "@/app_modules/investasi/_fun"; +import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; import { Investasi_UiDetailBerita } from "@/app_modules/investasi/_ui"; -export default async function Page({ params }: { params: { id: string } }) { - const beritaId = params.id; - const dataBerita = await investasi_funGetOneBeritaById({ beritaId }); +export default async function Page() { + const userLoginId = await funGetUserIdByToken(); + return ( <> - + ); } diff --git a/src/app/dev/investasi/berita/daftar/[id]/page.tsx b/src/app/dev/investasi/berita/daftar/[id]/page.tsx index 62d40827..de880b81 100644 --- a/src/app/dev/investasi/berita/daftar/[id]/page.tsx +++ b/src/app/dev/investasi/berita/daftar/[id]/page.tsx @@ -1,14 +1,9 @@ -import { investasi_funGetBeritaById } from "@/app_modules/investasi/_fun"; import { Investasi_UiDaftarBerita } from "@/app_modules/investasi/_ui"; -export default async function Page({ params }: { params: { id: string } }) { - const investasiId = params.id; - const dataBerita = await investasi_funGetBeritaById({ investasiId }); - - +export default async function Page() { return ( <> - + ); } diff --git a/src/app/dev/investasi/berita/rekap/[id]/page.tsx b/src/app/dev/investasi/berita/rekap/[id]/page.tsx index 7075e1b7..bae957ad 100644 --- a/src/app/dev/investasi/berita/rekap/[id]/page.tsx +++ b/src/app/dev/investasi/berita/rekap/[id]/page.tsx @@ -1,17 +1,9 @@ -import { investasi_funGetBeritaById } from "@/app_modules/investasi/_fun"; import { Investasi_UiRekapBerita } from "@/app_modules/investasi/_ui"; -export default async function Page({ params }: { params: { id: string } }) { - const investasiId = params.id; - const dataBerita = await investasi_funGetBeritaById({ investasiId }); - - +export default async function Page() { return ( <> - + ); } diff --git a/src/app/dev/investasi/create/berita/[id]/page.tsx b/src/app/dev/investasi/create/berita/[id]/page.tsx index b4d9a4f6..71683b93 100644 --- a/src/app/dev/investasi/create/berita/[id]/page.tsx +++ b/src/app/dev/investasi/create/berita/[id]/page.tsx @@ -1,10 +1,9 @@ import { Investasi_UiCreateBerita } from "@/app_modules/investasi/_ui"; -export default async function Page({ params }: { params: { id: string } }) { - const investasiId = params.id; +export default async function Page() { return ( <> - + ); } diff --git a/src/app/lib/prisma.ts b/src/app/lib/prisma.ts index bb2d1af0..b3e6e417 100644 --- a/src/app/lib/prisma.ts +++ b/src/app/lib/prisma.ts @@ -21,9 +21,9 @@ if (process.env.NODE_ENV !== "production") { } process.on("SIGINT", async () => { - console.log("Start in Disconnecting PrismaClient..."); + // console.log("Start in Disconnecting PrismaClient..."); const disconnect = await prisma.$disconnect(); - console.log("End of Disconnecting PrismaClient...", disconnect); + // console.log("End of Disconnecting PrismaClient...", disconnect); process.exit(0); }); diff --git a/src/app_modules/_global/fun/delete/fun_delete_file_by_id.tsx b/src/app_modules/_global/fun/delete/fun_delete_file_by_id.tsx index ced99c38..568f3657 100644 --- a/src/app_modules/_global/fun/delete/fun_delete_file_by_id.tsx +++ b/src/app_modules/_global/fun/delete/fun_delete_file_by_id.tsx @@ -10,7 +10,7 @@ export async function funDeteleteFileById({ try { const tokenResponse = await fetch("/api/get-cookie"); if (!tokenResponse.ok) { - throw new Error("Failed to get token"); + return { success: false, message: "Token not found" }; } const { token } = await tokenResponse.json(); diff --git a/src/app_modules/investasi/_lib/api_interface.ts b/src/app_modules/investasi/_lib/api_interface.ts index 1d400aee..63a70b3c 100644 --- a/src/app_modules/investasi/_lib/api_interface.ts +++ b/src/app_modules/investasi/_lib/api_interface.ts @@ -1,3 +1,4 @@ +import { data } from "autoprefixer"; export const apiGetOneInvestasiById = async ({ id }: { id: string }) => { const { token } = await fetch("/api/get-cookie").then((res) => res.json()); if (!token) return await token.json().catch(() => null); @@ -88,3 +89,29 @@ export const apiGetDokumenInvestasiById = async ({ ); return await response.json().catch(() => null); }; + +export const apiGetBeritaInvestasiById = async ({ + id, + kategori, + page, +}: { + id: string; + kategori?: undefined | "get-all"; + page?: string; +}) => { + const { token } = await fetch("/api/get-cookie").then((res) => res.json()); + if (!token) return await token.json().catch(() => null); + + const onCategory = kategori ? `?kategori=${kategori}&page=${page}` : ""; + + const response = await fetch(`/api/new/investasi/berita/${id}${onCategory}`, { + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "Access-Control-Allow-Origin": "*", + Authorization: `Bearer ${token}`, + }, + }); + + return await response.json().catch(() => null); +}; diff --git a/src/app_modules/investasi/_ui/create/ui_create_berita.tsx b/src/app_modules/investasi/_ui/create/ui_create_berita.tsx index 9ae233e7..32288f54 100644 --- a/src/app_modules/investasi/_ui/create/ui_create_berita.tsx +++ b/src/app_modules/investasi/_ui/create/ui_create_berita.tsx @@ -6,17 +6,13 @@ import { } from "@/app_modules/_global/ui"; import { Investasi_ViewCreateBerita } from "../../_view"; -export function Investasi_UiCreateBerita({ - investasiId, -}: { - investasiId: string; -}) { +export function Investasi_UiCreateBerita() { return ( <> } > - + ); diff --git a/src/app_modules/investasi/_ui/detail/ui_berita.tsx b/src/app_modules/investasi/_ui/detail/ui_berita.tsx index 959d27d2..647e88f3 100644 --- a/src/app_modules/investasi/_ui/detail/ui_berita.tsx +++ b/src/app_modules/investasi/_ui/detail/ui_berita.tsx @@ -10,40 +10,82 @@ import { UIGlobal_DrawerCustom, UIGlobal_LayoutHeaderTamplate, UIGlobal_LayoutTamplate, - UIGlobal_Modal + UIGlobal_Modal, } from "@/app_modules/_global/ui"; import { ActionIcon, Button, Center, Stack, Text } from "@mantine/core"; import { IconDotsVertical, IconTrash } from "@tabler/icons-react"; -import { useRouter } from "next/navigation"; +import { useParams, useRouter } from "next/navigation"; import { useState } from "react"; import { investasi_funDeleteBerita } from "../../_fun"; import { Investasi_ViewDetailBerita } from "../../_view"; +import { DIRECTORY_ID } from "@/app/lib"; +import { clientLogger } from "@/util/clientLogger"; +import { useShallowEffect } from "@mantine/hooks"; +import { apiGetBeritaInvestasiById } from "../../_lib/api_interface"; +import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; + +export function Investasi_UiDetailBerita({ + userLoginId, +}: { + userLoginId: string; +}) { + const params = useParams<{ id: string }>(); + const id = params.id; -export function Investasi_UiDetailBerita({ dataBerita }: { dataBerita: any }) { const router = useRouter(); const [openDrawer, setOpenDrawer] = useState(false); const [openModal, setOpenModal] = useState(false); - const [data, setData] = useState(dataBerita); + const [data, setData] = useState(null); + const [isLoading, setLoading] = useState(false); - async function onDelete() { - const del = await investasi_funDeleteBerita({ - beritaId: dataBerita.id, - }); + useShallowEffect(() => { + onLoadData(); + }, []); - if (del.status === 200) { - const deleteImage = await funGlobal_DeleteFileById({ - fileId: data.imageId, + async function onLoadData() { + try { + const respone = await apiGetBeritaInvestasiById({ + id: id, }); - if (!deleteImage.success) { - ComponentGlobal_NotifikasiPeringatan("Gagal hapus gambar "); + if (respone) { + setData(respone.data); } + } catch (error) { + clientLogger.error("Error get detail berita", error); + } + } - ComponentGlobal_NotifikasiBerhasil(del.message); - setOpenModal(false); - router.back(); - } else { - ComponentGlobal_NotifikasiGagal(del.message); + async function onDelete() { + try { + setLoading(true); + const del = await investasi_funDeleteBerita({ + beritaId: id, + }); + + if (del.status === 200) { + if (data.imageId != null) { + const deleteImage = await funGlobal_DeleteFileById({ + fileId: data.imageId, + dirId: DIRECTORY_ID.investasi_berita, + }); + + if (!deleteImage.success) { + setLoading(false); + ComponentGlobal_NotifikasiPeringatan("Gagal hapus gambar "); + } + } + + router.back(); + ComponentGlobal_NotifikasiBerhasil(del.message); + setOpenModal(false); + } else { + setLoading(false); + ComponentGlobal_NotifikasiGagal(del.message); + } + } catch (error) { + setLoading(false); + clientLogger.error("Error delete berita", error); } } @@ -54,17 +96,21 @@ export function Investasi_UiDetailBerita({ dataBerita }: { dataBerita: any }) { setOpenDrawer(true)} - > - - + data && userLoginId === data.investasi.authorId ? ( + setOpenDrawer(true)} + > + + + ) : ( + "" + ) } /> } > - + { diff --git a/src/app_modules/investasi/_ui/detail/ui_daftar_berita.tsx b/src/app_modules/investasi/_ui/detail/ui_daftar_berita.tsx index 350bcaf6..2d15ed34 100644 --- a/src/app_modules/investasi/_ui/detail/ui_daftar_berita.tsx +++ b/src/app_modules/investasi/_ui/detail/ui_daftar_berita.tsx @@ -6,16 +6,12 @@ import { } from "@/app_modules/_global/ui"; import { Investasi_ViewDaftarBerita } from "../../_view"; -export function Investasi_UiDaftarBerita({ - dataBerita, -}: { - dataBerita: any[]; -}) { +export function Investasi_UiDaftarBerita() { return ( } > - + ); } diff --git a/src/app_modules/investasi/_ui/detail/ui_rekap_berita.tsx b/src/app_modules/investasi/_ui/detail/ui_rekap_berita.tsx index 5bad3146..3e9c3691 100644 --- a/src/app_modules/investasi/_ui/detail/ui_rekap_berita.tsx +++ b/src/app_modules/investasi/_ui/detail/ui_rekap_berita.tsx @@ -1,5 +1,6 @@ "use client"; +import { NEW_RouterInvestasi } from "@/app/lib/router_hipmi/router_investasi"; import { UIGlobal_Drawer, UIGlobal_LayoutHeaderTamplate, @@ -7,19 +8,13 @@ import { } from "@/app_modules/_global/ui"; import { ActionIcon } from "@mantine/core"; import { IconCirclePlus, IconDotsVertical } from "@tabler/icons-react"; -import { useRouter } from "next/navigation"; +import { useParams } from "next/navigation"; import { useState } from "react"; import { Investasi_ViewRekapBerita } from "../../_view"; -import { NEW_RouterInvestasi } from "@/app/lib/router_hipmi/router_investasi"; -export function Investasi_UiRekapBerita({ - investasiId, - dataBerita, -}: { - investasiId: string; - dataBerita: any[] -}) { - const router = useRouter(); +export function Investasi_UiRekapBerita() { + const params = useParams<{ id: string }>(); + const investasiId = params.id; const [openDrawer, setOpenDrawer] = useState(false); const listPage = [ @@ -32,32 +27,32 @@ export function Investasi_UiRekapBerita({ ]; return ( - { - setOpenDrawer(true); - }} - > - - - } - /> - } - > - - - + <> + { + setOpenDrawer(true); + }} + > + + + } + /> + } + > + + setOpenDrawer(false)} component={listPage} /> - + ); } diff --git a/src/app_modules/investasi/_view/create/view_create_berita.tsx b/src/app_modules/investasi/_view/create/view_create_berita.tsx index 1b5067d2..0ed7eb7a 100644 --- a/src/app_modules/investasi/_view/create/view_create_berita.tsx +++ b/src/app_modules/investasi/_view/create/view_create_berita.tsx @@ -1,39 +1,37 @@ -import { AccentColor, MainColor } from "@/app_modules/_global/color"; -import { - ComponentGlobal_BoxInformation, - ComponentGlobal_BoxUploadImage, - ComponentGlobal_InputCountDown, -} from "@/app_modules/_global/component"; -import { - ComponentGlobal_NotifikasiBerhasil, - ComponentGlobal_NotifikasiGagal, - ComponentGlobal_NotifikasiPeringatan, -} from "@/app_modules/_global/notif_global"; -import { - AspectRatio, - Button, - Center, - FileButton, - Image, - Stack, - Text, - TextInput, - Textarea, -} from "@mantine/core"; -import { IconCamera, IconUpload } from "@tabler/icons-react"; - import { DIRECTORY_ID } from "@/app/lib"; +import { MainColor } from "@/app_modules/_global/color"; +import { + ComponentGlobal_BoxInformation, + ComponentGlobal_BoxUploadImage, + ComponentGlobal_ButtonUploadFileImage, + ComponentGlobal_InputCountDown, +} from "@/app_modules/_global/component"; import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun"; +import { + ComponentGlobal_NotifikasiBerhasil, + ComponentGlobal_NotifikasiGagal, + ComponentGlobal_NotifikasiPeringatan, +} from "@/app_modules/_global/notif_global"; +import { clientLogger } from "@/util/clientLogger"; +import { + AspectRatio, + Button, + Center, + Image, + Stack, + TextInput, + Textarea, +} from "@mantine/core"; import { Prisma } from "@prisma/client"; -import { useRouter } from "next/navigation"; +import { IconPhoto } from "@tabler/icons-react"; +import { useParams, useRouter } from "next/navigation"; import { useState } from "react"; import { investasi_funCreateBerita } from "../../_fun"; -export function Investasi_ViewCreateBerita({ - investasiId, -}: { - investasiId: string; -}) { +export function Investasi_ViewCreateBerita() { + const params = useParams<{ id: string }>(); + const investasiId = params.id; + const router = useRouter(); const [file, setFile] = useState(null); const [img, setImg] = useState(); @@ -48,9 +46,6 @@ export function Investasi_ViewCreateBerita({ }); async function onCreate() { - if (data.data.title == "" || data.data.deskripsi == "") - return ComponentGlobal_NotifikasiPeringatan("Lengkapi data"); - try { setIsLoading(true); if (file != null) { @@ -59,32 +54,39 @@ export function Investasi_ViewCreateBerita({ dirId: DIRECTORY_ID.investasi_berita, }); - if (!uploadFile.success) - return ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar"); + if (!uploadFile.success) { + ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar"); + return; + } const createWithFile = await investasi_funCreateBerita({ data: data.data as any, fileId: uploadFile.data.id, }); - createWithFile.status === 201 - ? (ComponentGlobal_NotifikasiBerhasil(createWithFile.message), - router.back()) - : ComponentGlobal_NotifikasiGagal(createWithFile.message); + if (createWithFile.status === 201) { + ComponentGlobal_NotifikasiBerhasil(createWithFile.message); + router.back(); + } else { + setIsLoading(false); + ComponentGlobal_NotifikasiGagal(createWithFile.message); + } } else { const createNoFile = await investasi_funCreateBerita({ data: data.data as any, }); - createNoFile.status === 201 - ? (ComponentGlobal_NotifikasiBerhasil(createNoFile.message), - router.back()) - : ComponentGlobal_NotifikasiGagal(createNoFile.message); + if (createNoFile.status === 201) { + ComponentGlobal_NotifikasiBerhasil(createNoFile.message); + router.back(); + } else { + setIsLoading(false); + ComponentGlobal_NotifikasiGagal(createNoFile.message); + } } } catch (error) { - console.log(error); - } finally { setIsLoading(false); + clientLogger.error("Error create news", error); } } @@ -106,43 +108,16 @@ export function Investasi_ViewCreateBerita({ ) : ( - - - Upload Gambar - + )}
- { - 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) => ( - - )} - +
@@ -187,6 +162,10 @@ export function Investasi_ViewCreateBerita({