diff --git a/src/common/Api/LeCoffreApi/sdk/CollaboratorService.ts b/src/common/Api/LeCoffreApi/sdk/CollaboratorService.ts new file mode 100644 index 00000000..a071141d --- /dev/null +++ b/src/common/Api/LeCoffreApi/sdk/CollaboratorService.ts @@ -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 { + 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((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 { + // 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 { + // Check if we have valid cache + const item: any = this.getItem('_collaborators_', uid); + if (item) { + return Promise.resolve(item); + } + + return new Promise((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 { + return new Promise((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); + }); + } +} diff --git a/src/common/Api/LeCoffreApi/sdk/OfficeService.ts b/src/common/Api/LeCoffreApi/sdk/OfficeService.ts new file mode 100644 index 00000000..eeed8a9e --- /dev/null +++ b/src/common/Api/LeCoffreApi/sdk/OfficeService.ts @@ -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 { + 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((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 { + // 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 { + // Check if we have valid cache + const item: any = this.getItem('_offices_', uid); + if (item) { + return Promise.resolve(item); + } + + return new Promise((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 { + return new Promise((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); + }); + } +} diff --git a/src/front/Api/Auth/IdNot/index.ts b/src/front/Api/Auth/IdNot/index.ts index 5cd82e71..2aad0c33 100644 --- a/src/front/Api/Auth/IdNot/index.ts +++ b/src/front/Api/Auth/IdNot/index.ts @@ -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); diff --git a/src/front/Components/LayoutTemplates/DefaultCollaboratorDashboard/index.tsx b/src/front/Components/LayoutTemplates/DefaultCollaboratorDashboard/index.tsx index c9818720..cc6db955 100644 --- a/src/front/Components/LayoutTemplates/DefaultCollaboratorDashboard/index.tsx +++ b/src/front/Components/LayoutTemplates/DefaultCollaboratorDashboard/index.tsx @@ -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) => { @@ -49,10 +63,10 @@ export default function DefaultCollaboratorDashboard(props: IProps) { blocks={ collaborators ? collaborators.map((collaborator) => ({ - id: collaborator.uid!, - primaryText: collaborator.contact?.first_name + " " + collaborator.contact?.last_name, - isActive: collaborator.uid === collaboratorUid, - })) + id: collaborator.uid!, + primaryText: collaborator.contact?.first_name + " " + collaborator.contact?.last_name, + isActive: collaborator.uid === collaboratorUid, + })) : [] } /> diff --git a/src/front/Components/LayoutTemplates/DefaultRoleDashboard/index.tsx b/src/front/Components/LayoutTemplates/DefaultRoleDashboard/index.tsx index 8e6215a4..b701b441 100644 --- a/src/front/Components/LayoutTemplates/DefaultRoleDashboard/index.tsx +++ b/src/front/Components/LayoutTemplates/DefaultRoleDashboard/index.tsx @@ -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(null); + const [roles, setRoles] = React.useState(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, })) : [] diff --git a/src/front/Components/Layouts/Collaborators/CollaboratorInformations/index.tsx b/src/front/Components/Layouts/Collaborators/CollaboratorInformations/index.tsx index 9e6553b0..4babe364 100644 --- a/src/front/Components/Layouts/Collaborators/CollaboratorInformations/index.tsx +++ b/src/front/Components/Layouts/Collaborators/CollaboratorInformations/index.tsx @@ -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((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(); diff --git a/src/front/Components/Layouts/LoginCallback/index.tsx b/src/front/Components/Layouts/LoginCallback/index.tsx index 5d6c3c45..9117561f 100644 --- a/src/front/Components/Layouts/LoginCallback/index.tsx +++ b/src/front/Components/Layouts/LoginCallback/index.tsx @@ -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,89 +14,213 @@ 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 [isAuthModalOpen, setIsAuthModalOpen] = useState(false); + const router = useRouter(); + const [idNotUser, setIdNotUser] = useState(null); + const [isAuthModalOpen, setIsAuthModalOpen] = useState(false); + const [isConnected, setIsConnected] = useState(false); - useEffect(() => { - async function getUser() { - // TODO: review - // HACK: If start with http://local.lecoffreio.4nkweb:3000/authorized-client - // Replace with http://localhost:3000/authorized-client - if (window.location.href.startsWith('http://local.lecoffreio.4nkweb:3000/authorized-client')) { - window.location.href = window.location.href.replace('http://local.lecoffreio.4nkweb:3000/authorized-client', 'http://localhost:3000/authorized-client'); - return; - } + const getOffice = async (idNotUser: any) => { + return await new Promise((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'; - const code = router.query["code"]; - if (code) { - try { - const token = await Auth.getInstance().getIdnotJwt(code as string); - 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(); - if (!jwt) return router.push(Module.getInstance().get().modules.pages.Login.props.path + "?error=1"); - if (jwt.rules && !jwt.rules.includes("GET folders")) { - return router.push(Module.getInstance().get().modules.pages.Subscription.pages.New.props.path); - } - 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") { - return router.push(Module.getInstance().get().modules.pages.Login.props.path + "?error=3"); - } - if (e.http_status === 409) { - return router.push(Module.getInstance().get().modules.pages.Login.props.path + "?error=4"); - } - return router.push(Module.getInstance().get().modules.pages.Login.props.path + "?error=1"); - } - } + OfficeService.createOffice(officeData, validatorId).then((process: any) => { + if (process) { + const office: any = process.processData; + resolve(office); + } + }); + } + }); + }); + }; - 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); - const jwt = JwtService.getInstance().decodeJwt(); - if (!jwt) return router.push(Module.getInstance().get().modules.pages.Login.props.path + "?error=1"); - if (!jwt.rules.includes("GET folders")) { - return router.push(Module.getInstance().get().modules.pages.Subscription.pages.New.props.path); - } - if (isTokenRefreshed) { - 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]; + const getRole = async (idNotUser: any) => { + return await new Promise((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'; - return ( - -
-
- coffre - - Connexion à votre espace professionnel - -
+ RoleService.createRole(roleData, validatorId).then((process: any) => { + if (process) { + const role: any = process.processData; + resolve(role); + } + }); + } + }); + }); + }; - -
- - {isAuthModalOpen && { - setIsAuthModalOpen(false); - router.push(Module.getInstance().get().modules.pages.Folder.props.path); - }} - />} -
- - ); + const getCollaborator = async (collaboratorData: any) => { + return await new Promise((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 + if (window.location.href.startsWith('http://local.lecoffreio.4nkweb:3000/authorized-client')) { + window.location.href = window.location.href.replace('http://local.lecoffreio.4nkweb:3000/authorized-client', 'http://localhost:3000/authorized-client'); + return; + } + + const code = router.query["code"]; + if (code) { + try { + 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(); + if (!jwt) return router.push(Module.getInstance().get().modules.pages.Login.props.path + "?error=1"); + if (jwt.rules && !jwt.rules.includes("GET folders")) { + return router.push(Module.getInstance().get().modules.pages.Subscription.pages.New.props.path); + } + 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") { + return router.push(Module.getInstance().get().modules.pages.Login.props.path + "?error=3"); + } + if (e.http_status === 409) { + return router.push(Module.getInstance().get().modules.pages.Login.props.path + "?error=4"); + } + 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); + const jwt = JwtService.getInstance().decodeJwt(); + if (!jwt) return router.push(Module.getInstance().get().modules.pages.Login.props.path + "?error=1"); + if (!jwt.rules.includes("GET folders")) { + return router.push(Module.getInstance().get().modules.pages.Subscription.pages.New.props.path); + } + if (isTokenRefreshed) { + //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]); + + return ( + +
+
+ coffre + + Connexion à votre espace professionnel + +
+ + +
+ + {isAuthModalOpen && { + 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 &&