diff --git a/src/common/Api/LeCoffreApi/sdk/DocumentTypeService.ts b/src/common/Api/LeCoffreApi/sdk/DocumentTypeService.ts index 499d9560..1f663663 100644 --- a/src/common/Api/LeCoffreApi/sdk/DocumentTypeService.ts +++ b/src/common/Api/LeCoffreApi/sdk/DocumentTypeService.ts @@ -9,7 +9,7 @@ export default class DocumentTypeService { private constructor() { } - public static createDocumentType(documentData: any, validatorId: string): Promise { + public static createDocumentType(documentTypeData: any, validatorId: string): Promise { const ownerId = User.getInstance().getPairingId()!; const processData: any = { @@ -18,7 +18,7 @@ export default class DocumentTypeService { isDeleted: 'false', created_at: new Date().toISOString(), updated_at: new Date().toISOString(), - ...documentData, + ...documentTypeData, }; const privateFields: string[] = Object.keys(processData); diff --git a/src/front/Components/Layouts/ClientDashboard/index.tsx b/src/front/Components/Layouts/ClientDashboard/index.tsx index f992be52..23fcb813 100644 --- a/src/front/Components/Layouts/ClientDashboard/index.tsx +++ b/src/front/Components/Layouts/ClientDashboard/index.tsx @@ -141,7 +141,7 @@ export default function ClientDashboard(props: IProps) { let documents: any[] = processes.map((process: any) => process.processData); // FilterBy folder_uid - documents = documents.filter((document: any) => document.folder.uid === folderUid); + documents = documents.filter((document: any) => document.folder.uid === folderUid && document.depositor); for (const document of documents) { document.document_type = (await DocumentTypeService.getDocumentTypeByUid(document.document_type.uid)).processData; diff --git a/src/front/Components/Layouts/DocumentTypes/DocumentTypesCreate/index.tsx b/src/front/Components/Layouts/DocumentTypes/DocumentTypesCreate/index.tsx index 14c94768..eba9773d 100644 --- a/src/front/Components/Layouts/DocumentTypes/DocumentTypesCreate/index.tsx +++ b/src/front/Components/Layouts/DocumentTypes/DocumentTypesCreate/index.tsx @@ -39,7 +39,7 @@ export default function DocumentTypesCreate(props: IProps) { }); await validateOrReject(documentFormModel, { groups: ["createDocumentType"] }); - const documentData: any = { + const documentTypeData: any = { ...values, office: { uid: officeId, @@ -48,7 +48,7 @@ export default function DocumentTypesCreate(props: IProps) { const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0'; LoaderService.getInstance().show(); - DocumentTypeService.createDocumentType(documentData, validatorId).then((processCreated: any) => { + DocumentTypeService.createDocumentType(documentTypeData, validatorId).then((processCreated: any) => { ToasterService.getInstance().success({ title: "Succès !", description: "Type de document créé avec succès" diff --git a/src/front/Components/Layouts/Folder/AskDocuments/ParameterDocuments/index.tsx b/src/front/Components/Layouts/Folder/AskDocuments/ParameterDocuments/index.tsx index 3ab37262..56512953 100644 --- a/src/front/Components/Layouts/Folder/AskDocuments/ParameterDocuments/index.tsx +++ b/src/front/Components/Layouts/Folder/AskDocuments/ParameterDocuments/index.tsx @@ -1,5 +1,3 @@ -import Deeds from "@Front/Api/LeCoffreApi/Notary/Deeds/Deeds"; -import DocumentTypes from "@Front/Api/LeCoffreApi/Notary/DocumentTypes/DocumentTypes"; import { IOption } from "@Front/Components/DesignSystem/Dropdown/DropdownMenu/DropdownOption"; import AutocompleteMultiSelectField from "@Front/Components/DesignSystem/Form/AutocompleteMultiSelectField"; import { IOption as IFormOption } from "@Front/Components/DesignSystem/Form/SelectFieldOld"; @@ -7,12 +5,14 @@ import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField"; import TextField from "@Front/Components/DesignSystem/Form/TextField"; import Modal from "@Front/Components/DesignSystem/Modal"; import RadioBox from "@Front/Components/DesignSystem/RadioBox"; -import { DocumentType, OfficeFolder } from "le-coffre-resources/dist/Notary"; +import { OfficeFolder } from "le-coffre-resources/dist/Notary"; import { ChangeEvent, useCallback, useEffect, useState } from "react"; import classes from "./classes.module.scss"; import DocumentTypeService from "src/common/Api/LeCoffreApi/sdk/DocumentTypeService"; +import DeedTypeService from "src/common/Api/LeCoffreApi/sdk/DeedTypeService"; +import LoaderService from "src/common/Api/LeCoffreApi/sdk/Loader/LoaderService"; type IProps = { isCreateDocumentModalVisible: boolean; @@ -75,18 +75,38 @@ export default function ParameterDocuments(props: IProps) { const addDocument = useCallback(async () => { if (addOrEditDocument === "add") { try { - const documentType = await DocumentTypes.getInstance().post({ + LoaderService.getInstance().show(); + + const documentTypeData: any = { name: documentName, private_description: visibleDescription, office: { uid: props.folder.office!.uid!, }, public_description: visibleDescription, + }; + const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0'; + + const documentType: any = await new Promise((resolve: (documentType: any) => void) => { + DocumentTypeService.createDocumentType(documentTypeData, validatorId).then((processCreated: any) => { + const documentType: any = processCreated.processData; + resolve(documentType); + }); }); const oldDocumentsType = props.folder.deed?.document_types!; - await Deeds.getInstance().put(props.folder.deed?.uid!, { - document_types: [...oldDocumentsType, documentType], + + await new Promise((resolve: () => void) => { + DeedTypeService.getDeedTypeByUid(props.folder.deed?.deed_type?.uid!).then((process: any) => { + if (process) { + DeedTypeService.updateDeedType(process, { + document_types: [ + ...oldDocumentsType.map((document: any) => ({ uid: document.uid })), + { uid: documentType.uid } + ] + }).then(() => resolve()); + } + }); }); // Create a new document type in the format expected by the parent component @@ -100,28 +120,44 @@ export default function ParameterDocuments(props: IProps) { props.onDocumentsUpdated([newDocumentType]); } + LoaderService.getInstance().hide(); handleClose(); } catch (e) { console.error(e); } } else { try { + LoaderService.getInstance().show(); + const oldDocumentsType = props.folder.deed?.document_types!; - await Deeds.getInstance().put(props.folder.deed?.uid!, { - document_types: [ - ...oldDocumentsType, - ...selectedDocuments.map((document) => DocumentType.hydrate({ uid: document.id as string })), - ], + await new Promise((resolve: () => void) => { + DeedTypeService.getDeedTypeByUid(props.folder.deed?.deed_type?.uid!).then((process: any) => { + if (process) { + DeedTypeService.updateDeedType(process, { + document_types: [ + ...oldDocumentsType.map((document: any) => ({ uid: document.uid })), + ...selectedDocuments.map((document: any) => ({ uid: document.id as string })) + ] + }).then(() => resolve()); + } + }); }); // Get the full document details for the selected documents const documentsById = await Promise.all( selectedDocuments.map(async (doc) => { - const fullDoc = await DocumentTypes.getInstance().getByUid(doc.id as string); + const documentType: any = await new Promise((resolve: (documentType: any) => void) => { + DocumentTypeService.getDocumentTypeByUid(doc.id as string).then((process: any) => { + if (process) { + const documentType: any = process.processData; + resolve(documentType); + } + }); + }); return { - label: fullDoc.name!, - value: fullDoc.uid!, - description: fullDoc.private_description!, + label: documentType.name!, + value: documentType.uid!, + description: documentType.private_description!, } as IFormOption; }) ); @@ -130,6 +166,7 @@ export default function ParameterDocuments(props: IProps) { props.onDocumentsUpdated(documentsById); } + LoaderService.getInstance().hide(); handleClose(); } catch (e) { console.error(e); diff --git a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/index.tsx index fd1c43d2..5f85bb8c 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/index.tsx @@ -1,4 +1,3 @@ -import FilesNotary from "@Front/Api/LeCoffreApi/Notary/FilesNotary/Files"; import CircleProgress from "@Front/Components/DesignSystem/CircleProgress"; import IconButton from "@Front/Components/DesignSystem/IconButton"; import Table from "@Front/Components/DesignSystem/Table"; @@ -9,7 +8,6 @@ import Module from "@Front/Config/Module"; import useOpenable from "@Front/Hooks/useOpenable"; import { ArrowDownTrayIcon, EyeIcon, TrashIcon } from "@heroicons/react/24/outline"; import { useMediaQuery } from "@mui/material"; -import { Document } from "le-coffre-resources/dist/Customer"; import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document"; import DocumentNotary, { EDocumentNotaryStatus } from "le-coffre-resources/dist/Notary/DocumentNotary"; import Link from "next/link"; @@ -44,7 +42,7 @@ const tradDocumentsNotaryStatus: Record = { export default function DocumentTables(props: IProps) { const { folderUid, customerUid } = props; - const [documents, setDocuments] = useState([]); + const [documents, setDocuments] = useState([]); const [documentsNotary, setDocumentsNotary] = useState([]); const [focusedDocumentUid, setFocusedDocumentUid] = useState(null); @@ -157,21 +155,23 @@ export default function DocumentTables(props: IProps) { }).catch((e) => console.warn(e)); }, []); - const onDownloadFileNotary = useCallback((doc: DocumentNotary) => { + const onDownloadFileNotary = useCallback((doc: any) => { const file = doc.files?.[0]; - if (!file || !file?.uid) return; + if (!file) return; - return FilesNotary.getInstance() - .download(file.uid) - .then((blob) => { - const url = URL.createObjectURL(blob); - const a = document.createElement("a"); - a.href = url; - a.download = file.file_name ?? "file"; - a.click(); - URL.revokeObjectURL(url); - }) - .catch((e) => console.warn(e)); + return new Promise((resolve: () => void) => { + const blob = new Blob([file.file_blob.data], { type: file.file_blob.type }); + const url = URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = file.file_name; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); + + resolve(); + }).catch((e) => console.warn(e)); }, []); const askedDocuments: IRowProps[] = useMemo( @@ -181,21 +181,25 @@ export default function DocumentTables(props: IProps) { if (document.document_status !== EDocumentStatus.ASKED) return null; return { key: document.uid, - document_type: { sx: { width: 400 }, content: document.document_type?.name ?? "_" }, + document_type: { sx: { width: 300 }, content: document.document_type?.name ?? "_" }, document_status: { sx: { width: 107 }, content: ( ), }, date: { - sx: { width: 107 }, + sx: { width: 120 }, content: document.created_at ? new Date(document.created_at).toLocaleDateString() : "_", }, + file: { + sx: { width: 120 }, + content: "_", + }, actions: { sx: { width: 76 }, content: ( @@ -217,21 +221,25 @@ export default function DocumentTables(props: IProps) { if (document.document_status !== EDocumentStatus.DEPOSITED) return null; return { key: document.uid, - document_type: { sx: { width: 400 }, content: document.document_type?.name ?? "_" }, + document_type: { sx: { width: 300 }, content: document.document_type?.name ?? "_" }, document_status: { sx: { width: 107 }, content: ( ), }, date: { - sx: { width: 107 }, + sx: { width: 120 }, content: document.updated_at ? new Date(document.updated_at).toLocaleDateString() : "_", }, + file: { + sx: { width: 120 }, + content: document.files?.[0]?.file_name ?? "_", + }, actions: { sx: { width: 76 }, content: ( @@ -259,21 +267,25 @@ export default function DocumentTables(props: IProps) { if (document.document_status !== EDocumentStatus.VALIDATED) return null; return { key: document.uid, - document_type: { sx: { width: 400 }, content: document.document_type?.name ?? "_" }, + document_type: { sx: { width: 300 }, content: document.document_type?.name ?? "_" }, document_status: { sx: { width: 107 }, content: ( ), }, date: { - sx: { width: 107 }, + sx: { width: 120 }, content: document.updated_at ? new Date(document.updated_at).toLocaleDateString() : "_", }, + file: { + sx: { width: 120 }, + content: document.files?.[0]?.file_name ?? "_", + }, actions: { sx: { width: 76 }, content: ( @@ -302,14 +314,14 @@ export default function DocumentTables(props: IProps) { if (document.document_status !== EDocumentStatus.REFUSED) return null; return { key: document.uid, - document_type: { sx: { width: 400 }, content: document.document_type?.name ?? "_" }, + document_type: { sx: { width: 300 }, content: document.document_type?.name ?? "_" }, document_status: { sx: { width: 107 }, content: ( ), }, @@ -331,7 +343,7 @@ export default function DocumentTables(props: IProps) { return { key: document.uid, document_type: { - sx: { width: 400 }, + sx: { width: 300 }, content: formatName(document.files?.[0]?.file_name?.split(".")?.[0] ?? "") || "_", }, document_status: { @@ -339,9 +351,13 @@ export default function DocumentTables(props: IProps) { content: getTagForSentDocument(document.document_status as EDocumentNotaryStatus), }, date: { - sx: { width: 107 }, + sx: { width: 120 }, content: document.updated_at ? new Date(document.updated_at).toLocaleDateString() : "_", }, + file: { + sx: { width: 120 }, + content: document.files?.[0]?.file_name ?? "_", + }, actions: { sx: { width: 76 }, content: ( @@ -428,6 +444,10 @@ function getHeader(dateColumnTitle: string, isMobile: boolean): IHead[] { key: "date", title: dateColumnTitle, }, + { + key: "file", + title: "Fichier", + }, { key: "actions", title: "Action",