Fixes
This commit is contained in:
parent
5c5c13c620
commit
f5195f5c0a
@ -59,12 +59,13 @@ export default class DepositRib extends React.Component<IProps, IState> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
handleFile = (file: File) => {
|
handleFile = (file: File) => {
|
||||||
|
if (!file) return;
|
||||||
if (file.type === "application/pdf" || file.type === "image/jpeg" || file.type === "image/png") {
|
if (file.type === "application/pdf" || file.type === "image/jpeg" || file.type === "image/png") {
|
||||||
this.setState((prevState) => ({
|
this.setState({
|
||||||
documents: [...prevState.documents, file],
|
documents: [file],
|
||||||
errorMessage: "",
|
errorMessage: "",
|
||||||
}));
|
});
|
||||||
this.props.onChange([...this.state.documents, file]);
|
this.props.onChange([file]);
|
||||||
} else {
|
} else {
|
||||||
this.setState({ errorMessage: "Only PDF, JPEG, and PNG files are allowed." });
|
this.setState({ errorMessage: "Only PDF, JPEG, and PNG files are allowed." });
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useCallback, useEffect, useState } from "react";
|
||||||
import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography";
|
import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography";
|
||||||
import classes from "./classes.module.scss";
|
import classes from "./classes.module.scss";
|
||||||
import DefaultTemplate from "@Front/Components/LayoutTemplates/DefaultTemplate";
|
import DefaultTemplate from "@Front/Components/LayoutTemplates/DefaultTemplate";
|
||||||
@ -17,29 +17,32 @@ export default function Rib() {
|
|||||||
const [fileName, setFileName] = useState<string>("");
|
const [fileName, setFileName] = useState<string>("");
|
||||||
const [key, setKey] = useState<string>("");
|
const [key, setKey] = useState<string>("");
|
||||||
const [isRibModalOpen, setIsRibModalOpen] = useState<boolean>(false);
|
const [isRibModalOpen, setIsRibModalOpen] = useState<boolean>(false);
|
||||||
|
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState<boolean>(false);
|
||||||
|
|
||||||
|
//Put fetch data in a useCallback
|
||||||
|
|
||||||
|
const fetchData = useCallback(async () => {
|
||||||
|
console.log("fetchData", officeUid);
|
||||||
|
|
||||||
const fetchData = async () => {
|
|
||||||
if (!officeUid) return;
|
if (!officeUid) return;
|
||||||
const blob = await Bucket.getInstance().getRibStream(officeUid as string);
|
try {
|
||||||
|
const blob = await Bucket.getInstance().getRibStream(officeUid as string);
|
||||||
|
|
||||||
if (!blob) {
|
const ribUrl = URL.createObjectURL(blob);
|
||||||
|
|
||||||
|
setFileUrl(ribUrl);
|
||||||
|
setKey(key);
|
||||||
|
setFileName(key);
|
||||||
|
} catch (error) {
|
||||||
setFileUrl("");
|
setFileUrl("");
|
||||||
setFileName("");
|
setFileName("");
|
||||||
setKey("");
|
setKey("");
|
||||||
}
|
}
|
||||||
const ribUrl = URL.createObjectURL(blob);
|
}, [officeUid]);
|
||||||
|
|
||||||
setFileUrl(ribUrl);
|
useEffect(() => {
|
||||||
setKey(key);
|
|
||||||
setFileName(key);
|
|
||||||
};
|
|
||||||
|
|
||||||
async function deleteFile() {
|
|
||||||
if (!officeUid) return;
|
|
||||||
await Bucket.getInstance().delete(officeUid as string);
|
|
||||||
setDocumentList([]);
|
|
||||||
fetchData();
|
fetchData();
|
||||||
}
|
}, [officeUid]);
|
||||||
|
|
||||||
function downloadFile() {
|
function downloadFile() {
|
||||||
if (!fileUrl) return;
|
if (!fileUrl) return;
|
||||||
@ -59,18 +62,34 @@ export default function Rib() {
|
|||||||
|
|
||||||
await Bucket.getInstance().post(formData);
|
await Bucket.getInstance().post(formData);
|
||||||
|
|
||||||
setDocumentList([]);
|
onCloseRibModal();
|
||||||
setIsRibModalOpen(false);
|
|
||||||
fetchData();
|
fetchData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function openRibModal(): void {
|
||||||
|
setIsRibModalOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
function onCloseRibModal(): void {
|
function onCloseRibModal(): void {
|
||||||
setDocumentList([]);
|
setDocumentList([]);
|
||||||
setIsRibModalOpen(false);
|
setIsRibModalOpen(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
function openRibModal(): void {
|
async function onDeleteModalAccepted() {
|
||||||
setIsRibModalOpen(true);
|
if (!officeUid) return;
|
||||||
|
const office = await Bucket.getInstance().delete(officeUid as string);
|
||||||
|
console.log(office);
|
||||||
|
|
||||||
|
onCloseDeleteModal();
|
||||||
|
fetchData();
|
||||||
|
}
|
||||||
|
|
||||||
|
function openDeleteModal(): void {
|
||||||
|
setIsDeleteModalOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onCloseDeleteModal(): void {
|
||||||
|
setIsDeleteModalOpen(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
const onDocumentChange = (documentList: File[]) => {
|
const onDocumentChange = (documentList: File[]) => {
|
||||||
@ -103,7 +122,7 @@ export default function Rib() {
|
|||||||
<div className={classes["document-container"]}>
|
<div className={classes["document-container"]}>
|
||||||
<div className={classes["file-container"]}>{fileUrl && <FilePreview href={fileUrl} fileName={fileName} />}</div>
|
<div className={classes["file-container"]}>{fileUrl && <FilePreview href={fileUrl} fileName={fileName} />}</div>
|
||||||
<div className={classes["footer"]}>
|
<div className={classes["footer"]}>
|
||||||
<Button onClick={deleteFile} variant={EButtonVariant.SECONDARY}>
|
<Button onClick={openDeleteModal} variant={EButtonVariant.SECONDARY}>
|
||||||
Supprimer
|
Supprimer
|
||||||
</Button>
|
</Button>
|
||||||
<Button onClick={openRibModal} variant={EButtonVariant.GHOST}>
|
<Button onClick={openRibModal} variant={EButtonVariant.GHOST}>
|
||||||
@ -124,12 +143,20 @@ export default function Rib() {
|
|||||||
<DepositRib onChange={onDocumentChange} />
|
<DepositRib onChange={onDocumentChange} />
|
||||||
</Confirm>
|
</Confirm>
|
||||||
|
|
||||||
{/* <div className={classes["footer"]}>
|
<Confirm
|
||||||
<DepositRib />
|
isOpen={isDeleteModalOpen}
|
||||||
<Button variant={EButtonVariant.SECONDARY}>Supprimer</Button>
|
onAccept={onDeleteModalAccepted}
|
||||||
<Button variant={EButtonVariant.GHOST}>Modifier</Button>
|
onClose={onCloseDeleteModal}
|
||||||
<Button onClick={downloadFile}>Télécharger</Button>
|
closeBtn
|
||||||
</div> */}
|
cancelText={"Annuler"}
|
||||||
|
confirmText={"Supprimer"}>
|
||||||
|
<Typography typo={ITypo.H1} color={ITypoColor.BLACK} className={classes["title"]}>
|
||||||
|
Supprimer le RIB
|
||||||
|
</Typography>
|
||||||
|
<Typography typo={ITypo.P_18} color={ITypoColor.GREY}>
|
||||||
|
Voulez-vous vraiment supprimer le RIB de votre office ?
|
||||||
|
</Typography>
|
||||||
|
</Confirm>
|
||||||
</div>
|
</div>
|
||||||
</DefaultTemplate>
|
</DefaultTemplate>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user