From e7a6af23be8d4a4225329a6e8b61781afbbf4a92 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Wed, 4 Oct 2023 16:52:07 +0200 Subject: [PATCH 1/6] :sparkles: Don't allow to ask documents on an anchored folder --- .../DesignSystem/UserFolder/index.tsx | 32 +++++++++++++------ .../FolderInformation/ClientSection/index.tsx | 3 ++ .../Folder/FolderInformation/index.tsx | 10 ++++-- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/front/Components/DesignSystem/UserFolder/index.tsx b/src/front/Components/DesignSystem/UserFolder/index.tsx index 3e2ca7da..62391808 100644 --- a/src/front/Components/DesignSystem/UserFolder/index.tsx +++ b/src/front/Components/DesignSystem/UserFolder/index.tsx @@ -16,6 +16,7 @@ import QuantityProgressBar from "../QuantityProgressBar"; import classes from "./classes.module.scss"; import DocumentList from "./DocumentList"; import UserFolderHeader from "./UserFolderHeader"; +import { AnchorStatus } from "@Front/Components/Layouts/Folder/FolderInformation"; type IProps = { customer: Customer; @@ -24,6 +25,7 @@ type IProps = { isArchived?: boolean; isOpened: boolean; onChange: (id: string) => void; + anchorStatus: AnchorStatus; }; type IState = { isOpenDeletionModal: boolean; @@ -89,25 +91,35 @@ export default class UserFolder extends React.Component { currentNumber={this.calculateDocumentsPercentageProgress()} />
- + {this.props.anchorStatus === AnchorStatus.NOT_ANCHORED && ( + + )} + 0 - ? "Vous avez des documents à valider." + ? this.props.anchorStatus !== AnchorStatus.NOT_ANCHORED + ? "" + : "Vous avez des documents à valider." : "Vous n'avez aucun document à valider" } openDeletionModal={this.openDeletionModal} folderUid={this.props.folder.uid!} /> - {!this.props.isArchived && ( + + {!this.props.isArchived && this.props.anchorStatus === AnchorStatus.NOT_ANCHORED && (
- {this.doesFolderHaveCustomer() && } + {this.doesFolderHaveCustomer() && ( + + )}
- {!this.doesFolderHaveCustomer() && } + {!this.doesFolderHaveCustomer() && ( + + )}
- + {this.props.anchorStatus === AnchorStatus.NOT_ANCHORED && ( + + + + )} ) : (
@@ -50,11 +52,13 @@ export default class ClientSection extends React.Component { Aucun client n'est associé au dossier.
- - - + {this.props.anchorStatus === AnchorStatus.NOT_ANCHORED && ( + + + + )}
)} From 575700761e981f707f0befc55b461dfcd79fe4de Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Wed, 4 Oct 2023 17:23:18 +0200 Subject: [PATCH 3/6] :sparkles: Refacto archive/restore --- .../Api/LeCoffreApi/Notary/Folders/Folders.ts | 25 +++++++++++++------ .../Folder/FolderInformation/index.tsx | 4 +-- .../FolderInformation/index.tsx | 4 +-- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/front/Api/LeCoffreApi/Notary/Folders/Folders.ts b/src/front/Api/LeCoffreApi/Notary/Folders/Folders.ts index 800d3c96..b7aa1342 100644 --- a/src/front/Api/LeCoffreApi/Notary/Folders/Folders.ts +++ b/src/front/Api/LeCoffreApi/Notary/Folders/Folders.ts @@ -1,7 +1,6 @@ import { type OfficeFolder } from "le-coffre-resources/dist/Notary"; import BaseNotary from "../BaseNotary"; -import EFolderStatus from "le-coffre-resources/dist/Customer/EFolderStatus"; // TODO Type get query params -> Where + inclue + orderby export interface IGetFoldersParams { @@ -97,20 +96,32 @@ export default class Folders extends BaseNotary { } } - public async archive(uid: string, body: Partial): Promise { - body.status = EFolderStatus.ARCHIVED; + public async archive(uid: string, archived_description: string): Promise { try { - return await this.put(uid, body); + const url = new URL(this.baseURl.concat(`/${uid}/archive`)); + try { + return await this.putRequest(url, { + archived_description, + }); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } } catch (err) { this.onError(err); return Promise.reject(err); } } - public async restore(uid: string, body: Partial): Promise { - body.status = EFolderStatus.LIVE; + public async restore(uid: string): Promise { try { - return await this.put(uid, body); + const url = new URL(this.baseURl.concat(`/${uid}/restore`)); + try { + return await this.putRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } } catch (err) { this.onError(err); return Promise.reject(err); diff --git a/src/front/Components/Layouts/Folder/FolderInformation/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/index.tsx index aa817ad9..640ad945 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/index.tsx @@ -393,9 +393,7 @@ class FolderInformationClass extends BasePage { private async onArchivedModalAccepted() { if (!this.props.selectedFolder) return; - const ressourceFolder = OfficeFolder.hydrate(this.props.selectedFolder); - ressourceFolder.archived_description = this.state.inputArchivedDescripton; - await Folders.getInstance().archive(this.props.selectedFolder.uid ?? "", ressourceFolder); + await Folders.getInstance().archive(this.props.selectedFolder.uid ?? "", this.state.inputArchivedDescripton); this.closeArchivedModal(); this.props.router.push(Module.getInstance().get().modules.pages.Folder.props.path); } diff --git a/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx b/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx index 8376f0a4..1eb5600c 100644 --- a/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx +++ b/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx @@ -123,9 +123,7 @@ class FolderInformationClass extends BasePage { private async restoreFolder() { if (!this.state.selectedFolder) return; - const ressourceFolder = OfficeFolder.hydrate(this.state.selectedFolder); - ressourceFolder.archived_description = null; - await Folders.getInstance().restore(this.state.selectedFolder.uid ?? "", ressourceFolder); + await Folders.getInstance().restore(this.state.selectedFolder.uid ?? ""); this.props.router.push( Module.getInstance() .get() From 9c14c1df3b692aa1a0f9322e9838c399e4d2263b Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Wed, 4 Oct 2023 17:28:26 +0200 Subject: [PATCH 4/6] :sparkles: Cannot modify folder after anchoring --- .../Components/DesignSystem/FolderBoxInformation/index.tsx | 4 +++- .../Components/Layouts/Folder/FolderInformation/index.tsx | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/front/Components/DesignSystem/FolderBoxInformation/index.tsx b/src/front/Components/DesignSystem/FolderBoxInformation/index.tsx index a2e95014..48529ede 100644 --- a/src/front/Components/DesignSystem/FolderBoxInformation/index.tsx +++ b/src/front/Components/DesignSystem/FolderBoxInformation/index.tsx @@ -8,11 +8,13 @@ import React from "react"; import Typography, { ITypo } from "../Typography"; import classes from "./classes.module.scss"; +import { AnchorStatus } from "@Front/Components/Layouts/Folder/FolderInformation"; type IProps = { folder: OfficeFolder; type: EFolderBoxInformationType; isArchived?: boolean; + anchorStatus: AnchorStatus; }; export enum EFolderBoxInformationType { @@ -34,7 +36,7 @@ export default function FolderBoxInformation(props: IProps) { return (
{renderContentByType(props.folder, type)}
- {!isArchived && ( + {!isArchived && props.anchorStatus === AnchorStatus.NOT_ANCHORED && ( edit informations diff --git a/src/front/Components/Layouts/Folder/FolderInformation/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/index.tsx index 640ad945..8d324b13 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/index.tsx @@ -97,11 +97,13 @@ class FolderInformationClass extends BasePage {
From f06539bb787644908a527bdcae5268943d9e054d Mon Sep 17 00:00:00 2001 From: OxSaitama Date: Wed, 4 Oct 2023 19:28:07 +0200 Subject: [PATCH 5/6] refacto votes and connexion --- package.json | 2 +- src/front/Api/Auth/IdNot/User.ts | 1 - src/front/Api/Auth/IdNot/index.ts | 1 - .../Components/DesignSystem/DepositOtherDocument/index.tsx | 5 ----- src/front/Components/Layouts/LoginCallback/index.tsx | 1 + .../Components/Layouts/Users/UserInformations/index.tsx | 2 +- 6 files changed, 3 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 7d306a4d..9d3fba5b 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "eslint-config-next": "13.2.4", "form-data": "^4.0.0", "jwt-decode": "^3.1.2", - "le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.89", + "le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.90", "next": "13.2.4", "prettier": "^2.8.7", "react": "18.2.0", diff --git a/src/front/Api/Auth/IdNot/User.ts b/src/front/Api/Auth/IdNot/User.ts index 96c54a77..1854979a 100644 --- a/src/front/Api/Auth/IdNot/User.ts +++ b/src/front/Api/Auth/IdNot/User.ts @@ -27,7 +27,6 @@ export default class User extends BaseApiService { } public async verifyJwt(jwt: string) { - console.log(this.baseURl); const url = new URL(`${this.baseURl}/verify-token/${jwt}`); try { return await this.postRequest(url); diff --git a/src/front/Api/Auth/IdNot/index.ts b/src/front/Api/Auth/IdNot/index.ts index 58cd9933..b358b6c8 100644 --- a/src/front/Api/Auth/IdNot/index.ts +++ b/src/front/Api/Auth/IdNot/index.ts @@ -16,7 +16,6 @@ export default class Auth extends BaseApiService { public async logOutWithIdNot() { const variables = FrontendVariables.getInstance(); const url = new URL(`${variables.IDNOT_BASE_URL}/user/auth/logout?post_logout_redirect_uri=${variables.FRONT_APP_HOST}`); - console.log(url.toString()) try { return await fetch(url); } catch (err) { diff --git a/src/front/Components/DesignSystem/DepositOtherDocument/index.tsx b/src/front/Components/DesignSystem/DepositOtherDocument/index.tsx index 7d84c26b..d2192944 100644 --- a/src/front/Components/DesignSystem/DepositOtherDocument/index.tsx +++ b/src/front/Components/DesignSystem/DepositOtherDocument/index.tsx @@ -121,7 +121,6 @@ export default class DepositOtherDocument extends React.Component 0 && (
{this.state.currentFiles.map((file) => { - console.log(file); const fileObj = file.file; @@ -237,9 +236,6 @@ export default class DepositOtherDocument extends React.Component file.index === parseInt(indexToRemove)); diff --git a/src/front/Components/Layouts/LoginCallback/index.tsx b/src/front/Components/Layouts/LoginCallback/index.tsx index 12d2293c..86b3a6e2 100644 --- a/src/front/Components/Layouts/LoginCallback/index.tsx +++ b/src/front/Components/Layouts/LoginCallback/index.tsx @@ -22,6 +22,7 @@ export default function LoginCallBack() { if (!code) return; 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); return router.push(Module.getInstance().get().modules.pages.Folder.props.path); } catch (e) { diff --git a/src/front/Components/Layouts/Users/UserInformations/index.tsx b/src/front/Components/Layouts/Users/UserInformations/index.tsx index 9962f139..9f393bd0 100644 --- a/src/front/Components/Layouts/Users/UserInformations/index.tsx +++ b/src/front/Components/Layouts/Users/UserInformations/index.tsx @@ -165,7 +165,7 @@ export default function UserInformations(props: IProps) { let vote = Vote.hydrate({ appointment: Appointment.hydrate({ uid: currentAppointment?.uid ?? undefined, - targeted_user: User.hydrate({ + user: User.hydrate({ uid: userSelected.uid, }), choice: superAdminModalType === "add" ? EVote.NOMINATE : EVote.DISMISS, From be8279dfa9e06bc7ac9da0d18f45a4012e1cb302 Mon Sep 17 00:00:00 2001 From: OxSaitama Date: Wed, 4 Oct 2023 20:58:41 +0200 Subject: [PATCH 6/6] fix archived folder --- .../FolderInformation/ClientSection/index.tsx | 3 + .../FolderInformation/classes.module.scss | 12 +++ .../FolderInformation/index.tsx | 86 ++++++++++++++++++- 3 files changed, 98 insertions(+), 3 deletions(-) diff --git a/src/front/Components/Layouts/FolderArchived/FolderInformation/ClientSection/index.tsx b/src/front/Components/Layouts/FolderArchived/FolderInformation/ClientSection/index.tsx index 2c2b7918..3052c261 100644 --- a/src/front/Components/Layouts/FolderArchived/FolderInformation/ClientSection/index.tsx +++ b/src/front/Components/Layouts/FolderArchived/FolderInformation/ClientSection/index.tsx @@ -3,9 +3,11 @@ import classes from "./classes.module.scss"; import { OfficeFolder } from "le-coffre-resources/dist/Notary"; import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography"; import UserFolder from "@Front/Components/DesignSystem/UserFolder"; +import { AnchorStatus } from "@Front/Components/Layouts/Folder/FolderInformation"; type IProps = { folder: OfficeFolder; + anchorStatus: AnchorStatus; }; type IState = { openedCustomer: string; @@ -49,6 +51,7 @@ export default class ClientSection extends React.Component { key={customer.uid} isOpened={this.state.openedCustomer === customer.uid} onChange={this.changeUserFolder} + anchorStatus={this.props.anchorStatus} isArchived /> ); diff --git a/src/front/Components/Layouts/FolderArchived/FolderInformation/classes.module.scss b/src/front/Components/Layouts/FolderArchived/FolderInformation/classes.module.scss index a1052297..d3eba151 100644 --- a/src/front/Components/Layouts/FolderArchived/FolderInformation/classes.module.scss +++ b/src/front/Components/Layouts/FolderArchived/FolderInformation/classes.module.scss @@ -86,4 +86,16 @@ .modal-title { margin-bottom: 24px; } +} + +.loader-container { + display: flex; + flex: 1; + align-items: center; + justify-content: center; + height: 100%; + .loader { + width: 40px; + height: 40px; + } } \ No newline at end of file diff --git a/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx b/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx index 1eb5600c..59fbcab7 100644 --- a/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx +++ b/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx @@ -13,12 +13,18 @@ import BasePage from "../../Base"; import classes from "./classes.module.scss"; import ClientSection from "./ClientSection"; import Link from "next/link"; +import { AnchorStatus } from "../../Folder/FolderInformation"; +import { useCallback, useEffect, useState } from "react"; +import OfficeFolderAnchors from "@Front/Api/LeCoffreApi/Notary/OfficeFolderAnchors/OfficeFolderAnchors"; +import Loader from "@Front/Components/DesignSystem/Loader"; type IProps = {}; type IPropsClass = IProps & { router: NextRouter; selectedFolderUid: string; + isLoading: boolean; + isAnchored: AnchorStatus; }; type IState = { @@ -46,6 +52,7 @@ class FolderInformationClass extends BasePage { .modules.pages.Folder.pages.EditCollaborators.props.path.replace("[folderUid]", this.props.selectedFolderUid); return ( + {!this.props.isLoading && (
{this.state.selectedFolder ? (
@@ -61,12 +68,14 @@ class FolderInformationClass extends BasePage {
{
{
- {this.doesFolderHaveCustomer() && } + {this.doesFolderHaveCustomer() && }
- {!this.doesFolderHaveCustomer() && } + {!this.doesFolderHaveCustomer() && }
)}
+ )} + {this.props.isLoading && ( +
+
+ +
+
+ )}
); } @@ -154,7 +172,69 @@ class FolderInformationClass extends BasePage { export default function FolderInformation(props: IProps) { const router = useRouter(); + const [isAnchored, setIsAnchored] = useState(AnchorStatus.NOT_ANCHORED); + const [isLoading, setIsLoading] = useState(true); + const [selectedFolder, setSelectedFolder] = useState(null); + let { folderUid } = router.query; folderUid = folderUid as string; - return ; + + const getAnchoringStatus = useCallback(async () => { + if(!folderUid) return; + setIsLoading(true); + try { + const anchorStatus = await OfficeFolderAnchors.getInstance().getByUid(folderUid as string); + setIsAnchored(anchorStatus.status === "VERIFIED_ON_CHAIN" ? AnchorStatus.VERIFIED_ON_CHAIN : AnchorStatus.ANCHORING); + } catch (e) { + setIsAnchored(AnchorStatus.NOT_ANCHORED); + } + setIsLoading(false); + }, [folderUid]); + + const getFolder = useCallback(async () => { + if (!folderUid) return; + setIsLoading(true); + const query = { + q: { + deed: { include: { deed_type: true } }, + office: true, + customers: { + include: { + contact: true, + documents: { + include: { + folder: true, + document_type: true, + files: true, + }, + }, + }, + }, + documents: { + include: { + depositor: { + include: { + contact: true, + }, + }, + }, + }, + folder_anchor: true, + }, + }; + const folder = await Folders.getInstance().getByUid(folderUid as string, query); + if (folder) { + setSelectedFolder(folder); + getAnchoringStatus(); + } + + setIsLoading(false); + }, [folderUid, getAnchoringStatus]); + + useEffect(() => { + setIsLoading(true); + getFolder(); + }, [getFolder]); + + return ; }