Compare commits
No commits in common. "56878c977c5bafbeee970eb705e8e3a69b512848" and "6a7918d081af3716748b0a7b94eff16a6ea0b887" have entirely different histories.
56878c977c
...
6a7918d081
@ -3,7 +3,6 @@ import { v4 as uuidv4 } from 'uuid';
|
||||
import User from 'src/sdk/User';
|
||||
|
||||
import AbstractService from './AbstractService';
|
||||
import { DEFAULT_STORAGE_URLS } from '@Front/Config/AppConstants';
|
||||
|
||||
export default class CustomerService extends AbstractService {
|
||||
|
||||
@ -11,7 +10,7 @@ export default class CustomerService extends AbstractService {
|
||||
super();
|
||||
}
|
||||
|
||||
public static async createCustomer(customerData: any, validatorId: string): Promise<{ processId: string, processData: any }> {
|
||||
public static createCustomer(customerData: any, validatorId: string): Promise<any> {
|
||||
const ownerId: string = User.getInstance().getPairingId()!;
|
||||
|
||||
const processData: any = {
|
||||
@ -24,72 +23,114 @@ export default class CustomerService extends AbstractService {
|
||||
};
|
||||
|
||||
const privateFields: string[] = Object.keys(processData);
|
||||
const allFields: string[] = [...privateFields, 'roles'];
|
||||
privateFields.splice(privateFields.indexOf('uid'), 1);
|
||||
privateFields.splice(privateFields.indexOf('utype'), 1);
|
||||
privateFields.splice(privateFields.indexOf('isDeleted'), 1);
|
||||
|
||||
const roles: any = {
|
||||
demiurge: {
|
||||
members: [ownerId, validatorId],
|
||||
members: [...[ownerId], validatorId],
|
||||
validation_rules: [],
|
||||
storages: []
|
||||
},
|
||||
owner: {
|
||||
members: [ownerId, validatorId],
|
||||
members: [ownerId],
|
||||
validation_rules: [
|
||||
{
|
||||
quorum: 1,
|
||||
fields: allFields,
|
||||
quorum: 0.5,
|
||||
fields: [...privateFields, 'roles', 'uid', 'utype'],
|
||||
min_sig_member: 1,
|
||||
},
|
||||
],
|
||||
storages: [...DEFAULT_STORAGE_URLS]
|
||||
storages: []
|
||||
},
|
||||
validator: {
|
||||
members: [validatorId],
|
||||
validation_rules: [
|
||||
{
|
||||
quorum: 0.5,
|
||||
fields: ['idCertified', 'roles'],
|
||||
min_sig_member: 1,
|
||||
},
|
||||
{
|
||||
quorum: 0.0,
|
||||
fields: [...privateFields],
|
||||
min_sig_member: 0,
|
||||
},
|
||||
],
|
||||
storages: []
|
||||
},
|
||||
apophis: {
|
||||
members: [ownerId, validatorId],
|
||||
members: [ownerId],
|
||||
validation_rules: [],
|
||||
storages: []
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
const processCreated = await this.messageBus.createProcess(processData, privateFields, roles);
|
||||
await this.messageBus.notifyUpdate(processCreated.processId, processCreated.process.states[0].state_id);
|
||||
await this.messageBus.validateState(processCreated.processId, processCreated.process.states[0].state_id);
|
||||
const finalProcessData = await this.messageBus.getProcessData(processCreated.processId);
|
||||
|
||||
return { processId: processCreated.processId, processData: finalProcessData[processCreated.processId] };
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
return new Promise<any>((resolve: (processCreated: any) => void, reject: (error: string) => void) => {
|
||||
this.messageBus.createProcess(processData, privateFields, roles).then((processCreated: any) => {
|
||||
this.messageBus.notifyUpdate(processCreated.processId, processCreated.process.states[0].state_id).then(() => {
|
||||
this.messageBus.validateState(processCreated.processId, processCreated.process.states[0].state_id).then((_stateValidated: any) => {
|
||||
this.getCustomerByUid(processCreated.processData.uid).then(resolve).catch(reject);
|
||||
}).catch(reject);
|
||||
}).catch(reject);
|
||||
}).catch(reject);
|
||||
});
|
||||
}
|
||||
|
||||
public static getCustomers(callback: (processes: Record<string, any>) => void): void {
|
||||
public static getCustomers(): Promise<any[]> {
|
||||
// Check if we have valid cache
|
||||
const items: Record<string, any> = this.getItems('_customers_');
|
||||
if (Object.keys(items).length > 0) {
|
||||
setTimeout(() => callback(items), 0);
|
||||
const items: any[] = this.getItems('_customers_');
|
||||
|
||||
return this.messageBus.getProcessesDecoded((publicValues: any) =>
|
||||
publicValues['uid'] &&
|
||||
publicValues['utype'] &&
|
||||
publicValues['utype'] === 'customer' &&
|
||||
publicValues['isDeleted'] &&
|
||||
publicValues['isDeleted'] === 'false' &&
|
||||
!items.map((item: any) => item.processData.uid).includes(publicValues['uid'])
|
||||
).then((processes: any[]) => {
|
||||
if (processes.length === 0) {
|
||||
return items;
|
||||
} else {
|
||||
for (const process of processes) {
|
||||
// Update cache
|
||||
this.setItem('_customers_', process);
|
||||
|
||||
items.push(process);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static getCustomerByUid(uid: string): Promise<any> {
|
||||
// Check if we have valid cache
|
||||
const item: any = this.getItem('_customers_', uid);
|
||||
if (item) {
|
||||
return Promise.resolve(item);
|
||||
}
|
||||
|
||||
this.messageBus.getProcessesDecoded((_processId: string, values: any) => {
|
||||
return values['utype']
|
||||
&& values['utype'] === 'customer'
|
||||
&& values['isDeleted']
|
||||
&& values['isDeleted'] === 'false';
|
||||
}).then(async (processes: Record<string, any>) => {
|
||||
if (Object.keys(processes).length === 0) {
|
||||
callback(items);
|
||||
return;
|
||||
}
|
||||
return new Promise<any>((resolve: (process: any) => void, reject: (error: string) => void) => {
|
||||
this.messageBus.getProcessesDecoded((publicValues: any) =>
|
||||
publicValues['uid'] &&
|
||||
publicValues['uid'] === uid &&
|
||||
publicValues['utype'] &&
|
||||
publicValues['utype'] === 'customer' &&
|
||||
publicValues['isDeleted'] &&
|
||||
publicValues['isDeleted'] === 'false'
|
||||
).then((processes: any[]) => {
|
||||
if (processes.length === 0) {
|
||||
resolve(null);
|
||||
} else {
|
||||
const process: any = processes[0];
|
||||
|
||||
const updatedItems: Record<string, any> = { ...items };
|
||||
// Update cache
|
||||
this.setItem('_customers_', process);
|
||||
|
||||
for (const [processId, process] of Object.entries(processes)) {
|
||||
// Update cache
|
||||
this.setItem('_customers_', processId, process);
|
||||
|
||||
updatedItems[processId] = process;
|
||||
}
|
||||
|
||||
callback(updatedItems);
|
||||
resolve(process);
|
||||
}
|
||||
}).catch(reject);
|
||||
});
|
||||
}
|
||||
|
||||
@ -102,7 +143,7 @@ export default class CustomerService extends AbstractService {
|
||||
const customerUid: string = process.processData.uid;
|
||||
this.removeItem('_customers_', customerUid);
|
||||
|
||||
resolve();
|
||||
this.getCustomerByUid(customerUid).then(resolve).catch(reject);
|
||||
}).catch(reject);
|
||||
}).catch(reject);
|
||||
}).catch(reject);
|
||||
|
||||
@ -7,7 +7,6 @@ import DefaultDashboardWithList, { IPropsDashboardWithList } from "../DefaultDas
|
||||
import { DeedType } from "le-coffre-resources/dist/Notary";
|
||||
|
||||
import DeedTypeService from "src/common/Api/LeCoffreApi/sdk/DeedTypeService";
|
||||
import { idAsUrl } from "@Front/Utils/ProcessIdUtils";
|
||||
|
||||
type IProps = IPropsDashboardWithList;
|
||||
|
||||
@ -18,13 +17,13 @@ export default function DefaultDeedTypeDashboard(props: IProps) {
|
||||
const [deedTypes, setDeedTypes] = React.useState<DeedType[] | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
DeedTypeService.getDeedTypes((processes: Record<string, any>) => {
|
||||
const deedTypes = Object.entries(processes).map(([processId, processData]) => ({
|
||||
...processData,
|
||||
processId: processId
|
||||
}));
|
||||
if (deedTypes.length > 0) {
|
||||
deedTypes.filter((deedType: any) => !deedType.archived_at);
|
||||
DeedTypeService.getDeedTypes((processes: any[]) => {
|
||||
if (processes.length > 0) {
|
||||
let deedTypes = processes.map((process: any) => process.processData);
|
||||
|
||||
// FilterBy archived_at = null or not defined
|
||||
deedTypes = deedTypes.filter((deedType: any) => !deedType.archived_at);
|
||||
|
||||
// OrderBy name asc
|
||||
deedTypes.sort((a: any, b: any) => a.name.localeCompare(b.name));
|
||||
|
||||
@ -36,9 +35,7 @@ export default function DefaultDeedTypeDashboard(props: IProps) {
|
||||
}, []);
|
||||
|
||||
const onSelectedBlock = (block: IBlock) => {
|
||||
// Remove ':0' suffix from processId for URL navigation
|
||||
const urlId = idAsUrl(block.id as string);
|
||||
router.push(Module.getInstance().get().modules.pages.DeedTypes.pages.DeedTypesInformations.props.path.replace("[uid]", urlId));
|
||||
router.push(Module.getInstance().get().modules.pages.DeedTypes.pages.DeedTypesInformations.props.path.replace("[uid]", block.id));
|
||||
};
|
||||
|
||||
return (
|
||||
@ -47,14 +44,11 @@ export default function DefaultDeedTypeDashboard(props: IProps) {
|
||||
onSelectedBlock={onSelectedBlock}
|
||||
blocks={
|
||||
deedTypes
|
||||
? deedTypes.map((deedType: any) => {
|
||||
const urlId = idAsUrl(deedType.processId);
|
||||
return {
|
||||
id: deedType.processId, // Keep full processId for internal use
|
||||
primaryText: deedType.name,
|
||||
isActive: urlId === deedTypeUid, // Compare without ':0' suffix
|
||||
};
|
||||
})
|
||||
? deedTypes.map((deedTypes) => ({
|
||||
id: deedTypes.uid!,
|
||||
primaryText: deedTypes.name,
|
||||
isActive: deedTypes.uid === deedTypeUid,
|
||||
}))
|
||||
: []
|
||||
}
|
||||
bottomButton={{
|
||||
|
||||
@ -9,7 +9,6 @@ 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;
|
||||
@ -26,11 +25,11 @@ export default function DefaultNotaryDashboard(props: IProps) {
|
||||
: Module.getInstance().get().modules.pages.Folder.pages.FolderInformation.props.path;
|
||||
|
||||
const getBlocks = useCallback(
|
||||
(folders: any[]): IBlock[] => {
|
||||
(folders: OfficeFolder[]): IBlock[] => {
|
||||
const pendingFolders = folders
|
||||
.filter((folder) => {
|
||||
const pendingDocuments = (folder.documents ?? []).filter(
|
||||
(document: any) => document.document_status === EDocumentStatus.DEPOSITED,
|
||||
(document) => document.document_status === EDocumentStatus.DEPOSITED,
|
||||
);
|
||||
return pendingDocuments.length >= 1;
|
||||
})
|
||||
@ -41,7 +40,7 @@ export default function DefaultNotaryDashboard(props: IProps) {
|
||||
const otherFolders = folders
|
||||
.filter((folder) => {
|
||||
const pendingDocuments = (folder.documents ?? []).filter(
|
||||
(document: any) => document.document_status === EDocumentStatus.DEPOSITED,
|
||||
(document) => document.document_status === EDocumentStatus.DEPOSITED,
|
||||
);
|
||||
return pendingDocuments.length === 0;
|
||||
})
|
||||
@ -49,18 +48,15 @@ export default function DefaultNotaryDashboard(props: IProps) {
|
||||
return folder1.created_at! > folder2.created_at! ? -1 : 1;
|
||||
});
|
||||
|
||||
const blocks = [...pendingFolders, ...otherFolders].map((folder) => {
|
||||
const res = {
|
||||
id: idAsUrl(folder.processId),
|
||||
return [...pendingFolders, ...otherFolders].map((folder) => {
|
||||
return {
|
||||
id: folder.uid!,
|
||||
primaryText: folder.name,
|
||||
secondaryText: folder.folder_number,
|
||||
isActive: folderUid === idAsUrl(folder.processId),
|
||||
showAlert: folder.documents?.some((document: any) => document.document_status === EDocumentStatus.DEPOSITED),
|
||||
isActive: folderUid === folder.uid,
|
||||
showAlert: folder.documents?.some((document) => document.document_status === EDocumentStatus.DEPOSITED),
|
||||
};
|
||||
return res;
|
||||
});
|
||||
|
||||
return blocks;
|
||||
},
|
||||
[folderUid],
|
||||
);
|
||||
@ -119,26 +115,14 @@ export default function DefaultNotaryDashboard(props: IProps) {
|
||||
.then((folders) => setFolders(folders));
|
||||
*/
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
FolderService.getFolders((processes: any[]) => {
|
||||
if (processes.length > 0) {
|
||||
let folders: any[] = processes.map((process: any) => process.processData);
|
||||
|
||||
// FilterBy status
|
||||
folders = folders.filter((folder: any) => {
|
||||
const matches = folder.status === targetedStatus;
|
||||
return matches;
|
||||
});
|
||||
folders = folders.filter((folder: any) => folder.status === targetedStatus);
|
||||
|
||||
setFolders(folders);
|
||||
} else {
|
||||
console.debug('[DefaultNotaryDashboard] No processes found');
|
||||
}
|
||||
});
|
||||
}, [isArchived]);
|
||||
|
||||
@ -19,7 +19,6 @@ import LoaderService from "src/common/Api/LeCoffreApi/sdk/Loader/LoaderService";
|
||||
import DeedTypeService from "src/common/Api/LeCoffreApi/sdk/DeedTypeService";
|
||||
import { DEFAULT_VALIDATOR_ID } from "@Front/Config/AppConstants";
|
||||
import Auth from "@Front/Api/Auth/IdNot";
|
||||
import { idAsUrl } from "@Front/Utils/ProcessIdUtils";
|
||||
|
||||
type IProps = {};
|
||||
export default function DeedTypesCreate(props: IProps) {
|
||||
@ -81,7 +80,7 @@ export default function DeedTypesCreate(props: IProps) {
|
||||
});
|
||||
const deedTypeUid = processCreated.processId;
|
||||
// Remove ':0' suffix from processId for URL navigation
|
||||
const urlId = idAsUrl(deedTypeUid);
|
||||
const urlId = deedTypeUid.replace(/:0$/, '');
|
||||
router.push(
|
||||
Module.getInstance()
|
||||
.get()
|
||||
|
||||
@ -17,7 +17,6 @@ import classes from "./classes.module.scss";
|
||||
import DeedTypeService from "src/common/Api/LeCoffreApi/sdk/DeedTypeService";
|
||||
import LoaderService from "src/common/Api/LeCoffreApi/sdk/Loader/LoaderService";
|
||||
import MessageBus from "src/sdk/MessageBus";
|
||||
import { idAsProcessId } from "@Front/Utils/ProcessIdUtils";
|
||||
|
||||
export default function DeedTypesEdit() {
|
||||
const router = useRouter();
|
||||
@ -34,7 +33,7 @@ export default function DeedTypesEdit() {
|
||||
if (!deedTypeUid) return;
|
||||
LoaderService.getInstance().show();
|
||||
// deedTypeUid comes from URL without ':0' suffix, add it back for API calls
|
||||
const processId = idAsProcessId(deedTypeUid as string);
|
||||
const processId = (deedTypeUid as string) + ':0';
|
||||
MessageBus.getInstance().getProcessData(processId).then((processData: any) => {
|
||||
if (processData) {
|
||||
setDeedTypeSelected(processData);
|
||||
@ -67,7 +66,7 @@ export default function DeedTypesEdit() {
|
||||
try {
|
||||
LoaderService.getInstance().show();
|
||||
// deedTypeUid comes from URL without ':0' suffix, add it back for API calls
|
||||
const processId = idAsProcessId(deedTypeUid as string);
|
||||
const processId = (deedTypeUid as string) + ':0';
|
||||
|
||||
const process = await MessageBus.getInstance().getProcessData(processId);
|
||||
if (process) {
|
||||
|
||||
@ -22,7 +22,6 @@ import DeedTypeService from "src/common/Api/LeCoffreApi/sdk/DeedTypeService";
|
||||
import DocumentTypeService from "src/common/Api/LeCoffreApi/sdk/DocumentTypeService";
|
||||
import LoaderService from "src/common/Api/LeCoffreApi/sdk/Loader/LoaderService";
|
||||
import MessageBus from "src/sdk/MessageBus";
|
||||
import { idAsProcessId } from "@Front/Utils/ProcessIdUtils";
|
||||
|
||||
type IProps = {};
|
||||
export default function DeedTypesInformations(props: IProps) {
|
||||
@ -52,14 +51,12 @@ export default function DeedTypesInformations(props: IProps) {
|
||||
setIsSaveModalOpened(false);
|
||||
}, []);
|
||||
|
||||
const deleteDeedType = async () => {
|
||||
const deleteDeedType = useCallback(async () => {
|
||||
LoaderService.getInstance().show();
|
||||
try {
|
||||
// deedTypeUid comes from URL without ':0' suffix, add it back for API calls
|
||||
const processId = idAsProcessId(deedTypeUid as string);
|
||||
const process = await MessageBus.getInstance().getProcessData(processId);
|
||||
|
||||
if (process && process[processId]) {
|
||||
// deedTypeUid comes from URL without ':0' suffix, add it back for API calls
|
||||
const processId = (deedTypeUid as string) + ':0';
|
||||
MessageBus.getInstance().getProcessData(processId).then(async (process: any) => {
|
||||
if (process) {
|
||||
// New data
|
||||
const newData: any = {
|
||||
isDeleted: 'true',
|
||||
@ -67,22 +64,19 @@ export default function DeedTypesInformations(props: IProps) {
|
||||
};
|
||||
|
||||
// Merge process data with new data & update process
|
||||
process[processId].isDeleted = newData.isDeleted;
|
||||
process[processId].archived_at = newData.archived_at;
|
||||
await DeedTypeService.updateDeedType(processId, newData);
|
||||
process.processData.isDeleted = newData.isDeleted;
|
||||
process.processData.archived_at = newData.archived_at;
|
||||
await DeedTypeService.updateDeedType(process, newData);
|
||||
|
||||
router.push(
|
||||
Module.getInstance()
|
||||
.get()
|
||||
.modules.pages.DeedTypes.props.path
|
||||
);
|
||||
LoaderService.getInstance().hide();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error deleting deed type:', error);
|
||||
} finally {
|
||||
LoaderService.getInstance().hide();
|
||||
}
|
||||
};
|
||||
});
|
||||
}, [deedTypeUid, router]);
|
||||
|
||||
useEffect(() => {
|
||||
async function getDeedType() {
|
||||
@ -90,7 +84,7 @@ export default function DeedTypesInformations(props: IProps) {
|
||||
|
||||
setSelectedDocuments([]);
|
||||
// deedTypeUid comes from URL without ':0' suffix, add it back for API calls
|
||||
const processId = idAsProcessId(deedTypeUid as string);
|
||||
const processId = (deedTypeUid as string) + ':0';
|
||||
MessageBus.getInstance().getProcessData(processId).then((process: any) => {
|
||||
if (process) {
|
||||
console.log('[DeedTypesInformations] process', process);
|
||||
@ -137,7 +131,7 @@ export default function DeedTypesInformations(props: IProps) {
|
||||
const saveDocumentTypes = useCallback(async () => {
|
||||
LoaderService.getInstance().show();
|
||||
// deedTypeUid comes from URL without ':0' suffix, add it back for API calls
|
||||
const processId = idAsProcessId(deedTypeUid as string);
|
||||
const processId = (deedTypeUid as string) + ':0';
|
||||
console.log('[DeedTypesInformations] processId', processId);
|
||||
const deedType = (await MessageBus.getInstance().getProcessData(processId))[processId];
|
||||
if (deedType) {
|
||||
|
||||
@ -16,7 +16,6 @@ import classes from "./classes.module.scss";
|
||||
|
||||
import DocumentTypeService from "src/common/Api/LeCoffreApi/sdk/DocumentTypeService";
|
||||
import LoaderService from "src/common/Api/LeCoffreApi/sdk/Loader/LoaderService";
|
||||
import { idAsUrl } from "@Front/Utils/ProcessIdUtils";
|
||||
import UserStore from "@Front/Stores/UserStore";
|
||||
import { DEFAULT_VALIDATOR_ID } from "@Front/Config/AppConstants";
|
||||
|
||||
@ -69,7 +68,7 @@ export default function DocumentTypesCreate(props: IProps) {
|
||||
title: "Succès !",
|
||||
description: "Type de document créé avec succès"
|
||||
});
|
||||
const documentTypeUid = idAsUrl(processCreated.processId);
|
||||
const documentTypeUid = processCreated.processId.split(':')[0];
|
||||
if (!documentTypeUid) {
|
||||
console.error("DocumentTypesCreate: documentTypeUid is undefined - processCreated.processId is missing");
|
||||
return;
|
||||
|
||||
@ -33,10 +33,9 @@ export default function ClientBox(props: IProps) {
|
||||
const handleDelete = useCallback(
|
||||
(customerUid: string) => {
|
||||
LoaderService.getInstance().show();
|
||||
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);
|
||||
DocumentService.getDocuments().then((processes: any[]) => {
|
||||
if (processes.length > 0) {
|
||||
let documents: any[] = processes.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,9 +1,11 @@
|
||||
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";
|
||||
|
||||
@ -16,10 +18,9 @@ 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: any;
|
||||
folder: { processId: string, FolderData: OfficeFolder};
|
||||
anchorStatus: AnchorStatus;
|
||||
};
|
||||
|
||||
@ -91,7 +92,7 @@ export default function ClientView(props: IProps) {
|
||||
<Link
|
||||
href={Module.getInstance()
|
||||
.get()
|
||||
.modules.pages.Folder.pages.AddClient.props.path.replace("[folderUid]", idAsUrl(folder.processId) ?? "")}>
|
||||
.modules.pages.Folder.pages.AddClient.props.path.replace("[folderUid]", folder.processId ?? "")}>
|
||||
<Button
|
||||
size={EButtonSize.MD}
|
||||
rightIcon={<UserPlusIcon />}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import Button, { EButtonSize, EButtonstyletype, EButtonVariant } from "@Front/Components/DesignSystem/Button";
|
||||
import EmptyAlert from "@Front/Components/DesignSystem/EmptyAlert";
|
||||
import Module from "@Front/Config/Module";
|
||||
import { idAsUrl } from "@Front/Utils/ProcessIdUtils";
|
||||
import { UserPlusIcon } from "@heroicons/react/24/outline";
|
||||
import Link from "next/link";
|
||||
import React, { useMemo } from "react";
|
||||
@ -15,7 +14,7 @@ export default function AddClientSection(props: IProps) {
|
||||
|
||||
const addClientPath = useMemo(() => {
|
||||
if (!folderUid) return "";
|
||||
return Module.getInstance().get().modules.pages.Folder.pages.AddClient.props.path.replace("[folderUid]", idAsUrl(folderUid));
|
||||
return Module.getInstance().get().modules.pages.Folder.pages.AddClient.props.path.replace("[folderUid]", folderUid);
|
||||
}, [folderUid]);
|
||||
|
||||
return (
|
||||
|
||||
@ -20,9 +20,8 @@ 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",
|
||||
@ -63,34 +62,63 @@ export default function FolderInformation(props: IProps) {
|
||||
const doesFolderHaveClient = useMemo(() => folder?.customers?.length !== 0, [folder]);
|
||||
|
||||
const fetchFolder = useCallback(async () => {
|
||||
if (!folderUid) {
|
||||
console.log('[FolderInformation] No folderUid, skipping fetch');
|
||||
return;
|
||||
}
|
||||
if (!folderUid) return;
|
||||
|
||||
const processId = idAsProcessId(folderUid as string);
|
||||
return MessageBus.getInstance().getProcessData(processId).then(async (process: { [key: string]: any }) => {
|
||||
/*
|
||||
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 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);
|
||||
}
|
||||
const folder: any = process.processData;
|
||||
setFolder(folder);
|
||||
}
|
||||
}).catch((e) => {
|
||||
console.error('[FolderInformation] No process found for folderUid ', folderUid, ':', e);
|
||||
});
|
||||
}, [folderUid]);
|
||||
|
||||
const fetchAnchorStatus = useCallback(() => {
|
||||
return OfficeFolderAnchors.getInstance()
|
||||
.getByUid(folderUid as string)
|
||||
.getByUid(folderUid)
|
||||
.then((anchorStatus) =>
|
||||
setAnchorStatus(anchorStatus.status === "VERIFIED_ON_CHAIN" ? AnchorStatus.VERIFIED_ON_CHAIN : AnchorStatus.ANCHORING),
|
||||
)
|
||||
@ -140,7 +168,7 @@ export default function FolderInformation(props: IProps) {
|
||||
)}
|
||||
{!isArchived && anchorStatus === AnchorStatus.ANCHORING && <AnchoringProcessingInfo />}
|
||||
{isArchived && folderUid && (
|
||||
<ArchiveAlertWarning folderUid={folderUid as string} onDownloadAnchoringProof={downloadAnchoringProofModal.open} />
|
||||
<ArchiveAlertWarning folderUid={folderUid} onDownloadAnchoringProof={downloadAnchoringProofModal.open} />
|
||||
)}
|
||||
{folder && !doesFolderHaveClient && <NoClientView folder={folder} anchorStatus={anchorStatus} />}
|
||||
{folder && doesFolderHaveClient && <ClientView folder={folder} anchorStatus={anchorStatus} />}
|
||||
@ -148,7 +176,7 @@ export default function FolderInformation(props: IProps) {
|
||||
<AnchoringModal
|
||||
isOpen={anchoringModal.isOpen}
|
||||
onClose={anchoringModal.close}
|
||||
folderUid={folderUid as string}
|
||||
folderUid={folderUid}
|
||||
onAnchorSuccess={fetchData}
|
||||
/>
|
||||
)}
|
||||
@ -164,7 +192,7 @@ export default function FolderInformation(props: IProps) {
|
||||
onClose={requireAnchoringModal.close}
|
||||
onAnchor={anchoringModal.open}
|
||||
/>
|
||||
{folderUid && <ArchiveModal isOpen={archiveModal.isOpen} onClose={archiveModal.close} folderUid={folderUid as string} />}
|
||||
{folderUid && <ArchiveModal isOpen={archiveModal.isOpen} onClose={archiveModal.close} folderUid={folderUid} />}
|
||||
</div>
|
||||
)}
|
||||
{isLoading && (
|
||||
|
||||
@ -24,8 +24,6 @@ import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService";
|
||||
import FileService from "src/common/Api/LeCoffreApi/sdk/FileService";
|
||||
import CustomerService from "src/common/Api/LeCoffreApi/sdk/CustomerService";
|
||||
import { DEFAULT_VALIDATOR_ID } from "@Front/Config/AppConstants";
|
||||
import { idAsProcessId } from "@Front/Utils/ProcessIdUtils";
|
||||
import MessageBus from "src/sdk/MessageBus";
|
||||
|
||||
enum EClientSelection {
|
||||
ALL_CLIENTS = "all_clients",
|
||||
@ -72,7 +70,7 @@ export default function SendDocuments() {
|
||||
const customer: any = await new Promise<void>((resolve: (customer: any) => void) => {
|
||||
CustomerService.getCustomerByUid(selectedClient as string).then((process: any) => {
|
||||
if (process) {
|
||||
const customer: any = process;
|
||||
const customer: any = process.processData;
|
||||
resolve(customer);
|
||||
}
|
||||
});
|
||||
@ -102,7 +100,7 @@ export default function SendDocuments() {
|
||||
};
|
||||
|
||||
FileService.createFile(fileData, DEFAULT_VALIDATOR_ID).then((processCreated: any) => {
|
||||
const fileUid: string = processCreated.uid;
|
||||
const fileUid: string = processCreated.processData.uid;
|
||||
|
||||
const documentData: any = {
|
||||
folder: {
|
||||
@ -175,9 +173,9 @@ export default function SendDocuments() {
|
||||
|
||||
const fetchFolder = useCallback(async () => {
|
||||
LoaderService.getInstance().show();
|
||||
MessageBus.getInstance().getProcessData(idAsProcessId(folderUid as string)).then((process: any) => {
|
||||
FolderService.getFolderByUid(folderUid as string).then((process: any) => {
|
||||
if (process) {
|
||||
const folder: any = process;
|
||||
const folder: any = process.processData;
|
||||
setFolder(folder);
|
||||
LoaderService.getInstance().hide();
|
||||
}
|
||||
|
||||
@ -16,7 +16,6 @@ import { useEffect, useState } from "react";
|
||||
import classes from "./classes.module.scss";
|
||||
|
||||
import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService";
|
||||
import { idAsUrl } from "@Front/Utils/ProcessIdUtils";
|
||||
|
||||
export default function Folder() {
|
||||
const [_isArchivedModalOpen, _setIsArchivedModalOpen] = useState(true);
|
||||
@ -40,7 +39,7 @@ export default function Folder() {
|
||||
folders = folders.sort((a: any, b: any) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
|
||||
|
||||
if (folders.length > 0) {
|
||||
const folderUid = idAsUrl(folders[0]?.processId);
|
||||
const folderUid = folders[0]?.processId;
|
||||
|
||||
if (!folderUid) {
|
||||
return;
|
||||
|
||||
@ -1,52 +0,0 @@
|
||||
/**
|
||||
* Utility functions to safely handle conversion between URL-friendly IDs and process IDs.
|
||||
*
|
||||
* Process IDs in the system use a ":0" suffix for API calls, but URLs use the clean ID without the suffix.
|
||||
* These functions provide safe conversion between the two formats to avoid error-prone string manipulation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Converts a process ID to URL-friendly format by removing the ":0" suffix if present.
|
||||
* Safe to call multiple times - won't remove ":0" from IDs that don't end with it.
|
||||
*
|
||||
* @param processId - The process ID that may or may not have ":0" suffix
|
||||
* @returns The ID without ":0" suffix, suitable for use in URLs. Returns empty string for null/undefined.
|
||||
*
|
||||
* @example
|
||||
* idAsUrl("abc123:0") // returns "abc123"
|
||||
* idAsUrl("abc123") // returns "abc123" (no change)
|
||||
* idAsUrl("abc:123:0") // returns "abc:123" (only removes trailing ":0")
|
||||
* idAsUrl(null) // returns ""
|
||||
* idAsUrl(undefined) // returns ""
|
||||
*/
|
||||
export function idAsUrl(processId: string | null | undefined): string {
|
||||
if (!processId || typeof processId !== 'string') {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Only remove ":0" if it's at the very end of the string
|
||||
return processId.replace(/:0$/, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a URL-friendly ID to process ID format by adding ":0" suffix if not already present.
|
||||
* Safe to call multiple times - won't add ":0" if it's already there.
|
||||
*
|
||||
* @param urlId - The URL-friendly ID that may or may not have ":0" suffix
|
||||
* @returns The ID with ":0" suffix, suitable for use in API calls. Returns ":0" for null/undefined.
|
||||
*
|
||||
* @example
|
||||
* idAsProcessId("abc123") // returns "abc123:0"
|
||||
* idAsProcessId("abc123:0") // returns "abc123:0" (no change)
|
||||
* idAsProcessId("abc:123") // returns "abc:123:0"
|
||||
* idAsProcessId(null) // returns ""
|
||||
* idAsProcessId(undefined) // returns ""
|
||||
*/
|
||||
export function idAsProcessId(urlId: string | null | undefined): string {
|
||||
if (!urlId || typeof urlId !== 'string') {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Only add ":0" if it's not already at the end
|
||||
return urlId.endsWith(':0') ? urlId : `${urlId}:0`;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user