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 DefaultDashboardWithList, { IPropsDashboardWithList } from "../DefaultDashboardWithList";
|
||||||
|
|
||||||
import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService";
|
import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService";
|
||||||
|
import { idAsUrl } from "@Front/Utils/ProcessIdUtils";
|
||||||
|
|
||||||
type IProps = IPropsDashboardWithList & {
|
type IProps = IPropsDashboardWithList & {
|
||||||
isArchived?: boolean;
|
isArchived?: boolean;
|
||||||
@ -25,11 +26,11 @@ export default function DefaultNotaryDashboard(props: IProps) {
|
|||||||
: Module.getInstance().get().modules.pages.Folder.pages.FolderInformation.props.path;
|
: Module.getInstance().get().modules.pages.Folder.pages.FolderInformation.props.path;
|
||||||
|
|
||||||
const getBlocks = useCallback(
|
const getBlocks = useCallback(
|
||||||
(folders: OfficeFolder[]): IBlock[] => {
|
(folders: any[]): IBlock[] => {
|
||||||
const pendingFolders = folders
|
const pendingFolders = folders
|
||||||
.filter((folder) => {
|
.filter((folder) => {
|
||||||
const pendingDocuments = (folder.documents ?? []).filter(
|
const pendingDocuments = (folder.documents ?? []).filter(
|
||||||
(document) => document.document_status === EDocumentStatus.DEPOSITED,
|
(document: any) => document.document_status === EDocumentStatus.DEPOSITED,
|
||||||
);
|
);
|
||||||
return pendingDocuments.length >= 1;
|
return pendingDocuments.length >= 1;
|
||||||
})
|
})
|
||||||
@ -40,7 +41,7 @@ export default function DefaultNotaryDashboard(props: IProps) {
|
|||||||
const otherFolders = folders
|
const otherFolders = folders
|
||||||
.filter((folder) => {
|
.filter((folder) => {
|
||||||
const pendingDocuments = (folder.documents ?? []).filter(
|
const pendingDocuments = (folder.documents ?? []).filter(
|
||||||
(document) => document.document_status === EDocumentStatus.DEPOSITED,
|
(document: any) => document.document_status === EDocumentStatus.DEPOSITED,
|
||||||
);
|
);
|
||||||
return pendingDocuments.length === 0;
|
return pendingDocuments.length === 0;
|
||||||
})
|
})
|
||||||
@ -48,15 +49,18 @@ export default function DefaultNotaryDashboard(props: IProps) {
|
|||||||
return folder1.created_at! > folder2.created_at! ? -1 : 1;
|
return folder1.created_at! > folder2.created_at! ? -1 : 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
return [...pendingFolders, ...otherFolders].map((folder) => {
|
const blocks = [...pendingFolders, ...otherFolders].map((folder) => {
|
||||||
return {
|
const res = {
|
||||||
id: folder.uid!,
|
id: idAsUrl(folder.processId),
|
||||||
primaryText: folder.name,
|
primaryText: folder.name,
|
||||||
secondaryText: folder.folder_number,
|
secondaryText: folder.folder_number,
|
||||||
isActive: folderUid === folder.uid,
|
isActive: folderUid === idAsUrl(folder.processId),
|
||||||
showAlert: folder.documents?.some((document) => document.document_status === EDocumentStatus.DEPOSITED),
|
showAlert: folder.documents?.some((document: any) => document.document_status === EDocumentStatus.DEPOSITED),
|
||||||
};
|
};
|
||||||
|
return res;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return blocks;
|
||||||
},
|
},
|
||||||
[folderUid],
|
[folderUid],
|
||||||
);
|
);
|
||||||
@ -115,14 +119,26 @@ export default function DefaultNotaryDashboard(props: IProps) {
|
|||||||
.then((folders) => setFolders(folders));
|
.then((folders) => setFolders(folders));
|
||||||
*/
|
*/
|
||||||
|
|
||||||
FolderService.getFolders((processes: any[]) => {
|
FolderService.getFolders((processes: Record<string, any>) => {
|
||||||
if (processes.length > 0) {
|
if (Object.keys(processes).length > 0) {
|
||||||
let folders: any[] = processes.map((process: any) => process.processData);
|
let folders: any[] = Object.entries(processes).map(([processId, process]) => {
|
||||||
|
const res = {
|
||||||
|
...process,
|
||||||
|
processId: processId
|
||||||
|
};
|
||||||
|
return res;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// FilterBy status
|
// FilterBy status
|
||||||
folders = folders.filter((folder: any) => folder.status === targetedStatus);
|
folders = folders.filter((folder: any) => {
|
||||||
|
const matches = folder.status === targetedStatus;
|
||||||
|
return matches;
|
||||||
|
});
|
||||||
|
|
||||||
setFolders(folders);
|
setFolders(folders);
|
||||||
|
} else {
|
||||||
|
console.debug('[DefaultNotaryDashboard] No processes found');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, [isArchived]);
|
}, [isArchived]);
|
||||||
|
@ -33,9 +33,10 @@ export default function ClientBox(props: IProps) {
|
|||||||
const handleDelete = useCallback(
|
const handleDelete = useCallback(
|
||||||
(customerUid: string) => {
|
(customerUid: string) => {
|
||||||
LoaderService.getInstance().show();
|
LoaderService.getInstance().show();
|
||||||
DocumentService.getDocuments().then((processes: any[]) => {
|
DocumentService.getDocuments().then((processes: Record<string, any>) => {
|
||||||
if (processes.length > 0) {
|
const processArray = Object.values(processes);
|
||||||
let documents: any[] = processes.map((process: any) => process.processData);
|
if (processArray.length > 0) {
|
||||||
|
let documents: any[] = processArray.map((process: any) => process.processData);
|
||||||
|
|
||||||
// FilterBy folder.uid & depositor.uid
|
// FilterBy folder.uid & depositor.uid
|
||||||
documents = documents.filter((document: any) => document.folder.uid === folderUid && document.depositor && document.depositor.uid === customerUid);
|
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 Button, { EButtonSize, EButtonstyletype, EButtonVariant } from "@Front/Components/DesignSystem/Button";
|
||||||
import Tabs from "@Front/Components/Elements/Tabs";
|
import Tabs from "@Front/Components/Elements/Tabs";
|
||||||
import Module from "@Front/Config/Module";
|
import Module from "@Front/Config/Module";
|
||||||
import { DocumentIcon, UserPlusIcon } from "@heroicons/react/24/outline";
|
import { DocumentIcon, UserPlusIcon } from "@heroicons/react/24/outline";
|
||||||
import Customer from "le-coffre-resources/dist/Customer";
|
import Customer from "le-coffre-resources/dist/Customer";
|
||||||
import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document";
|
import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document";
|
||||||
import { OfficeFolder } from "le-coffre-resources/dist/Notary";
|
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useCallback, useMemo, useState } from "react";
|
import { useCallback, useMemo, useState } from "react";
|
||||||
|
|
||||||
@ -18,9 +16,10 @@ import EmailReminder from "./EmailReminder";
|
|||||||
import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService";
|
import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService";
|
||||||
import LoaderService from "src/common/Api/LeCoffreApi/sdk/Loader/LoaderService";
|
import LoaderService from "src/common/Api/LeCoffreApi/sdk/Loader/LoaderService";
|
||||||
import MessageBus from "src/sdk/MessageBus";
|
import MessageBus from "src/sdk/MessageBus";
|
||||||
|
import { idAsUrl } from "@Front/Utils/ProcessIdUtils";
|
||||||
|
|
||||||
type IProps = {
|
type IProps = {
|
||||||
folder: { processId: string, FolderData: OfficeFolder};
|
folder: any;
|
||||||
anchorStatus: AnchorStatus;
|
anchorStatus: AnchorStatus;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -92,7 +91,7 @@ export default function ClientView(props: IProps) {
|
|||||||
<Link
|
<Link
|
||||||
href={Module.getInstance()
|
href={Module.getInstance()
|
||||||
.get()
|
.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
|
<Button
|
||||||
size={EButtonSize.MD}
|
size={EButtonSize.MD}
|
||||||
rightIcon={<UserPlusIcon />}
|
rightIcon={<UserPlusIcon />}
|
||||||
|
@ -20,8 +20,9 @@ import InformationSection from "./InformationSection";
|
|||||||
import NoClientView from "./NoClientView";
|
import NoClientView from "./NoClientView";
|
||||||
import AnchoringProcessingInfo from "./elements/AnchoringProcessingInfo";
|
import AnchoringProcessingInfo from "./elements/AnchoringProcessingInfo";
|
||||||
|
|
||||||
import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService";
|
|
||||||
import EFolderStatus from "le-coffre-resources/dist/Customer/EFolderStatus";
|
import EFolderStatus from "le-coffre-resources/dist/Customer/EFolderStatus";
|
||||||
|
import MessageBus from "src/sdk/MessageBus";
|
||||||
|
import { idAsProcessId } from "@Front/Utils/ProcessIdUtils";
|
||||||
|
|
||||||
export enum AnchorStatus {
|
export enum AnchorStatus {
|
||||||
"VERIFIED_ON_CHAIN" = "VERIFIED_ON_CHAIN",
|
"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 doesFolderHaveClient = useMemo(() => folder?.customers?.length !== 0, [folder]);
|
||||||
|
|
||||||
const fetchFolder = useCallback(async () => {
|
const fetchFolder = useCallback(async () => {
|
||||||
if (!folderUid) return;
|
if (!folderUid) {
|
||||||
|
console.log('[FolderInformation] No folderUid, skipping fetch');
|
||||||
/*
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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]);
|
}, [folderUid]);
|
||||||
|
|
||||||
const fetchAnchorStatus = useCallback(() => {
|
const fetchAnchorStatus = useCallback(() => {
|
||||||
return OfficeFolderAnchors.getInstance()
|
return OfficeFolderAnchors.getInstance()
|
||||||
.getByUid(folderUid)
|
.getByUid(folderUid as string)
|
||||||
.then((anchorStatus) =>
|
.then((anchorStatus) =>
|
||||||
setAnchorStatus(anchorStatus.status === "VERIFIED_ON_CHAIN" ? AnchorStatus.VERIFIED_ON_CHAIN : AnchorStatus.ANCHORING),
|
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 && anchorStatus === AnchorStatus.ANCHORING && <AnchoringProcessingInfo />}
|
||||||
{isArchived && folderUid && (
|
{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 && <NoClientView folder={folder} anchorStatus={anchorStatus} />}
|
||||||
{folder && doesFolderHaveClient && <ClientView folder={folder} anchorStatus={anchorStatus} />}
|
{folder && doesFolderHaveClient && <ClientView folder={folder} anchorStatus={anchorStatus} />}
|
||||||
@ -176,7 +148,7 @@ export default function FolderInformation(props: IProps) {
|
|||||||
<AnchoringModal
|
<AnchoringModal
|
||||||
isOpen={anchoringModal.isOpen}
|
isOpen={anchoringModal.isOpen}
|
||||||
onClose={anchoringModal.close}
|
onClose={anchoringModal.close}
|
||||||
folderUid={folderUid}
|
folderUid={folderUid as string}
|
||||||
onAnchorSuccess={fetchData}
|
onAnchorSuccess={fetchData}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@ -192,7 +164,7 @@ export default function FolderInformation(props: IProps) {
|
|||||||
onClose={requireAnchoringModal.close}
|
onClose={requireAnchoringModal.close}
|
||||||
onAnchor={anchoringModal.open}
|
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>
|
</div>
|
||||||
)}
|
)}
|
||||||
{isLoading && (
|
{isLoading && (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user