Fix Dashboard with folders
This commit is contained in:
parent
2450d674e2
commit
0a3be835a9
@ -9,6 +9,7 @@ import { useRouter } from "next/router";
|
||||
import DefaultDashboardWithList, { IPropsDashboardWithList } from "../DefaultDashboardWithList";
|
||||
|
||||
import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService";
|
||||
import { idAsUrl } from "@Front/Utils/ProcessIdUtils";
|
||||
|
||||
type IProps = IPropsDashboardWithList & {
|
||||
isArchived?: boolean;
|
||||
@ -25,11 +26,11 @@ export default function DefaultNotaryDashboard(props: IProps) {
|
||||
: Module.getInstance().get().modules.pages.Folder.pages.FolderInformation.props.path;
|
||||
|
||||
const getBlocks = useCallback(
|
||||
(folders: OfficeFolder[]): IBlock[] => {
|
||||
(folders: any[]): IBlock[] => {
|
||||
const pendingFolders = folders
|
||||
.filter((folder) => {
|
||||
const pendingDocuments = (folder.documents ?? []).filter(
|
||||
(document) => document.document_status === EDocumentStatus.DEPOSITED,
|
||||
(document: any) => document.document_status === EDocumentStatus.DEPOSITED,
|
||||
);
|
||||
return pendingDocuments.length >= 1;
|
||||
})
|
||||
@ -40,7 +41,7 @@ export default function DefaultNotaryDashboard(props: IProps) {
|
||||
const otherFolders = folders
|
||||
.filter((folder) => {
|
||||
const pendingDocuments = (folder.documents ?? []).filter(
|
||||
(document) => document.document_status === EDocumentStatus.DEPOSITED,
|
||||
(document: any) => document.document_status === EDocumentStatus.DEPOSITED,
|
||||
);
|
||||
return pendingDocuments.length === 0;
|
||||
})
|
||||
@ -48,15 +49,18 @@ export default function DefaultNotaryDashboard(props: IProps) {
|
||||
return folder1.created_at! > folder2.created_at! ? -1 : 1;
|
||||
});
|
||||
|
||||
return [...pendingFolders, ...otherFolders].map((folder) => {
|
||||
return {
|
||||
id: folder.uid!,
|
||||
const blocks = [...pendingFolders, ...otherFolders].map((folder) => {
|
||||
const res = {
|
||||
id: idAsUrl(folder.processId),
|
||||
primaryText: folder.name,
|
||||
secondaryText: folder.folder_number,
|
||||
isActive: folderUid === folder.uid,
|
||||
showAlert: folder.documents?.some((document) => document.document_status === EDocumentStatus.DEPOSITED),
|
||||
isActive: folderUid === idAsUrl(folder.processId),
|
||||
showAlert: folder.documents?.some((document: any) => document.document_status === EDocumentStatus.DEPOSITED),
|
||||
};
|
||||
return res;
|
||||
});
|
||||
|
||||
return blocks;
|
||||
},
|
||||
[folderUid],
|
||||
);
|
||||
@ -115,14 +119,26 @@ export default function DefaultNotaryDashboard(props: IProps) {
|
||||
.then((folders) => setFolders(folders));
|
||||
*/
|
||||
|
||||
FolderService.getFolders((processes: any[]) => {
|
||||
if (processes.length > 0) {
|
||||
let folders: any[] = processes.map((process: any) => process.processData);
|
||||
FolderService.getFolders((processes: Record<string, any>) => {
|
||||
if (Object.keys(processes).length > 0) {
|
||||
let folders: any[] = Object.entries(processes).map(([processId, process]) => {
|
||||
const res = {
|
||||
...process,
|
||||
processId: processId
|
||||
};
|
||||
return res;
|
||||
});
|
||||
|
||||
|
||||
// FilterBy status
|
||||
folders = folders.filter((folder: any) => folder.status === targetedStatus);
|
||||
folders = folders.filter((folder: any) => {
|
||||
const matches = folder.status === targetedStatus;
|
||||
return matches;
|
||||
});
|
||||
|
||||
setFolders(folders);
|
||||
} else {
|
||||
console.debug('[DefaultNotaryDashboard] No processes found');
|
||||
}
|
||||
});
|
||||
}, [isArchived]);
|
||||
|
@ -33,9 +33,10 @@ export default function ClientBox(props: IProps) {
|
||||
const handleDelete = useCallback(
|
||||
(customerUid: string) => {
|
||||
LoaderService.getInstance().show();
|
||||
DocumentService.getDocuments().then((processes: any[]) => {
|
||||
if (processes.length > 0) {
|
||||
let documents: any[] = processes.map((process: any) => process.processData);
|
||||
DocumentService.getDocuments().then((processes: Record<string, any>) => {
|
||||
const processArray = Object.values(processes);
|
||||
if (processArray.length > 0) {
|
||||
let documents: any[] = processArray.map((process: any) => process.processData);
|
||||
|
||||
// FilterBy folder.uid & depositor.uid
|
||||
documents = documents.filter((document: any) => document.folder.uid === folderUid && document.depositor && document.depositor.uid === customerUid);
|
||||
|
@ -1,11 +1,9 @@
|
||||
import Folders from "@Front/Api/LeCoffreApi/Notary/Folders/Folders";
|
||||
import Button, { EButtonSize, EButtonstyletype, EButtonVariant } from "@Front/Components/DesignSystem/Button";
|
||||
import Tabs from "@Front/Components/Elements/Tabs";
|
||||
import Module from "@Front/Config/Module";
|
||||
import { DocumentIcon, UserPlusIcon } from "@heroicons/react/24/outline";
|
||||
import Customer from "le-coffre-resources/dist/Customer";
|
||||
import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document";
|
||||
import { OfficeFolder } from "le-coffre-resources/dist/Notary";
|
||||
import Link from "next/link";
|
||||
import { useCallback, useMemo, useState } from "react";
|
||||
|
||||
@ -18,9 +16,10 @@ import EmailReminder from "./EmailReminder";
|
||||
import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService";
|
||||
import LoaderService from "src/common/Api/LeCoffreApi/sdk/Loader/LoaderService";
|
||||
import MessageBus from "src/sdk/MessageBus";
|
||||
import { idAsUrl } from "@Front/Utils/ProcessIdUtils";
|
||||
|
||||
type IProps = {
|
||||
folder: { processId: string, FolderData: OfficeFolder};
|
||||
folder: any;
|
||||
anchorStatus: AnchorStatus;
|
||||
};
|
||||
|
||||
@ -92,7 +91,7 @@ export default function ClientView(props: IProps) {
|
||||
<Link
|
||||
href={Module.getInstance()
|
||||
.get()
|
||||
.modules.pages.Folder.pages.AddClient.props.path.replace("[folderUid]", folder.processId ?? "")}>
|
||||
.modules.pages.Folder.pages.AddClient.props.path.replace("[folderUid]", idAsUrl(folder.processId) ?? "")}>
|
||||
<Button
|
||||
size={EButtonSize.MD}
|
||||
rightIcon={<UserPlusIcon />}
|
||||
|
@ -20,8 +20,9 @@ import InformationSection from "./InformationSection";
|
||||
import NoClientView from "./NoClientView";
|
||||
import AnchoringProcessingInfo from "./elements/AnchoringProcessingInfo";
|
||||
|
||||
import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService";
|
||||
import EFolderStatus from "le-coffre-resources/dist/Customer/EFolderStatus";
|
||||
import MessageBus from "src/sdk/MessageBus";
|
||||
import { idAsProcessId } from "@Front/Utils/ProcessIdUtils";
|
||||
|
||||
export enum AnchorStatus {
|
||||
"VERIFIED_ON_CHAIN" = "VERIFIED_ON_CHAIN",
|
||||
@ -62,63 +63,34 @@ export default function FolderInformation(props: IProps) {
|
||||
const doesFolderHaveClient = useMemo(() => folder?.customers?.length !== 0, [folder]);
|
||||
|
||||
const fetchFolder = useCallback(async () => {
|
||||
if (!folderUid) return;
|
||||
|
||||
/*
|
||||
const query = {
|
||||
q: {
|
||||
deed: { include: { deed_type: true, document_types: true } },
|
||||
office: true,
|
||||
customers: {
|
||||
include: {
|
||||
contact: true,
|
||||
documents: {
|
||||
where: {
|
||||
folder_uid: folderUid,
|
||||
},
|
||||
include: {
|
||||
folder: true,
|
||||
document_type: true,
|
||||
files: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
documents: {
|
||||
include: {
|
||||
depositor: {
|
||||
include: {
|
||||
contact: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
folder_anchor: true,
|
||||
notes: {
|
||||
include: {
|
||||
customer: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
return Folders.getInstance()
|
||||
.getByUid(folderUid, query)
|
||||
.then((folder) => setFolder(folder));
|
||||
*/
|
||||
|
||||
// TODO: review
|
||||
return FolderService.getFolderByUid(folderUid).then(async (process: any) => {
|
||||
if (process) {
|
||||
const folder: any = process.processData;
|
||||
setFolder(folder);
|
||||
if (!folderUid) {
|
||||
console.log('[FolderInformation] No folderUid, skipping fetch');
|
||||
return;
|
||||
}
|
||||
|
||||
const processId = idAsProcessId(folderUid as string);
|
||||
return MessageBus.getInstance().getProcessData(processId).then(async (process: { [key: string]: any }) => {
|
||||
if (process) {
|
||||
const processEntries = Object.entries(process);
|
||||
if (processEntries.length === 1) {
|
||||
const [processId, processData] = processEntries[0]!;
|
||||
const folder: any = {
|
||||
...processData,
|
||||
processId: processId
|
||||
};
|
||||
setFolder(folder);
|
||||
} else if (processEntries.length > 1) {
|
||||
console.error('[FolderInformation] Multiple processes found for folderUid ', folderUid, ':', processEntries);
|
||||
}
|
||||
}
|
||||
}).catch((e) => {
|
||||
console.error('[FolderInformation] No process found for folderUid ', folderUid, ':', e);
|
||||
});
|
||||
}, [folderUid]);
|
||||
|
||||
const fetchAnchorStatus = useCallback(() => {
|
||||
return OfficeFolderAnchors.getInstance()
|
||||
.getByUid(folderUid)
|
||||
.getByUid(folderUid as string)
|
||||
.then((anchorStatus) =>
|
||||
setAnchorStatus(anchorStatus.status === "VERIFIED_ON_CHAIN" ? AnchorStatus.VERIFIED_ON_CHAIN : AnchorStatus.ANCHORING),
|
||||
)
|
||||
@ -168,7 +140,7 @@ export default function FolderInformation(props: IProps) {
|
||||
)}
|
||||
{!isArchived && anchorStatus === AnchorStatus.ANCHORING && <AnchoringProcessingInfo />}
|
||||
{isArchived && folderUid && (
|
||||
<ArchiveAlertWarning folderUid={folderUid} onDownloadAnchoringProof={downloadAnchoringProofModal.open} />
|
||||
<ArchiveAlertWarning folderUid={folderUid as string} onDownloadAnchoringProof={downloadAnchoringProofModal.open} />
|
||||
)}
|
||||
{folder && !doesFolderHaveClient && <NoClientView folder={folder} anchorStatus={anchorStatus} />}
|
||||
{folder && doesFolderHaveClient && <ClientView folder={folder} anchorStatus={anchorStatus} />}
|
||||
@ -176,7 +148,7 @@ export default function FolderInformation(props: IProps) {
|
||||
<AnchoringModal
|
||||
isOpen={anchoringModal.isOpen}
|
||||
onClose={anchoringModal.close}
|
||||
folderUid={folderUid}
|
||||
folderUid={folderUid as string}
|
||||
onAnchorSuccess={fetchData}
|
||||
/>
|
||||
)}
|
||||
@ -192,7 +164,7 @@ export default function FolderInformation(props: IProps) {
|
||||
onClose={requireAnchoringModal.close}
|
||||
onAnchor={anchoringModal.open}
|
||||
/>
|
||||
{folderUid && <ArchiveModal isOpen={archiveModal.isOpen} onClose={archiveModal.close} folderUid={folderUid} />}
|
||||
{folderUid && <ArchiveModal isOpen={archiveModal.isOpen} onClose={archiveModal.close} folderUid={folderUid as string} />}
|
||||
</div>
|
||||
)}
|
||||
{isLoading && (
|
||||
|
Loading…
x
Reference in New Issue
Block a user