Merge pull request #356 from bipproduction/bagas/4-mar-25
fix file view investasi
This commit is contained in:
@@ -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>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -73,14 +73,18 @@ export function Investasi_UiFileViewProspektus() {
|
|||||||
title="Pratinjau Prospektus"
|
title="Pratinjau Prospektus"
|
||||||
iconLeft={<IconX />}
|
iconLeft={<IconX />}
|
||||||
customButtonRight={
|
customButtonRight={
|
||||||
<ActionIcon
|
error && error !== "" ? (
|
||||||
variant="transparent"
|
<ActionIcon disabled />
|
||||||
onClick={() => {
|
) : (
|
||||||
setOpen(true);
|
<ActionIcon
|
||||||
}}
|
variant="transparent"
|
||||||
>
|
onClick={() => {
|
||||||
<IconDotsVertical color="white" />
|
setOpen(true);
|
||||||
</ActionIcon>
|
}}
|
||||||
|
>
|
||||||
|
<IconDotsVertical color="white" />
|
||||||
|
</ActionIcon>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
@@ -88,10 +92,10 @@ export function Investasi_UiFileViewProspektus() {
|
|||||||
<Box mb="lg">
|
<Box mb="lg">
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<CustomSkeleton height={"80vh"} width={"100%"} />
|
<CustomSkeleton height={"80vh"} width={"100%"} />
|
||||||
) : error ? (
|
) : error && error !== "" ? (
|
||||||
<Stack>
|
<Stack>
|
||||||
<ComponentGlobal_IsEmptyData text="Maaf, PDF mengalami error" />
|
<ComponentGlobal_IsEmptyData text="Maaf, PDF mengalami error" />
|
||||||
<ComponentGlobal_IsEmptyData text={error} />
|
{/* <ComponentGlobal_IsEmptyData text={error} /> */}
|
||||||
</Stack>
|
</Stack>
|
||||||
) : (
|
) : (
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import _ from "lodash";
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Investasi_ComponentButtonCreateNewInvestasi } from "../_component";
|
import { Investasi_ComponentButtonCreateNewInvestasi } from "../_component";
|
||||||
import { apiGetMasterInvestasi } from "../_lib/api_interface";
|
import { apiGetMasterInvestasi } from "../_lib/api_interface";
|
||||||
|
import { Investasi_ComponentButtonUploadFile } from "../_component/button/comp_button_upload_file_prospektus";
|
||||||
|
|
||||||
export default function InvestasiCreateNew() {
|
export default function InvestasiCreateNew() {
|
||||||
const [loadingMasterInvestor, setLoadingMasterInvestor] = useState(true);
|
const [loadingMasterInvestor, setLoadingMasterInvestor] = useState(true);
|
||||||
@@ -188,10 +189,9 @@ export default function InvestasiCreateNew() {
|
|||||||
</ComponentGlobal_CardStyles>
|
</ComponentGlobal_CardStyles>
|
||||||
|
|
||||||
<Center>
|
<Center>
|
||||||
<ComponentGlobal_ButtonUploadFileImage
|
<Investasi_ComponentButtonUploadFile
|
||||||
onSetFile={setFilePdf}
|
onSetFile={setFilePdf}
|
||||||
onSetImage={setFPdf}
|
onSetImage={setFPdf}
|
||||||
accept={"application/pdf"}
|
|
||||||
text="Upload File"
|
text="Upload File"
|
||||||
icon={<IconFileTypePdf size={20} />}
|
icon={<IconFileTypePdf size={20} />}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user