ajanin #5
152
src/common/Api/LeCoffreApi/sdk/CollaboratorService.ts
Normal file
152
src/common/Api/LeCoffreApi/sdk/CollaboratorService.ts
Normal file
@ -0,0 +1,152 @@
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import User from 'src/sdk/User';
|
||||
|
||||
import AbstractService from './AbstractService';
|
||||
|
||||
export default class CollaboratorService extends AbstractService {
|
||||
|
||||
private constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static createCollaborator(collaboratorData: any, validatorId: string): Promise<any> {
|
||||
const ownerId = User.getInstance().getPairingId()!;
|
||||
|
||||
const processData: any = {
|
||||
uid: uuidv4(),
|
||||
utype: 'collaborator',
|
||||
isDeleted: 'false',
|
||||
created_at: new Date().toISOString(),
|
||||
updated_at: new Date().toISOString(),
|
||||
...collaboratorData,
|
||||
};
|
||||
|
||||
const privateFields: string[] = Object.keys(processData);
|
||||
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],
|
||||
validation_rules: [],
|
||||
storages: []
|
||||
},
|
||||
owner: {
|
||||
members: [ownerId],
|
||||
validation_rules: [
|
||||
{
|
||||
quorum: 0.5,
|
||||
fields: [...privateFields, 'roles', 'uid', 'utype'],
|
||||
min_sig_member: 1,
|
||||
},
|
||||
],
|
||||
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],
|
||||
validation_rules: [],
|
||||
storages: []
|
||||
}
|
||||
};
|
||||
|
||||
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.getCollaboratorByUid(processCreated.processData.uid).then(resolve).catch(reject);
|
||||
}).catch(reject);
|
||||
}).catch(reject);
|
||||
}).catch(reject);
|
||||
});
|
||||
}
|
||||
|
||||
public static getCollaborators(): Promise<any[]> {
|
||||
// Check if we have valid cache
|
||||
const items: any[] = this.getItems('_collaborators_');
|
||||
|
||||
return this.messageBus.getProcessesDecoded((publicValues: any) =>
|
||||
publicValues['uid'] &&
|
||||
publicValues['utype'] &&
|
||||
publicValues['utype'] === 'collaborator' &&
|
||||
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('_collaborators_', process);
|
||||
|
||||
items.push(process);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static getCollaboratorByUid(uid: string): Promise<any> {
|
||||
// Check if we have valid cache
|
||||
const item: any = this.getItem('_collaborators_', uid);
|
||||
if (item) {
|
||||
return Promise.resolve(item);
|
||||
}
|
||||
|
||||
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'] === 'collaborator' &&
|
||||
publicValues['isDeleted'] &&
|
||||
publicValues['isDeleted'] === 'false'
|
||||
).then((processes: any[]) => {
|
||||
if (processes.length === 0) {
|
||||
resolve(null);
|
||||
} else {
|
||||
const process: any = processes[0];
|
||||
|
||||
// Update cache
|
||||
this.setItem('_collaborators_', process);
|
||||
|
||||
resolve(process);
|
||||
}
|
||||
}).catch(reject);
|
||||
});
|
||||
}
|
||||
|
||||
public static updateCollaborator(process: any, newData: any): Promise<void> {
|
||||
return new Promise<void>((resolve: () => void, reject: (error: string) => void) => {
|
||||
this.messageBus.updateProcess(process.processId, { updated_at: new Date().toISOString(), ...newData }, [], null).then((processUpdated: any) => {
|
||||
const newStateId: string = processUpdated.diffs[0]?.state_id;
|
||||
this.messageBus.notifyUpdate(process.processId, newStateId).then(() => {
|
||||
this.messageBus.validateState(process.processId, newStateId).then((_stateValidated) => {
|
||||
const collaboratorUid: string = process.processData.uid;
|
||||
this.removeItem('_collaborators_', collaboratorUid);
|
||||
|
||||
this.getCollaboratorByUid(collaboratorUid).then(resolve).catch(reject);
|
||||
}).catch(reject);
|
||||
}).catch(reject);
|
||||
}).catch(reject);
|
||||
});
|
||||
}
|
||||
}
|
152
src/common/Api/LeCoffreApi/sdk/OfficeService.ts
Normal file
152
src/common/Api/LeCoffreApi/sdk/OfficeService.ts
Normal file
@ -0,0 +1,152 @@
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import User from 'src/sdk/User';
|
||||
|
||||
import AbstractService from './AbstractService';
|
||||
|
||||
export default class OfficeService extends AbstractService {
|
||||
|
||||
private constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static createOffice(officeData: any, validatorId: string): Promise<any> {
|
||||
const ownerId = User.getInstance().getPairingId()!;
|
||||
|
||||
const processData: any = {
|
||||
uid: uuidv4(),
|
||||
utype: 'office',
|
||||
isDeleted: 'false',
|
||||
created_at: new Date().toISOString(),
|
||||
updated_at: new Date().toISOString(),
|
||||
...officeData,
|
||||
};
|
||||
|
||||
const privateFields: string[] = Object.keys(processData);
|
||||
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],
|
||||
validation_rules: [],
|
||||
storages: []
|
||||
},
|
||||
owner: {
|
||||
members: [ownerId],
|
||||
validation_rules: [
|
||||
{
|
||||
quorum: 0.5,
|
||||
fields: [...privateFields, 'roles', 'uid', 'utype'],
|
||||
min_sig_member: 1,
|
||||
},
|
||||
],
|
||||
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],
|
||||
validation_rules: [],
|
||||
storages: []
|
||||
}
|
||||
};
|
||||
|
||||
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.getOfficeByUid(processCreated.processData.uid).then(resolve).catch(reject);
|
||||
}).catch(reject);
|
||||
}).catch(reject);
|
||||
}).catch(reject);
|
||||
});
|
||||
}
|
||||
|
||||
public static getOffices(): Promise<any[]> {
|
||||
// Check if we have valid cache
|
||||
const items: any[] = this.getItems('_offices_');
|
||||
|
||||
return this.messageBus.getProcessesDecoded((publicValues: any) =>
|
||||
publicValues['uid'] &&
|
||||
publicValues['utype'] &&
|
||||
publicValues['utype'] === 'office' &&
|
||||
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('_offices_', process);
|
||||
|
||||
items.push(process);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static getOfficeByUid(uid: string): Promise<any> {
|
||||
// Check if we have valid cache
|
||||
const item: any = this.getItem('_offices_', uid);
|
||||
if (item) {
|
||||
return Promise.resolve(item);
|
||||
}
|
||||
|
||||
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'] === 'office' &&
|
||||
publicValues['isDeleted'] &&
|
||||
publicValues['isDeleted'] === 'false'
|
||||
).then((processes: any[]) => {
|
||||
if (processes.length === 0) {
|
||||
resolve(null);
|
||||
} else {
|
||||
const process: any = processes[0];
|
||||
|
||||
// Update cache
|
||||
this.setItem('_offices_', process);
|
||||
|
||||
resolve(process);
|
||||
}
|
||||
}).catch(reject);
|
||||
});
|
||||
}
|
||||
|
||||
public static updateDocument(process: any, newData: any): Promise<void> {
|
||||
return new Promise<void>((resolve: () => void, reject: (error: string) => void) => {
|
||||
this.messageBus.updateProcess(process.processId, { updated_at: new Date().toISOString(), ...newData }, [], null).then((processUpdated: any) => {
|
||||
const newStateId: string = processUpdated.diffs[0]?.state_id;
|
||||
this.messageBus.notifyUpdate(process.processId, newStateId).then(() => {
|
||||
this.messageBus.validateState(process.processId, newStateId).then((_stateValidated) => {
|
||||
const officeUid: string = process.processData.uid;
|
||||
this.removeItem('_offices_', officeUid);
|
||||
|
||||
this.getOfficeByUid(officeUid).then(resolve).catch(reject);
|
||||
}).catch(reject);
|
||||
}).catch(reject);
|
||||
}).catch(reject);
|
||||
});
|
||||
}
|
||||
}
|
@ -40,7 +40,7 @@ export default class Auth extends BaseApiService {
|
||||
}
|
||||
}
|
||||
|
||||
public async getIdnotJwt(autorizationCode: string | string[]): Promise<{ accessToken: string; refreshToken: string }> {
|
||||
public async getIdNotUser(autorizationCode: string | string[]): Promise<{ idNotUser: any }> {
|
||||
// const variables = FrontendVariables.getInstance();
|
||||
|
||||
// TODO: review
|
||||
@ -48,7 +48,7 @@ export default class Auth extends BaseApiService {
|
||||
|
||||
const url = new URL(`${baseBackUrl}/api/v1/idnot/user/${autorizationCode}`);
|
||||
try {
|
||||
return await this.postRequest<{ accessToken: string; refreshToken: string }>(url);
|
||||
return await this.postRequest<{ idNotUser: any }>(url);
|
||||
} catch (err) {
|
||||
this.onError(err);
|
||||
return Promise.reject(err);
|
||||
|
@ -2,11 +2,12 @@ import React, { useEffect } from "react";
|
||||
|
||||
import { useRouter } from "next/router";
|
||||
import Module from "@Front/Config/Module";
|
||||
import UserStore from "@Front/Stores/UserStore";
|
||||
import { IBlock } from "@Front/Components/DesignSystem/SearchBlockList/BlockList/Block";
|
||||
import DefaultDashboardWithList, { IPropsDashboardWithList } from "../DefaultDashboardWithList";
|
||||
import User from "le-coffre-resources/dist/Notary";
|
||||
// import JwtService from "@Front/Services/JwtService/JwtService";
|
||||
// import Users, { IGetUsersparams } from "@Front/Api/LeCoffreApi/Admin/Users/Users";
|
||||
|
||||
import CollaboratorService from "src/common/Api/LeCoffreApi/sdk/CollaboratorService";
|
||||
|
||||
type IProps = IPropsDashboardWithList;
|
||||
|
||||
@ -33,7 +34,20 @@ export default function DefaultCollaboratorDashboard(props: IProps) {
|
||||
.get(query)
|
||||
.then((users) => setCollaborators(users));
|
||||
*/
|
||||
setCollaborators([]);
|
||||
|
||||
const user: any = UserStore.instance.getUser();
|
||||
const officeUid: string = user.office.uid;
|
||||
|
||||
CollaboratorService.getCollaborators().then((processes: any[]) => {
|
||||
if (processes.length > 0) {
|
||||
let collaborators: any[] = processes.map((process: any) => process.processData);
|
||||
|
||||
// FilterBy office.uid
|
||||
collaborators = collaborators.filter((collaborator: any) => collaborator.office.uid === officeUid);
|
||||
|
||||
setCollaborators(collaborators);
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
|
||||
const onSelectedBlock = (block: IBlock) => {
|
||||
|
@ -51,7 +51,11 @@ export default function DefaultCustomerDashboard(props: IProps) {
|
||||
if (props.isReady) {
|
||||
FolderService.getFolders().then((processes: any[]) => {
|
||||
if (processes.length > 0) {
|
||||
const folders: any[] = processes.map((process: any) => process.processData);
|
||||
let folders: any[] = processes.map((process: any) => process.processData);
|
||||
|
||||
// Filter By customer.uid
|
||||
folders = folders.filter((folder: any) => folder.customers.some((customer: any) => customer.uid === profileUid));
|
||||
|
||||
setFolders(folders);
|
||||
}
|
||||
});
|
||||
|
@ -4,8 +4,6 @@ import { useRouter } from "next/router";
|
||||
import Module from "@Front/Config/Module";
|
||||
import { IBlock } from "@Front/Components/DesignSystem/SearchBlockList/BlockList/Block";
|
||||
import DefaultDashboardWithList, { IPropsDashboardWithList } from "../DefaultDashboardWithList";
|
||||
import { OfficeRole } from "le-coffre-resources/dist/Notary";
|
||||
// import OfficeRoles, { IGetRolesParams } from "@Front/Api/LeCoffreApi/Admin/OfficeRoles/OfficeRoles";
|
||||
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
@ -14,7 +12,7 @@ import RoleService from "src/common/Api/LeCoffreApi/sdk/RoleService";
|
||||
type IProps = IPropsDashboardWithList;
|
||||
|
||||
export default function DefaultRoleDashboard(props: IProps) {
|
||||
const [roles, setRoles] = React.useState<OfficeRole[] | null>(null);
|
||||
const [roles, setRoles] = React.useState<any[] | null>(null);
|
||||
const router = useRouter();
|
||||
const { roleUid } = router.query;
|
||||
useEffect(() => {
|
||||
@ -112,12 +110,14 @@ export default function DefaultRoleDashboard(props: IProps) {
|
||||
const roles: any[] = processes.map((process: any) => process.processData);
|
||||
setRoles(roles);
|
||||
} else {
|
||||
/*
|
||||
for (let role of roles) {
|
||||
const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0';
|
||||
|
||||
await RoleService.createRole(role, validatorId);
|
||||
}
|
||||
setRoles(roles);
|
||||
*/
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
@ -134,7 +134,7 @@ export default function DefaultRoleDashboard(props: IProps) {
|
||||
roles
|
||||
? roles.map((role) => ({
|
||||
id: role.uid!,
|
||||
primaryText: role.name,
|
||||
primaryText: role.label,
|
||||
isActive: role.uid === roleUid,
|
||||
}))
|
||||
: []
|
||||
|
@ -115,7 +115,7 @@ export default function ReceivedDocuments() {
|
||||
let documents: any[] = processes.map((process: any) => process.processData);
|
||||
|
||||
// FilterBy folder.uid & customer.uid
|
||||
documents = documents.filter((document: any) => document.folder.uid === folderUid && document.customer && document.customer.uid === customerUid);
|
||||
documents = documents.filter((document: any) => document.folder.uid === folderUid && document.customer /*&& document.customer.uid === customerUid*/);
|
||||
|
||||
for (const document of documents) {
|
||||
if (document.files && document.files.length > 0) {
|
||||
|
@ -139,6 +139,7 @@ export default function ClientDashboard(props: IProps) {
|
||||
|
||||
const fetchDocuments = useCallback(
|
||||
async (customerUid: string | undefined) => {
|
||||
setDocuments([]);
|
||||
LoaderService.getInstance().show();
|
||||
return new Promise<void>((resolve: () => void) => {
|
||||
DocumentService.getDocuments().then(async (processes: any[]) => {
|
||||
@ -179,9 +180,9 @@ export default function ClientDashboard(props: IProps) {
|
||||
*/
|
||||
|
||||
useEffect(() => {
|
||||
setDocumentsNotary([]);
|
||||
const customerUid = customer?.uid;
|
||||
if (!folderUid || !customerUid) return;
|
||||
|
||||
LoaderService.getInstance().show();
|
||||
DocumentService.getDocuments().then(async (processes: any[]) => {
|
||||
if (processes.length > 0) {
|
||||
|
@ -18,6 +18,9 @@ import { IOption } from "@Front/Components/DesignSystem/Dropdown/DropdownMenu/Dr
|
||||
import { getLabel } from "@Front/Components/DesignSystem/Dropdown";
|
||||
import SelectField from "@Front/Components/DesignSystem/Form/SelectField";
|
||||
|
||||
import CollaboratorService from "src/common/Api/LeCoffreApi/sdk/CollaboratorService";
|
||||
import RoleService from "src/common/Api/LeCoffreApi/sdk/RoleService";
|
||||
|
||||
type IProps = {};
|
||||
export default function CollaboratorInformations(props: IProps) {
|
||||
const router = useRouter();
|
||||
@ -120,6 +123,30 @@ export default function CollaboratorInformations(props: IProps) {
|
||||
useEffect(() => {
|
||||
async function getUser() {
|
||||
if (!collaboratorUid) return;
|
||||
|
||||
CollaboratorService.getCollaboratorByUid(collaboratorUid as string).then(async (process: any) => {
|
||||
if (process) {
|
||||
const collaborator: any = process.processData;
|
||||
|
||||
const roles: any[] = await new Promise<any[]>((resolve: (roles: any[]) => void) => {
|
||||
RoleService.getRoles().then((processes: any[]) => {
|
||||
if (processes.length > 0) {
|
||||
const roles: any[] = processes.map((process: any) => process.processData);
|
||||
resolve(roles);
|
||||
}
|
||||
});
|
||||
});
|
||||
setAvailableRoles(roles.map((role) => ({ id: role.uid ?? "", label: role.label })));
|
||||
|
||||
setUserSelected(collaborator);
|
||||
setSelectedOption({
|
||||
id: (collaborator?.office_role ? collaborator?.office_role?.uid : collaborator?.role?.uid) ?? "",
|
||||
label: collaborator?.office_role ? collaborator?.office_role?.label : "Utilisateur restreint",
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
const user = await Users.getInstance().getByUid(collaboratorUid as string, {
|
||||
q: {
|
||||
contact: true,
|
||||
@ -142,6 +169,7 @@ export default function CollaboratorInformations(props: IProps) {
|
||||
id: (user?.office_role ? user?.office_role?.uid : user?.role?.uid) ?? "",
|
||||
label: user?.office_role ? user?.office_role?.name : "Utilisateur restreint",
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
getUser();
|
||||
|
@ -6,8 +6,6 @@ import Typography, { ETypo, ETypoColor } from "@Front/Components/DesignSystem/Ty
|
||||
import HelpBox from "@Front/Components/Elements/HelpBox";
|
||||
import DefaultDoubleSidePage from "@Front/Components/LayoutTemplates/DefaultDoubleSidePage";
|
||||
import Module from "@Front/Config/Module";
|
||||
import CookieService from "@Front/Services/CookieService/CookieService";
|
||||
import JwtService from "@Front/Services/JwtService/JwtService";
|
||||
import UserStore from "@Front/Stores/UserStore";
|
||||
import Image from "next/image";
|
||||
import { useRouter } from "next/router";
|
||||
@ -16,12 +14,100 @@ import classes from "./classes.module.scss";
|
||||
|
||||
import AuthModal from "src/sdk/AuthModal";
|
||||
|
||||
import MessageBus from "src/sdk/MessageBus";
|
||||
import Iframe from "src/sdk/Iframe";
|
||||
|
||||
import OfficeService from "src/common/Api/LeCoffreApi/sdk/OfficeService";
|
||||
import RoleService from "src/common/Api/LeCoffreApi/sdk/RoleService";
|
||||
import CollaboratorService from "src/common/Api/LeCoffreApi/sdk/CollaboratorService";
|
||||
|
||||
export default function LoginCallBack() {
|
||||
const router = useRouter();
|
||||
const [idNotUser, setIdNotUser] = useState<any>(null);
|
||||
const [isAuthModalOpen, setIsAuthModalOpen] = useState(false);
|
||||
const [isConnected, setIsConnected] = useState(false);
|
||||
|
||||
const getOffice = async (idNotUser: any) => {
|
||||
return await new Promise<any>((resolve: (office: any) => void) => {
|
||||
OfficeService.getOffices().then((processes: any[]) => {
|
||||
const officeFound: any = processes.length > 0 ? processes.map((process: any) => process.processData).find((office: any) => office.idNot === idNotUser.office.idNot) : null;
|
||||
if (officeFound) {
|
||||
resolve(officeFound);
|
||||
} else {
|
||||
const officeData: any = {
|
||||
idNot: idNotUser.office.idNot,
|
||||
name: idNotUser.office.name,
|
||||
crpcen: idNotUser.office.crpcen,
|
||||
address: {
|
||||
create: {
|
||||
address: idNotUser.office.address.address,
|
||||
zip_code: idNotUser.office.address.zip_code,
|
||||
city: idNotUser.office.address.city,
|
||||
},
|
||||
},
|
||||
office_status: 'ACTIVATED'
|
||||
};
|
||||
const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0';
|
||||
|
||||
OfficeService.createOffice(officeData, validatorId).then((process: any) => {
|
||||
if (process) {
|
||||
const office: any = process.processData;
|
||||
resolve(office);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const getRole = async (idNotUser: any) => {
|
||||
return await new Promise<any>((resolve: (role: any) => void) => {
|
||||
RoleService.getRoles().then((processes: any[]) => {
|
||||
const roleFound: any = processes.length > 0 ? processes.map((process: any) => process.processData).find((role: any) => role.name === idNotUser.role.name) : null;
|
||||
if (roleFound) {
|
||||
resolve(roleFound);
|
||||
} else {
|
||||
const roleData: any = {
|
||||
name: idNotUser.role!.name,
|
||||
label: idNotUser.role!.label
|
||||
};
|
||||
const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0';
|
||||
|
||||
RoleService.createRole(roleData, validatorId).then((process: any) => {
|
||||
if (process) {
|
||||
const role: any = process.processData;
|
||||
resolve(role);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const getCollaborator = async (collaboratorData: any) => {
|
||||
return await new Promise<any>((resolve: (role: any) => void) => {
|
||||
CollaboratorService.getCollaborators().then((processes: any[]) => {
|
||||
const collaboratorFound: any = processes.length > 0 ? processes.map((process: any) => process.processData).find((collaborator: any) => collaborator.idNot === idNotUser.idNot) : null;
|
||||
if (collaboratorFound) {
|
||||
resolve(collaboratorFound);
|
||||
} else {
|
||||
const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0';
|
||||
|
||||
CollaboratorService.createCollaborator(collaboratorData, validatorId).then((process: any) => {
|
||||
if (process) {
|
||||
const collaborator: any = process.processData;
|
||||
resolve(collaborator);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
async function getUser() {
|
||||
UserStore.instance.disconnect();
|
||||
|
||||
// TODO: review
|
||||
// HACK: If start with http://local.lecoffreio.4nkweb:3000/authorized-client
|
||||
// Replace with http://localhost:3000/authorized-client
|
||||
@ -33,7 +119,11 @@ export default function LoginCallBack() {
|
||||
const code = router.query["code"];
|
||||
if (code) {
|
||||
try {
|
||||
const token = await Auth.getInstance().getIdnotJwt(code as string);
|
||||
const idNotUser: any = await Auth.getInstance().getIdNotUser(code as string);
|
||||
setIdNotUser(idNotUser);
|
||||
setIsAuthModalOpen(true);
|
||||
/*
|
||||
const token: any = null;
|
||||
if (!token) return router.push(Module.getInstance().get().modules.pages.Login.props.path);
|
||||
await UserStore.instance.connect(token.accessToken, token.refreshToken);
|
||||
const jwt = JwtService.getInstance().decodeJwt();
|
||||
@ -43,6 +133,7 @@ export default function LoginCallBack() {
|
||||
}
|
||||
setIsAuthModalOpen(true);
|
||||
//return router.push(Module.getInstance().get().modules.pages.Folder.props.path);
|
||||
*/
|
||||
return;
|
||||
} catch (e: any) {
|
||||
if (e.http_status === 401 && e.message === "Email not found") {
|
||||
@ -54,7 +145,7 @@ export default function LoginCallBack() {
|
||||
return router.push(Module.getInstance().get().modules.pages.Login.props.path + "?error=1");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
const refreshToken = CookieService.getInstance().getCookie("leCoffreRefreshToken");
|
||||
if (!refreshToken) return router.push(Module.getInstance().get().modules.pages.Login.props.path + "?error=1");
|
||||
const isTokenRefreshed = await JwtService.getInstance().refreshToken(refreshToken);
|
||||
@ -64,15 +155,15 @@ export default function LoginCallBack() {
|
||||
return router.push(Module.getInstance().get().modules.pages.Subscription.pages.New.props.path);
|
||||
}
|
||||
if (isTokenRefreshed) {
|
||||
setIsAuthModalOpen(true);
|
||||
//setIsAuthModalOpen(true);
|
||||
//return router.push(Module.getInstance().get().modules.pages.Folder.props.path);
|
||||
return;
|
||||
}
|
||||
*/
|
||||
return router.push(Module.getInstance().get().modules.pages.Login.props.path + "?error=2");
|
||||
}
|
||||
getUser();
|
||||
}),
|
||||
[router];
|
||||
}, [router]);
|
||||
|
||||
return (
|
||||
<DefaultDoubleSidePage title={"Login"} image={backgroundImage}>
|
||||
@ -95,9 +186,40 @@ export default function LoginCallBack() {
|
||||
isOpen={isAuthModalOpen}
|
||||
onClose={() => {
|
||||
setIsAuthModalOpen(false);
|
||||
setIsConnected(true);
|
||||
setTimeout(() => {
|
||||
MessageBus.getInstance().initMessageListener();
|
||||
MessageBus.getInstance().isReady().then(async () => {
|
||||
const office: any = await getOffice(idNotUser);
|
||||
const role: any = await getRole(idNotUser);
|
||||
|
||||
const collaboratorData: any = {
|
||||
idNot: idNotUser.idNot,
|
||||
contact: idNotUser.contact,
|
||||
office: {
|
||||
uid: office.uid
|
||||
},
|
||||
role: {
|
||||
uid: role.uid
|
||||
}
|
||||
};
|
||||
const collaborator: any = await getCollaborator(collaboratorData);
|
||||
collaborator.office = office;
|
||||
collaborator.role = role;
|
||||
UserStore.instance.connect(collaborator);
|
||||
|
||||
MessageBus.getInstance().destroyMessageListener();
|
||||
/*
|
||||
if (jwt.rules && !jwt.rules.includes("GET folders")) {
|
||||
router.push(Module.getInstance().get().modules.pages.Subscription.pages.New.props.path);
|
||||
}
|
||||
*/
|
||||
router.push(Module.getInstance().get().modules.pages.Folder.props.path);
|
||||
});
|
||||
}, 100);
|
||||
}}
|
||||
/>}
|
||||
{isConnected && <Iframe />}
|
||||
</div>
|
||||
</DefaultDoubleSidePage>
|
||||
);
|
||||
|
@ -24,7 +24,7 @@ export default function RolesInformations() {
|
||||
const router = useRouter();
|
||||
let { roleUid } = router.query;
|
||||
|
||||
const [roleSelected, setRoleSelected] = useState<OfficeRole | null>(null);
|
||||
const [roleSelected, setRoleSelected] = useState<any | null>(null);
|
||||
const [rulesGroupsCheckboxes, setRulesGroupsCheckboxes] = useState<RuleGroupsCheckbox[]>([]);
|
||||
const [selectAll, setSelectAll] = useState<boolean>(false);
|
||||
|
||||
@ -169,7 +169,7 @@ export default function RolesInformations() {
|
||||
<Typography typo={ETypo.TITLE_H1}>Gestion des rôles</Typography>
|
||||
</div>
|
||||
<div className={classes["subtitle"]}>
|
||||
<Typography typo={ETypo.TITLE_H5}>{roleSelected?.name}</Typography>
|
||||
<Typography typo={ETypo.TITLE_H5}>{roleSelected?.label}</Typography>
|
||||
</div>
|
||||
<div className={classes["rights-container"]}>
|
||||
<div className={classes["rights-header"]}>
|
||||
|
@ -29,7 +29,7 @@ export interface ICustomerJwtPayload {
|
||||
|
||||
export default class JwtService {
|
||||
private static instance: JwtService;
|
||||
private constructor() {}
|
||||
private constructor() { }
|
||||
|
||||
public static getInstance() {
|
||||
return (this.instance ??= new this());
|
||||
@ -38,25 +38,25 @@ export default class JwtService {
|
||||
public getUserJwtPayload(): IUserJwtPayload | undefined {
|
||||
const accessToken = CookieService.getInstance().getCookie("leCoffreAccessToken");
|
||||
if (!accessToken) return;
|
||||
return jwt_decode(accessToken);
|
||||
return undefined; //jwt_decode(accessToken);
|
||||
}
|
||||
|
||||
public getCustomerJwtPayload(): ICustomerJwtPayload | undefined {
|
||||
const accessToken = CookieService.getInstance().getCookie("leCoffreAccessToken");
|
||||
if (!accessToken) return;
|
||||
return jwt_decode(accessToken);
|
||||
return undefined; //jwt_decode(accessToken);
|
||||
}
|
||||
|
||||
public decodeJwt(): IUserJwtPayload | undefined {
|
||||
const accessToken = CookieService.getInstance().getCookie("leCoffreAccessToken");
|
||||
if (!accessToken) return;
|
||||
return jwt_decode(accessToken);
|
||||
return undefined; //jwt_decode(accessToken);
|
||||
}
|
||||
|
||||
public decodeCustomerJwt(): ICustomerJwtPayload | undefined {
|
||||
const accessToken = CookieService.getInstance().getCookie("leCoffreAccessToken");
|
||||
if (!accessToken) return;
|
||||
return jwt_decode(accessToken);
|
||||
return undefined; //jwt_decode(accessToken);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -74,8 +74,7 @@ export default class JwtService {
|
||||
const headers = new Headers();
|
||||
headers.append("Authorization", `Bearer ${refreshToken}`);
|
||||
const response = await fetch(
|
||||
`${
|
||||
variables.BACK_API_PROTOCOL + variables.BACK_API_HOST + variables.BACK_API_ROOT_URL + variables.BACK_API_VERSION
|
||||
`${variables.BACK_API_PROTOCOL + variables.BACK_API_HOST + variables.BACK_API_ROOT_URL + variables.BACK_API_VERSION
|
||||
}/idnot/user/auth/refresh-token`,
|
||||
{ method: "POST", headers: headers },
|
||||
);
|
||||
@ -93,8 +92,7 @@ export default class JwtService {
|
||||
const headers = new Headers();
|
||||
headers.append("Authorization", `Bearer ${refreshToken}`);
|
||||
const response = await fetch(
|
||||
`${
|
||||
variables.BACK_API_PROTOCOL + variables.BACK_API_HOST + variables.BACK_API_ROOT_URL + variables.BACK_API_VERSION
|
||||
`${variables.BACK_API_PROTOCOL + variables.BACK_API_HOST + variables.BACK_API_ROOT_URL + variables.BACK_API_VERSION
|
||||
}/id360/customers/refresh-token`,
|
||||
{ method: "POST", headers: headers },
|
||||
);
|
||||
@ -122,8 +120,7 @@ export default class JwtService {
|
||||
const headers = new Headers();
|
||||
headers.append("Authorization", `Bearer ${refreshToken}`);
|
||||
const response = await fetch(
|
||||
`${
|
||||
variables.BACK_API_PROTOCOL + variables.BACK_API_HOST + variables.BACK_API_ROOT_URL + variables.BACK_API_VERSION
|
||||
`${variables.BACK_API_PROTOCOL + variables.BACK_API_HOST + variables.BACK_API_ROOT_URL + variables.BACK_API_VERSION
|
||||
}/idnot/user/auth/refresh-token`,
|
||||
{ method: "POST", headers: headers },
|
||||
);
|
||||
@ -141,8 +138,7 @@ export default class JwtService {
|
||||
const headers = new Headers();
|
||||
headers.append("Authorization", `Bearer ${refreshToken}`);
|
||||
const response = await fetch(
|
||||
`${
|
||||
variables.BACK_API_PROTOCOL + variables.BACK_API_HOST + variables.BACK_API_ROOT_URL + variables.BACK_API_VERSION
|
||||
`${variables.BACK_API_PROTOCOL + variables.BACK_API_HOST + variables.BACK_API_ROOT_URL + variables.BACK_API_VERSION
|
||||
}/id360/customers/refresh-token`,
|
||||
{ method: "POST", headers: headers },
|
||||
);
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
import CookieService from "@Front/Services/CookieService/CookieService";
|
||||
import EventEmitter from "@Front/Services/EventEmitter";
|
||||
import JwtService from "@Front/Services/JwtService/JwtService";
|
||||
|
||||
import User from "src/sdk/User";
|
||||
|
||||
@ -10,23 +9,16 @@ export default class UserStore {
|
||||
public static readonly instance = new this();
|
||||
protected readonly event = new EventEmitter();
|
||||
|
||||
private constructor() {}
|
||||
private constructor() { }
|
||||
|
||||
public isConnected(): boolean {
|
||||
return !!CookieService.getInstance().getCookie("leCoffreAccessToken");
|
||||
}
|
||||
|
||||
public getRole(): string | undefined {
|
||||
const decodedPayload = JwtService.getInstance().decodeJwt();
|
||||
return decodedPayload?.role;
|
||||
}
|
||||
|
||||
public async connect(accessToken: string, refreshToken: string) {
|
||||
public async connect(user: any) {
|
||||
try {
|
||||
//Save tokens in cookies
|
||||
CookieService.getInstance().setCookie("leCoffreAccessToken", accessToken);
|
||||
CookieService.getInstance().setCookie("leCoffreRefreshToken", refreshToken);
|
||||
|
||||
CookieService.getInstance().setCookie("leCoffreAccessToken", JSON.stringify(user));
|
||||
this.event.emit("connection", CookieService.getInstance().getCookie("leCoffreAccessToken"));
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@ -37,12 +29,10 @@ export default class UserStore {
|
||||
|
||||
public async disconnect() {
|
||||
try {
|
||||
//Remove tokens from cookies
|
||||
CookieService.getInstance().deleteCookie("leCoffreAccessToken");
|
||||
CookieService.getInstance().deleteCookie("leCoffreRefreshToken");
|
||||
|
||||
User.getInstance().clear();
|
||||
|
||||
//Remove tokens from cookies
|
||||
CookieService.getInstance().deleteCookie("leCoffreAccessToken");
|
||||
this.event.emit("disconnection", CookieService.getInstance().getCookie("leCoffreAccessToken"));
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@ -59,11 +49,7 @@ export default class UserStore {
|
||||
return () => this.event.off("connection", callback);
|
||||
}
|
||||
|
||||
public getAccessToken(): string {
|
||||
return CookieService.getInstance().getCookie("leCoffreAccessToken") || "";
|
||||
}
|
||||
|
||||
public getRefreshToken(): string {
|
||||
return CookieService.getInstance().getCookie("leCoffreRefreshToken") || "";
|
||||
public getUser(): any {
|
||||
return JSON.parse(CookieService.getInstance().getCookie("leCoffreAccessToken") || "");
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ export async function middleware(request: NextRequest) {
|
||||
const cookies = request.cookies.get("leCoffreAccessToken");
|
||||
if (!cookies) return NextResponse.redirect(new URL("/", request.url));
|
||||
|
||||
/*
|
||||
// Decode it
|
||||
const userDecodedToken = jwt_decode(cookies.value) as IUserJwtPayload;
|
||||
const customerDecodedToken = jwt_decode(cookies.value) as ICustomerJwtPayload;
|
||||
@ -23,6 +24,7 @@ export async function middleware(request: NextRequest) {
|
||||
if (customerDecodedToken.customerId && customerDecodedToken.exp < now) {
|
||||
return NextResponse.redirect(new URL("/id360/customer-callback", request.url));
|
||||
}
|
||||
*/
|
||||
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import Modal from '@Front/Components/DesignSystem/Modal';
|
||||
import Loader from '@Front/Components/DesignSystem/Loader';
|
||||
@ -54,19 +56,22 @@ export default function AuthModal({ isOpen, onClose }: AuthModalProps) {
|
||||
console.log('[AuthModal] handleMessage:', message);
|
||||
|
||||
switch (message.type) {
|
||||
case 'LISTENING':
|
||||
iframeRef.current.contentWindow!.postMessage({ type: 'REQUEST_LINK' }, targetOrigin);
|
||||
case 'LISTENING': {
|
||||
const messageId = `REQUEST_LINK_${uuidv4()}`;
|
||||
iframeRef.current.contentWindow!.postMessage({ type: 'REQUEST_LINK', messageId }, targetOrigin);
|
||||
setIsIframeReady(true);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'LINK_ACCEPTED':
|
||||
case 'LINK_ACCEPTED': {
|
||||
setShowIframe(false);
|
||||
|
||||
User.getInstance().setTokens(message.accessToken, message.refreshToken);
|
||||
iframeRef.current.contentWindow!.postMessage({ type: 'GET_PAIRING_ID', accessToken: message.accessToken }, targetOrigin);
|
||||
const messageId = `GET_PAIRING_ID_${uuidv4()}`;
|
||||
iframeRef.current.contentWindow!.postMessage({ type: 'GET_PAIRING_ID', accessToken: message.accessToken, messageId }, targetOrigin);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'GET_PAIRING_ID':
|
||||
case 'GET_PAIRING_ID': {
|
||||
User.getInstance().setPairingId(message.userPairingId);
|
||||
setAuthSuccess(true);
|
||||
|
||||
@ -78,6 +83,7 @@ export default function AuthModal({ isOpen, onClose }: AuthModalProps) {
|
||||
}, 500);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
window.addEventListener('message', handleMessage);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user