Fix some bugs - continue

This commit is contained in:
Anthony Janin 2025-06-26 16:18:00 +02:00
parent d7e27bbb9a
commit f9abdd31cd
4 changed files with 98 additions and 22 deletions

View File

@ -5,10 +5,12 @@ import { useCallback, useMemo, useState } from "react";
import classes from "./classes.module.scss"; import classes from "./classes.module.scss";
import Files from "@Front/Api/LeCoffreApi/Customer/Files/Files"; import Files from "@Front/Api/LeCoffreApi/Customer/Files/Files";
import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document";
import { ToasterService } from "@Front/Components/DesignSystem/Toaster"; import { ToasterService } from "@Front/Components/DesignSystem/Toaster";
import Confirm from "@Front/Components/DesignSystem/OldModal/Confirm"; import Confirm from "@Front/Components/DesignSystem/OldModal/Confirm";
import FileService from "src/common/Api/LeCoffreApi/sdk/FileService"; import FileService from "src/common/Api/LeCoffreApi/sdk/FileService";
import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService";
type IProps = { type IProps = {
document: Document; document: Document;
@ -59,15 +61,21 @@ export default function DepositDocumentComponent(props: IProps) {
const fileData = { const fileData = {
document: { document: {
uid: document.uid uid: document.uid!
}, },
file: fileBlob, fileBlob: fileBlob,
file_name: file.name, file_name: file.name,
mimetype: file.type mimetype: file.type
} }
const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0'; const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0';
FileService.createFile(fileData, validatorId).then(() => resolve()); FileService.createFile(fileData, validatorId).then(() => {
DocumentService.getDocumentByUid(document.uid!).then((process: any) => {
if (process) {
DocumentService.updateDocument(process, { document_status: EDocumentStatus.DEPOSITED }).then(() => resolve());
}
});
});
} }
}; };
reader.readAsArrayBuffer(file); reader.readAsArrayBuffer(file);

View File

@ -42,7 +42,6 @@ export default function ClientDashboard(props: IProps) {
const [customer, setCustomer] = useState<Customer | null>(null); const [customer, setCustomer] = useState<Customer | null>(null);
const [folder, setFolder] = useState<OfficeFolderNotary | null>(null); const [folder, setFolder] = useState<OfficeFolderNotary | null>(null);
const [file, setFile] = useState<any | null>(null);
const [documentsNotary, setDocumentsNotary] = useState<DocumentNotary[]>([]); const [documentsNotary, setDocumentsNotary] = useState<DocumentNotary[]>([]);
const [isAddDocumentModalVisible, setIsAddDocumentModalVisible] = useState<boolean>(false); const [isAddDocumentModalVisible, setIsAddDocumentModalVisible] = useState<boolean>(false);
@ -96,11 +95,8 @@ export default function ClientDashboard(props: IProps) {
setCustomer(customer); setCustomer(customer);
setFolder(folder); setFolder(folder);
setFile(file);
if (!file) { setIsAuthModalOpen(true);
setIsAuthModalOpen(true);
}
return { folder, customer }; return { folder, customer };
@ -178,6 +174,8 @@ export default function ClientDashboard(props: IProps) {
.map((p: any) => p.processData) .map((p: any) => p.processData)
.filter((file: any) => file.isDeleted === 'false'); .filter((file: any) => file.isDeleted === 'false');
// TODO: review - customerUid
for (const document of documents) { for (const document of documents) {
const p: any = await DocumentTypeService.getDocumentTypeByUid(document.document_type.uid); const p: any = await DocumentTypeService.getDocumentTypeByUid(document.document_type.uid);
document.document_type = p.processData; document.document_type = p.processData;
@ -224,6 +222,7 @@ export default function ClientDashboard(props: IProps) {
setIsAddDocumentModalVisible(true); setIsAddDocumentModalVisible(true);
}, []); }, []);
/*
const onDownloadFile = useCallback(() => { const onDownloadFile = useCallback(() => {
if (!file) { if (!file) {
return; return;
@ -238,6 +237,7 @@ export default function ClientDashboard(props: IProps) {
document.body.removeChild(a); document.body.removeChild(a);
URL.revokeObjectURL(url); URL.revokeObjectURL(url);
}, [file]); }, [file]);
*/
const renderBox = useCallback(() => { const renderBox = useCallback(() => {
return ( return (
@ -267,6 +267,8 @@ export default function ClientDashboard(props: IProps) {
<Typography typo={ETypo.TITLE_H4} color={ETypoColor.TEXT_PRIMARY}> <Typography typo={ETypo.TITLE_H4} color={ETypoColor.TEXT_PRIMARY}>
Bonjour {customer?.contact?.first_name.concat(" ", customer?.contact?.last_name)} Bonjour {customer?.contact?.first_name.concat(" ", customer?.contact?.last_name)}
</Typography> </Typography>
{/*
{file && ( {file && (
<Button <Button
variant={EButtonVariant.SECONDARY} variant={EButtonVariant.SECONDARY}
@ -276,6 +278,7 @@ export default function ClientDashboard(props: IProps) {
Télécharger le document Télécharger le document
</Button> </Button>
)} )}
*/}
<Tag color={ETagColor.INFO} label={folder?.deed?.deed_type?.name ?? ""} /> <Tag color={ETagColor.INFO} label={folder?.deed?.deed_type?.name ?? ""} />
<div className={classes["office-container"]}> <div className={classes["office-container"]}>

View File

@ -19,6 +19,10 @@ import Files from "@Front/Api/LeCoffreApi/Notary/Files/Files";
import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField"; import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField";
import MessageBox from "@Front/Components/Elements/MessageBox"; import MessageBox from "@Front/Components/Elements/MessageBox";
import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService";
import FileService from "src/common/Api/LeCoffreApi/sdk/FileService";
import MessageBus from "src/sdk/MessageBus";
type IProps = {}; type IProps = {};
type IPropsClass = { type IPropsClass = {
documentUid: string; documentUid: string;
@ -31,7 +35,7 @@ type IState = {
isValidateModalVisible: boolean; isValidateModalVisible: boolean;
refuseText: string; refuseText: string;
selectedFileIndex: number; selectedFileIndex: number;
selectedFile: File | null; selectedFile: any; // File | null; TODO: review
validatedPercentage: number; validatedPercentage: number;
document: Document | null; document: Document | null;
fileBlob: Blob | null; fileBlob: Blob | null;
@ -90,9 +94,9 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
)} )}
<div className={classes["file-container"]}> <div className={classes["file-container"]}>
{this.state.selectedFile.mimetype === "application/pdf" || {this.state.selectedFile.mimetype === "application/pdf" ||
this.state.selectedFile.mimetype === "image/jpeg" || this.state.selectedFile.mimetype === "image/jpeg" ||
this.state.selectedFile.mimetype === "image/png" || this.state.selectedFile.mimetype === "image/png" ||
this.state.selectedFile.mimetype === "image/jpg" ? ( this.state.selectedFile.mimetype === "image/jpg" ? (
<FilePreview <FilePreview
href={this.state.fileBlob ? URL.createObjectURL(this.state.fileBlob) : ""} href={this.state.fileBlob ? URL.createObjectURL(this.state.fileBlob) : ""}
fileName={this.state.selectedFile.file_name} fileName={this.state.selectedFile.file_name}
@ -141,7 +145,7 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
</> </>
)} )}
{this.state.document?.document_status === "VALIDATED" && this.state.fileBlob && ( {this.state.document?.document_status === "VALIDATED" && this.state.fileBlob && (
<Button onClick={this.downloadFile}>Télécharger</Button> <Button onClick={this.downloadFile}>Télécharger</Button>
)} )}
</div> </div>
</div> </div>
@ -197,6 +201,7 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
override async componentDidMount() { override async componentDidMount() {
try { try {
/* TODO: review
const document = await Documents.getInstance().getByUid(this.props.documentUid, { const document = await Documents.getInstance().getByUid(this.props.documentUid, {
files: { files: {
where: { archived_at: null }, where: { archived_at: null },
@ -205,6 +210,29 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
folder: true, folder: true,
depositor: true, depositor: true,
}); });
*/
const document: any = await new Promise((resolve: (document: any) => void) => {
DocumentService.getDocumentByUid(this.props.documentUid).then(async (process: any) => {
if (process) {
const document: any = process.processData;
const processes: any[] = await MessageBus.getInstance().getFiles();
const process1: any = processes.find((process: any) => process.processData.document.get('uid') === document.uid);
/*
const files: any[] = (await FileService.getFiles())
.map((p: any) => p.processData)
.filter((file: any) => file.isDeleted === 'false');
*/
document.files = [process1.processData];
resolve(document);
}
});
});
this.setState( this.setState(
{ {
document, document,
@ -226,7 +254,11 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
private async getFilePreview(): Promise<void> { private async getFilePreview(): Promise<void> {
try { try {
const fileBlob: Blob = await Files.getInstance().download(this.state.selectedFile?.uid as string); // TODO: review
const file: any = this.state.selectedFile.fileBlob;
const fileBlob: Blob = new Blob([file.data], { type: file.type });
//const fileBlob: Blob = await Files.getInstance().download(this.state.selectedFile?.uid as string);
this.setState({ this.setState({
fileBlob, fileBlob,
@ -236,6 +268,24 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
} }
} }
private downloadFile() {
// TODO: review
//if (!this.state.fileBlob) return;
const file: any = this.state.selectedFile.fileBlob;
const blob = new Blob([file.data], { type: file.type });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = this.state.selectedFile.file_name;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
/* TODO: review
private downloadFile() { private downloadFile() {
if (!this.state.fileBlob) return; if (!this.state.fileBlob) return;
const url = window.URL.createObjectURL(this.state.fileBlob); const url = window.URL.createObjectURL(this.state.fileBlob);
@ -248,6 +298,7 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
a.click(); a.click();
window.URL.revokeObjectURL(url); window.URL.revokeObjectURL(url);
} }
*/
private getRandomPercentageForOcr() { private getRandomPercentageForOcr() {
// find diff // find diff
@ -315,8 +366,8 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
Module.getInstance() Module.getInstance()
.get() .get()
.modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.folderUid) + .modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.folderUid) +
"?customerUid=" + "?customerUid=" +
this.state.document?.depositor?.uid, this.state.document?.depositor?.uid,
); );
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@ -333,8 +384,8 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
Module.getInstance() Module.getInstance()
.get() .get()
.modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.folderUid) + .modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.folderUid) +
"?customerUid=" + "?customerUid=" +
this.state.document?.depositor?.uid, this.state.document?.depositor?.uid,
); );
} catch (e) { } catch (e) {
console.error(e); console.error(e);

View File

@ -194,11 +194,25 @@ export default class MessageBus {
continue; continue;
} }
const isFile: boolean = process.states const publicDataDecoded: { [key: string]: any } = {};
.map((state: any) => state.keys)
.filter((keys: any) => keys['uid'] && keys['utype_ff']).length > 0;
if (!isFile) { for (let stateId = 0; stateId < process.states.length - 1; stateId++) {
const state = process.states[stateId];
if (!state) {
continue;
}
const publicDataEncoded = state.public_data;
if (!publicDataEncoded) {
continue;
}
for (const key of Object.keys(publicDataEncoded)) {
publicDataDecoded[key] = await this.getPublicData(publicDataEncoded[key]);
}
}
if (publicDataDecoded['utype'] !== 'file') {
continue; continue;
} }