Fix somes issues

This commit is contained in:
Anthony Janin 2025-07-02 10:55:21 +02:00
parent ca5a59c51a
commit d3e13bd801
5 changed files with 106 additions and 49 deletions

View File

@ -9,7 +9,7 @@ export default class DocumentTypeService {
private constructor() { }
public static createDocumentType(documentData: any, validatorId: string): Promise<any> {
public static createDocumentType(documentTypeData: any, validatorId: string): Promise<any> {
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);

View File

@ -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;

View File

@ -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"

View File

@ -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<any>((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<void>((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<DocumentType>({ uid: document.id as string })),
],
await new Promise<void>((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<any>((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);

View File

@ -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<EDocumentNotaryStatus, string> = {
export default function DocumentTables(props: IProps) {
const { folderUid, customerUid } = props;
const [documents, setDocuments] = useState<Document[]>([]);
const [documents, setDocuments] = useState<any[]>([]);
const [documentsNotary, setDocumentsNotary] = useState<DocumentNotary[]>([]);
const [focusedDocumentUid, setFocusedDocumentUid] = useState<string | null>(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<void>((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: (
<Tag
color={ETagColor.INFO}
variant={ETagVariant.SEMI_BOLD}
label={tradDocumentStatus[document.document_status].toUpperCase()}
label={tradDocumentStatus[document.document_status as EDocumentStatus].toUpperCase()}
/>
),
},
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: (
<Tag
color={ETagColor.WARNING}
variant={ETagVariant.SEMI_BOLD}
label={tradDocumentStatus[document.document_status].toUpperCase()}
label={tradDocumentStatus[document.document_status as EDocumentStatus].toUpperCase()}
/>
),
},
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: (
<Tag
color={ETagColor.SUCCESS}
variant={ETagVariant.SEMI_BOLD}
label={tradDocumentStatus[document.document_status].toUpperCase()}
label={tradDocumentStatus[document.document_status as EDocumentStatus].toUpperCase()}
/>
),
},
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: (
<Tag
color={ETagColor.ERROR}
variant={ETagVariant.SEMI_BOLD}
label={tradDocumentStatus[document.document_status].toUpperCase()}
label={tradDocumentStatus[document.document_status as EDocumentStatus].toUpperCase()}
/>
),
},
@ -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",