Use FileBlob and FileData everywhere
This commit is contained in:
parent
f46dae8954
commit
1fc9f1e73c
@ -2,6 +2,7 @@ import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import MessageBus from 'src/sdk/MessageBus';
|
||||
import User from 'src/sdk/User';
|
||||
import { FileData } from '../../../../front/Api/Entities/types';
|
||||
|
||||
export default class FileService {
|
||||
|
||||
@ -9,7 +10,7 @@ export default class FileService {
|
||||
|
||||
private constructor() { }
|
||||
|
||||
public static createFile(fileData: any, validatorId: string): Promise<any> {
|
||||
public static createFile(fileData: FileData, validatorId: string): Promise<any> {
|
||||
const ownerId = User.getInstance().getPairingId()!;
|
||||
|
||||
const processData: any = {
|
||||
@ -81,7 +82,7 @@ export default class FileService {
|
||||
return this.messageBus.getFileByUid(uid);
|
||||
}
|
||||
|
||||
public static updateFile(process: any, newData: any): Promise<void> {
|
||||
public static updateFile(process: any, newData: Partial<FileData> & { isDeleted?: string }): Promise<void> {
|
||||
return new Promise<void>((resolve: () => void, reject: (error: string) => void) => {
|
||||
this.messageBus.updateProcess(process.processId, { updated_at: new Date().toISOString(), ...newData }, [], null).then((processUpdated: any) => {
|
||||
const newStateId: string = processUpdated.diffs[0]?.state_id;
|
||||
|
2
src/front/Api/Entities/index.ts
Normal file
2
src/front/Api/Entities/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './types';
|
||||
export * from './rule';
|
@ -9,6 +9,7 @@ import Confirm from "@Front/Components/DesignSystem/OldModal/Confirm";
|
||||
|
||||
import FileService from "src/common/Api/LeCoffreApi/sdk/FileService";
|
||||
import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService";
|
||||
import { FileBlob, FileData } from "@Front/Api/Entities/types";
|
||||
|
||||
type IProps = {
|
||||
document: any;
|
||||
@ -39,12 +40,12 @@ export default function DepositDocumentComponent(props: IProps) {
|
||||
const arrayBuffer = event.target.result as ArrayBuffer;
|
||||
const uint8Array = new Uint8Array(arrayBuffer);
|
||||
|
||||
const fileBlob: any = {
|
||||
const fileBlob: FileBlob = {
|
||||
type: file.type,
|
||||
data: uint8Array
|
||||
};
|
||||
|
||||
const fileData: any = {
|
||||
const fileData: FileData = {
|
||||
file_blob: fileBlob,
|
||||
file_name: file.name
|
||||
};
|
||||
|
@ -7,6 +7,7 @@ import { DocumentNotary } from "le-coffre-resources/dist/Notary";
|
||||
import Image from "next/image";
|
||||
import { NextRouter, useRouter } from "next/router";
|
||||
import React from "react";
|
||||
import { FileBlob } from "@Front/Api/Entities/types";
|
||||
|
||||
import BasePage from "../../Base";
|
||||
import classes from "./classes.module.scss";
|
||||
@ -25,7 +26,7 @@ type IState = {
|
||||
isValidateModalVisible: boolean;
|
||||
refuseText: string;
|
||||
selectedFileIndex: number;
|
||||
selectedFile: any;
|
||||
selectedFile: { uid: string; file_name: string; file_blob: FileBlob } | null;
|
||||
documentNotary: DocumentNotary | null;
|
||||
fileBlob: Blob | null;
|
||||
isLoading: boolean;
|
||||
@ -132,7 +133,7 @@ class ViewDocumentsNotaryClass extends BasePage<IPropsClass, IState> {
|
||||
{
|
||||
documentNotary,
|
||||
selectedFileIndex: 0,
|
||||
selectedFile: documentNotary.files![0]!,
|
||||
selectedFile: documentNotary.files![0] as any,
|
||||
isLoading: false,
|
||||
},
|
||||
() => {
|
||||
|
@ -1,8 +1,12 @@
|
||||
import Modal from "@Front/Components/DesignSystem/Modal";
|
||||
import React from "react";
|
||||
import { FileBlob } from "@Front/Api/Entities/types";
|
||||
|
||||
type IProps = {
|
||||
file: any;
|
||||
file: {
|
||||
uid: string;
|
||||
file_blob: FileBlob;
|
||||
};
|
||||
url: string;
|
||||
isOpen: boolean;
|
||||
onClose?: () => void;
|
||||
|
@ -19,6 +19,7 @@ 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 { FileBlob } from "@Front/Api/Entities/types";
|
||||
|
||||
type IProps = {};
|
||||
type IPropsClass = {
|
||||
@ -32,7 +33,7 @@ type IState = {
|
||||
isValidateModalVisible: boolean;
|
||||
refuseText: string;
|
||||
selectedFileIndex: number;
|
||||
selectedFile: any; // File | null; TODO: review
|
||||
selectedFile: { uid: string; file_name: string; file_blob: FileBlob } | null;
|
||||
validatedPercentage: number;
|
||||
document: Document | null;
|
||||
fileBlob: Blob | null;
|
||||
@ -237,6 +238,8 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
|
||||
|
||||
private async getFilePreview(): Promise<void> {
|
||||
try {
|
||||
if (!this.state.selectedFile) return;
|
||||
|
||||
const fileBlob: Blob = new Blob([this.state.selectedFile.file_blob.data], { type: this.state.selectedFile.file_blob.type });
|
||||
this.setState({
|
||||
fileBlob,
|
||||
@ -247,7 +250,7 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
|
||||
}
|
||||
|
||||
private downloadFile() {
|
||||
if (!this.state.fileBlob) return;
|
||||
if (!this.state.fileBlob || !this.state.selectedFile) return;
|
||||
|
||||
const url = URL.createObjectURL(this.state.fileBlob);
|
||||
const a = document.createElement('a');
|
||||
|
Loading…
x
Reference in New Issue
Block a user