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

fix file view investasi
This commit is contained in:
Bagasbanuna02
2025-03-04 12:18:33 +08:00
committed by GitHub
3 changed files with 90 additions and 12 deletions

View File

@@ -0,0 +1,74 @@
"use client";
import { AccentColor, MainColor } from "@/app_modules/_global/color";
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global";
import { clientLogger } from "@/util/clientLogger";
import { Button, FileButton } from "@mantine/core";
import { IconUpload } from "@tabler/icons-react";
import { useState } from "react";
export function Investasi_ComponentButtonUploadFile({
onSetFile,
onSetImage,
text,
icon,
}: {
onSetFile: File | null | any;
onSetImage?: any | null;
text?: string;
icon?: string | any;
}) {
const [isLoading, setIsLoading] = useState(false);
return (
<FileButton
onChange={async (files: any | null) => {
try {
setIsLoading(true);
const buffer = URL.createObjectURL(
new Blob([new Uint8Array(await files.arrayBuffer())])
);
console.log("files", files);
if (files.size > 100 * 1024 * 1024) {
setIsLoading(false);
ComponentGlobal_NotifikasiPeringatan("File terlalu besar");
return;
}
if (files.type !== "application/pdf") {
setIsLoading(false);
ComponentGlobal_NotifikasiPeringatan("Tipe file bukan PDF");
return;
}
onSetFile(files);
onSetImage(buffer);
} catch (error) {
clientLogger.error("Upload image error:", error);
} finally {
setIsLoading(false);
}
}}
accept={"application/pdf"}
>
{(props) => (
<Button
{...props}
loading={isLoading}
loaderPosition="center"
radius={"xl"}
style={{
backgroundColor: MainColor.yellow,
border: `1px solid ${AccentColor.yellow}`,
}}
leftIcon={icon ? icon : <IconUpload color="black" size={20} />}
c={MainColor.darkblue}
>
{text ? text : "Upload"}
</Button>
)}
</FileButton>
);
}

View File

@@ -73,14 +73,18 @@ export function Investasi_UiFileViewProspektus() {
title="Pratinjau Prospektus"
iconLeft={<IconX />}
customButtonRight={
<ActionIcon
variant="transparent"
onClick={() => {
setOpen(true);
}}
>
<IconDotsVertical color="white" />
</ActionIcon>
error && error !== "" ? (
<ActionIcon disabled />
) : (
<ActionIcon
variant="transparent"
onClick={() => {
setOpen(true);
}}
>
<IconDotsVertical color="white" />
</ActionIcon>
)
}
/>
}
@@ -88,10 +92,10 @@ export function Investasi_UiFileViewProspektus() {
<Box mb="lg">
{loading ? (
<CustomSkeleton height={"80vh"} width={"100%"} />
) : error ? (
) : error && error !== "" ? (
<Stack>
<ComponentGlobal_IsEmptyData text="Maaf, PDF mengalami error" />
<ComponentGlobal_IsEmptyData text={error} />
{/* <ComponentGlobal_IsEmptyData text={error} /> */}
</Stack>
) : (
<div

View File

@@ -28,6 +28,7 @@ import _ from "lodash";
import { useState } from "react";
import { Investasi_ComponentButtonCreateNewInvestasi } from "../_component";
import { apiGetMasterInvestasi } from "../_lib/api_interface";
import { Investasi_ComponentButtonUploadFile } from "../_component/button/comp_button_upload_file_prospektus";
export default function InvestasiCreateNew() {
const [loadingMasterInvestor, setLoadingMasterInvestor] = useState(true);
@@ -188,10 +189,9 @@ export default function InvestasiCreateNew() {
</ComponentGlobal_CardStyles>
<Center>
<ComponentGlobal_ButtonUploadFileImage
<Investasi_ComponentButtonUploadFile
onSetFile={setFilePdf}
onSetImage={setFPdf}
accept={"application/pdf"}
text="Upload File"
icon={<IconFileTypePdf size={20} />}
/>