diff --git a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/index.tsx index 2f4e24d6..4d6cbb20 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/index.tsx @@ -38,6 +38,13 @@ const header: readonly IHead[] = [ }, ]; +const tradDocumentStatus: Record = { + [EDocumentStatus.ASKED]: "Demandé", + [EDocumentStatus.DEPOSITED]: "À valider", + [EDocumentStatus.VALIDATED]: "Validé", + [EDocumentStatus.REFUSED]: "Refusé", +}; + export default function DocumentTables(props: IProps) { const { documents: documentsProps } = props; const [documents, setDocuments] = useState(documentsProps); @@ -99,7 +106,11 @@ export default function DocumentTables(props: IProps) { key: document.uid, document_type: document.document_type?.name ?? "_", document_status: ( - + ), created_at: document.created_at ? new Date(document.created_at).toLocaleDateString() : "_", actions: openDeleteAskedDocumentModal(document.uid)} />} />, @@ -118,7 +129,11 @@ export default function DocumentTables(props: IProps) { key: document.uid, document_type: document.document_type?.name ?? "_", document_status: ( - + ), created_at: document.created_at, actions: onPreview(document)} icon={} />, @@ -137,7 +152,11 @@ export default function DocumentTables(props: IProps) { key: document.uid, document_type: document.document_type?.name ?? "_", document_status: ( - + ), created_at: document.created_at, actions: ( @@ -161,7 +180,11 @@ export default function DocumentTables(props: IProps) { key: document.uid, document_type: document.document_type?.name ?? "_", document_status: ( - + ), created_at: document.created_at, actions: "", diff --git a/src/front/Components/Layouts/Folder/FolderInformation/FolderInformationOld/ClientSection/classes.module.scss b/src/front/Components/Layouts/Folder/FolderInformation/FolderInformationOld/ClientSection/classes.module.scss deleted file mode 100644 index 1ac3bba8..00000000 --- a/src/front/Components/Layouts/Folder/FolderInformation/FolderInformationOld/ClientSection/classes.module.scss +++ /dev/null @@ -1,25 +0,0 @@ -@import "@Themes/constants.scss"; - -.root { - width: 100%; - padding-bottom: 32px; - - .no-client { - display: flex; - justify-content: center; - align-items: center; - flex-direction: column; - padding: 72px; - - .title { - margin-bottom: 16px; - text-align: center; - } - } - - .client { - display: grid; - gap: 32px; - margin-bottom: 32px; - } -} diff --git a/src/front/Components/Layouts/Folder/FolderInformation/FolderInformationOld/ClientSection/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/FolderInformationOld/ClientSection/index.tsx deleted file mode 100644 index f0277861..00000000 --- a/src/front/Components/Layouts/Folder/FolderInformation/FolderInformationOld/ClientSection/index.tsx +++ /dev/null @@ -1,98 +0,0 @@ -import PlusIcon from "@Assets/Icons/plus.svg"; -import Button, { EButtonstyletype, EButtonVariant } from "@Front/Components/DesignSystem/Button"; -import Typography, { ETypo, ETypoColor } from "@Front/Components/DesignSystem/Typography"; -import UserFolder from "@Front/Components/DesignSystem/UserFolder"; -import { OfficeFolder } from "le-coffre-resources/dist/Notary"; -import Module from "@Front/Config/Module"; -import Link from "next/link"; -import React from "react"; - -import classes from "./classes.module.scss"; -import { AnchorStatus } from ".."; - -type IProps = { - folder: OfficeFolder; - anchorStatus: AnchorStatus; - getFolderCallback: () => Promise; - openedCustomer?: string; -}; -type IState = { - openedCustomer: string; -}; - -export default class ClientSection extends React.Component { - public constructor(props: IProps) { - super(props); - this.state = { - openedCustomer: this.props.openedCustomer ?? "", - }; - this.changeUserFolder = this.changeUserFolder.bind(this); - this.renderCustomerFolders = this.renderCustomerFolders.bind(this); - } - - public override render(): JSX.Element { - const navigatePath = Module.getInstance() - .get() - .modules.pages.Folder.pages.AddClient.props.path.replace("[folderUid]", this.props.folder.uid ?? ""); - return ( -
- {this.doesFolderHaveCustomer() ? ( - <> -
{this.renderCustomerFolders()}
- {this.props.anchorStatus === AnchorStatus.NOT_ANCHORED && ( - - - - )} - - ) : ( -
-
- - Aucun client n'est associé au dossier. - -
- {this.props.anchorStatus === AnchorStatus.NOT_ANCHORED && ( - - - - )} -
- )} -
- ); - } - - private renderCustomerFolders() { - const output = this.props.folder.customers?.map((customer) => { - if (!customer) return null; - return ( - - ); - }); - return output ?? null; - } - - private changeUserFolder(uid: string) { - this.setState({ - openedCustomer: uid === this.state.openedCustomer ? "" : uid, - }); - } - - private doesFolderHaveCustomer(): boolean { - if (!this.props.folder?.customers) return false; - return this.props.folder?.customers!.length > 0; - } -} diff --git a/src/front/Components/Layouts/Folder/FolderInformation/FolderInformationOld/classes.module.scss b/src/front/Components/Layouts/Folder/FolderInformation/FolderInformationOld/classes.module.scss deleted file mode 100644 index a274d91e..00000000 --- a/src/front/Components/Layouts/Folder/FolderInformation/FolderInformationOld/classes.module.scss +++ /dev/null @@ -1,113 +0,0 @@ -@import "@Themes/constants.scss"; - -.root { - display: flex; - align-items: center; - flex-direction: column; - min-height: 100%; - - .no-folder-selected { - width: 100%; - - .choose-a-folder { - margin-top: 96px; - text-align: center; - } - } - - .folder-informations { - width: 100%; - min-height: 100%; - display: flex; - justify-content: space-between; - align-items: center; - flex-direction: column; - flex-grow: 1; - - .folder-header { - width: 100%; - - .header { - margin-bottom: 32px; - width: 100%; - display: flex; - justify-content: space-between; - align-items: center; - - @media (max-width: $screen-m) { - flex-wrap: wrap; - - .title { - margin-bottom: 24px; - } - } - } - } - } - - .second-box { - margin-top: 24px; - margin-bottom: 32px; - } - - .progress-bar { - margin-bottom: 32px; - } - - .button-container { - width: 100%; - display: flex; - gap: 16px; - text-align: center; - justify-content: center; - - .delete-folder { - display: flex; - margin-left: 12px; - } - - @media (max-width: $screen-m) { - display: flex; - flex-direction: column; - - .delete-folder { - margin-left: 0; - margin-top: 12px; - - > * { - flex: 1; - } - } - - > * { - width: 100%; - } - } - } - - .modal-title { - margin-bottom: 24px; - } -} - -.validate-document-container { - .document-validating-container { - .validate-gif { - width: 100%; - height: 100%; - object-fit: contain; - } - } -} - -.loader-container { - display: flex; - flex: 1; - align-items: center; - justify-content: center; - height: 100%; - .loader { - width: 21px; - height: 21px; - } -} diff --git a/src/front/Components/Layouts/Folder/FolderInformation/FolderInformationOld/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/FolderInformationOld/index.tsx deleted file mode 100644 index 7d943dd7..00000000 --- a/src/front/Components/Layouts/Folder/FolderInformation/FolderInformationOld/index.tsx +++ /dev/null @@ -1,541 +0,0 @@ -import ChevronIcon from "@Assets/Icons/chevron.svg"; -import Folders from "@Front/Api/LeCoffreApi/Notary/Folders/Folders"; -import OfficeFolderAnchors from "@Front/Api/LeCoffreApi/Notary/OfficeFolderAnchors/OfficeFolderAnchors"; -import Button, { EButtonstyletype, EButtonVariant } from "@Front/Components/DesignSystem/Button"; -import FolderBoxInformation, { EFolderBoxInformationType } from "@Front/Components/DesignSystem/FolderBoxInformation"; -import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField"; -import QuantityProgressBar from "@Front/Components/DesignSystem/QuantityProgressBar"; -import Typography, { ETypo, ETypoColor } from "@Front/Components/DesignSystem/Typography"; -import DefaultNotaryDashboard from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; -import Module from "@Front/Config/Module"; -import { OfficeFolder } from "le-coffre-resources/dist/Notary"; -import { EDocumentStatus } from "le-coffre-resources/dist/Notary/Document"; -import Link from "next/link"; -import { NextRouter, useRouter } from "next/router"; -import { ChangeEvent, useCallback, useEffect, useState } from "react"; -import Image from "next/image"; -import ValidateAnchoringGif from "@Front/Assets/images/validate_anchoring.gif"; - -import BasePage from "../../../Base"; -import classes from "./classes.module.scss"; -import ClientSection from "./ClientSection"; -import Loader from "@Front/Components/DesignSystem/Loader"; -import Newsletter from "@Front/Components/DesignSystem/Newsletter"; -import Confirm from "@Front/Components/DesignSystem/OldModal/Confirm"; - -export enum AnchorStatus { - "VERIFIED_ON_CHAIN" = "VERIFIED_ON_CHAIN", - "ANCHORING" = "ANCHORING", - "NOT_ANCHORED" = "NOT_ANCHORED", -} - -type IProps = {}; - -type IPropsClass = IProps & { - router: NextRouter; - selectedFolderUid: string; - isAnchored: AnchorStatus; - isLoading: boolean; - selectedFolder: OfficeFolder | null; - getAnchoringStatus: () => Promise; - getFolderCallback: () => Promise; - openedCustomer?: string; -}; - -type IState = { - isArchivedModalOpen: boolean; - inputArchivedDescripton: string; - isValidateModalVisible: boolean; - hasValidateAnchoring: boolean; - isVerifDeleteModalVisible: boolean; - isPreventArchiveModalOpen: boolean; - loadingAnchoring: boolean; -}; -class FolderInformationClass extends BasePage { - public constructor(props: IPropsClass) { - super(props); - this.state = { - isArchivedModalOpen: false, - inputArchivedDescripton: "", - isValidateModalVisible: false, - hasValidateAnchoring: false, - isVerifDeleteModalVisible: false, - isPreventArchiveModalOpen: false, - loadingAnchoring: false, - }; - this.openArchivedModal = this.openArchivedModal.bind(this); - this.closeArchivedModal = this.closeArchivedModal.bind(this); - this.onArchivedModalAccepted = this.onArchivedModalAccepted.bind(this); - this.onPreventArchiveModalAccepted = this.onPreventArchiveModalAccepted.bind(this); - this.getCompletionNumber = this.getCompletionNumber.bind(this); - this.onArchivedDescriptionInputChange = this.onArchivedDescriptionInputChange.bind(this); - this.deleteFolder = this.deleteFolder.bind(this); - this.closeModal = this.closeModal.bind(this); - this.validateAnchoring = this.validateAnchoring.bind(this); - this.openValidateModal = this.openValidateModal.bind(this); - this.openVerifDeleteFolder = this.openVerifDeleteFolder.bind(this); - this.closeVerifDeleteFolder = this.closeVerifDeleteFolder.bind(this); - this.closePreventArchiveModal = this.closePreventArchiveModal.bind(this); - } - - // TODO: Message if the user has not created any folder yet - // TODO: get the selected folder from the api in componentDidMount - public override render(): JSX.Element { - const redirectPathEditCollaborators = Module.getInstance() - .get() - .modules.pages.Folder.pages.EditCollaborators.props.path.replace("[folderUid]", this.props.selectedFolderUid); - return ( - - {!this.props.isLoading && ( -
- {this.props.selectedFolder ? ( -
-
-
-
- Informations du dossier -
- - - -
- -
- -
-
- -
- {this.doesFolderHaveCustomer() && ( - - )} -
- - {!this.doesFolderHaveCustomer() && ( - - )} - -
- - {this.everyDocumentValidated() && !this.props.isLoading && ( - <> - {this.props.isAnchored === AnchorStatus.NOT_ANCHORED && ( - - )} - {this.props.isAnchored === AnchorStatus.ANCHORING && ( - - )} - {this.props.isAnchored === AnchorStatus.VERIFIED_ON_CHAIN && ( - - )} - - )} - {this.canDeleteFolder() && ( - - - - )} -
- -
- Souhaitez-vous vraiment archiver le dossier ? -
- -
- -
- - Vous êtes en train d’archiver le dossier sans avoir l’ancré, êtes-vous sûr de vouloir le faire ? - -
- -
- -
- Cette action sera irréversible. -
-
- -
- ) : ( -
- Informations du dossier -
- - Sélectionnez un dossier - -
-
- )} -
- )} - {this.props.isLoading && ( -
-
- -
-
- )} - -
- {!this.state.hasValidateAnchoring && ( - - Les documents du dossier seront certifiés sur la blockchain. Pensez à bien télécharger l'ensemble des - documents du dossier ainsi que le fichier de preuve d'ancrage pour les mettre dans la GED de votre logiciel - de rédaction d'actes. - - )} - {this.state.hasValidateAnchoring && ( -
- - Veuillez revenir sur le dossier dans 5 minutes et rafraîchir la page pour télécharger le dossier de - preuve d'ancrage et le glisser dans la GED de votre logiciel de rédaction d'acte. - - Anchoring animation -
- )} -
-
-
- ); - } - - private closePreventArchiveModal() { - this.setState({ - isPreventArchiveModalOpen: false, - }); - } - - public openVerifDeleteFolder() { - this.setState({ - isVerifDeleteModalVisible: true, - }); - } - - public closeVerifDeleteFolder() { - this.setState({ - isVerifDeleteModalVisible: false, - }); - } - - private closeModal() { - this.setState({ - isValidateModalVisible: false, - }); - } - - private openValidateModal() { - this.setState({ - isValidateModalVisible: true, - }); - } - - private async validateAnchoring() { - this.setState({ - hasValidateAnchoring: true, - }); - - try { - const timeoutDelay = 9800; - await this.anchorFolder(); - setTimeout(() => { - this.setState({ - isValidateModalVisible: false, - }); - }, timeoutDelay); - - setTimeout(() => { - this.setState({ - hasValidateAnchoring: false, - }); - }, timeoutDelay + 1000); - } catch (e) { - this.setState({ - isValidateModalVisible: false, - hasValidateAnchoring: false, - }); - console.error(e); - } - } - - private async anchorFolder() { - if (!this.props.selectedFolder?.uid) return; - await OfficeFolderAnchors.getInstance().post(this.props.selectedFolder.uid); - this.props.getAnchoringStatus(); - } - - private async downloadAnchoringProof(uid?: string) { - if (!uid) return; - this.setState({ loadingAnchoring: true }); - try { - const file: Blob = await OfficeFolderAnchors.getInstance().download(uid); - const url = window.URL.createObjectURL(file); - const a = document.createElement("a"); - a.style.display = "none"; - a.href = url; - // the filename you want - a.download = `anchoring_proof_${this.props.selectedFolder?.folder_number}_${this.props.selectedFolder?.name}.zip`; - document.body.appendChild(a); - a.click(); - window.URL.revokeObjectURL(url); - this.setState({ loadingAnchoring: false }); - } catch (e) { - this.setState({ loadingAnchoring: false }); - console.error(e); - } - } - - private everyDocumentValidated(): boolean { - if (!this.props.selectedFolder?.documents) return false; - return ( - this.props.selectedFolder?.documents?.length >= 1 && - this.props.selectedFolder?.documents.every((document) => document.document_status === EDocumentStatus.VALIDATED) - ); - } - - private async deleteFolder() { - if (!this.props.selectedFolder?.uid) return; - await Folders.getInstance().delete(this.props.selectedFolder.uid); - this.props.router.push(Module.getInstance().get().modules.pages.Folder.props.path); - } - - private getCompletionNumber() { - const documents = this.props.selectedFolder?.documents; - if (!documents) return 0; - const totalDocuments = documents.length; - const refusedDocuments = documents.filter((document) => document.document_status === EDocumentStatus.REFUSED).length ?? 0; - const askedDocuments = - documents.filter( - (document) => document.document_status === EDocumentStatus.ASKED || document.document_status === EDocumentStatus.DEPOSITED, - ).length ?? 0; - const depositedDocuments = totalDocuments - askedDocuments - refusedDocuments; - const percentage = (depositedDocuments / totalDocuments) * 100; - return isNaN(percentage) ? 0 : percentage; - } - - private doesFolderHaveCustomer(): boolean { - if (!this.props.selectedFolder?.customers) return false; - return this.props.selectedFolder?.customers!.length > 0; - } - - private canDeleteFolder(): boolean { - return (this.props.selectedFolder?.customers?.length ?? 0) === 0 && (this.props.selectedFolder?.documents?.length ?? 0) === 0; - } - - private openArchivedModal(): void { - if (this.everyDocumentValidated() && this.props.isAnchored === AnchorStatus.VERIFIED_ON_CHAIN) { - this.setState({ isArchivedModalOpen: true }); - } else { - this.setState({ isPreventArchiveModalOpen: true }); - } - } - - private closeArchivedModal(): void { - this.setState({ isArchivedModalOpen: false }); - } - - private onArchivedDescriptionInputChange(e: ChangeEvent) { - this.setState({ inputArchivedDescripton: e.target.value }); - } - - private async onArchivedModalAccepted() { - if (!this.props.selectedFolder) return; - 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); - } - - private async onPreventArchiveModalAccepted() { - if (!this.props.selectedFolder) return; - await Folders.getInstance().archive(this.props.selectedFolder.uid ?? "", this.state.inputArchivedDescripton); - this.closePreventArchiveModal(); - this.props.router.push(Module.getInstance().get().modules.pages.Folder.props.path); - } -} - -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; - const customerUid = router.query["customerUid"] as string | undefined; - folderUid = folderUid as string; - - const getAnchoringStatus = useCallback(async () => { - if (!folderUid) return; - 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); - } - }, [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, - notes: { - include: { - customer: 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 ( - - ); -} diff --git a/src/front/Components/Layouts/Folder/FolderInformation/InformationSection/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/InformationSection/index.tsx index dd3ef56d..925a1b3f 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/InformationSection/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/InformationSection/index.tsx @@ -15,10 +15,11 @@ type IProps = { progress: number; onArchive: () => void; anchorStatus: AnchorStatus; + isArchived: boolean; }; export default function InformationSection(props: IProps) { - const { folder, progress, onArchive, anchorStatus } = props; + const { folder, progress, onArchive, anchorStatus, isArchived } = props; return (
@@ -66,12 +67,13 @@ export default function InformationSection(props: IProps) { )} - - } - variant={EIconButtonVariant.ERROR} - /> + {!isArchived && ( + } + variant={EIconButtonVariant.ERROR} + /> + )}
diff --git a/src/front/Components/Layouts/Folder/FolderInformation/AnchoringAlertInfo/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/elements/AnchoringAlertInfo/index.tsx similarity index 100% rename from src/front/Components/Layouts/Folder/FolderInformation/AnchoringAlertInfo/index.tsx rename to src/front/Components/Layouts/Folder/FolderInformation/elements/AnchoringAlertInfo/index.tsx diff --git a/src/front/Components/Layouts/Folder/FolderInformation/AnchoringAlertSuccess/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/elements/AnchoringAlertSuccess/index.tsx similarity index 79% rename from src/front/Components/Layouts/Folder/FolderInformation/AnchoringAlertSuccess/index.tsx rename to src/front/Components/Layouts/Folder/FolderInformation/elements/AnchoringAlertSuccess/index.tsx index 3ee5c80e..3cef33fb 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/AnchoringAlertSuccess/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/elements/AnchoringAlertSuccess/index.tsx @@ -5,10 +5,11 @@ import { ArrowDownOnSquareIcon, CheckIcon } from "@heroicons/react/24/outline"; type IProps = { onDownloadAnchoringProof: () => void; onArchive: () => void; + isArchived: boolean; }; export default function AnchoringAlertSuccess(props: IProps) { - const { onDownloadAnchoringProof, onArchive } = props; + const { onDownloadAnchoringProof, onArchive, isArchived } = props; return ( , onClick: onDownloadAnchoringProof, }} - secondButton={{ - children: "Archiver le dossier", - onClick: onArchive, - }} + secondButton={ + isArchived + ? undefined + : { + children: "Archiver le dossier", + onClick: onArchive, + } + } variant={EAlertVariant.SUCCESS} icon={} /> diff --git a/src/front/Components/Layouts/Folder/FolderInformation/AnchoringModal/classes.module.scss b/src/front/Components/Layouts/Folder/FolderInformation/elements/AnchoringModal/classes.module.scss similarity index 100% rename from src/front/Components/Layouts/Folder/FolderInformation/AnchoringModal/classes.module.scss rename to src/front/Components/Layouts/Folder/FolderInformation/elements/AnchoringModal/classes.module.scss diff --git a/src/front/Components/Layouts/Folder/FolderInformation/AnchoringModal/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/elements/AnchoringModal/index.tsx similarity index 94% rename from src/front/Components/Layouts/Folder/FolderInformation/AnchoringModal/index.tsx rename to src/front/Components/Layouts/Folder/FolderInformation/elements/AnchoringModal/index.tsx index 4d8abae4..6710946a 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/AnchoringModal/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/elements/AnchoringModal/index.tsx @@ -30,7 +30,7 @@ export default function AnchoringModal(props: IProps) { {!isAnchoring ? ( diff --git a/src/front/Components/Layouts/Folder/FolderInformation/ArchiveModal/classes.module.scss b/src/front/Components/Layouts/Folder/FolderInformation/elements/ArchiveModal/classes.module.scss similarity index 100% rename from src/front/Components/Layouts/Folder/FolderInformation/ArchiveModal/classes.module.scss rename to src/front/Components/Layouts/Folder/FolderInformation/elements/ArchiveModal/classes.module.scss diff --git a/src/front/Components/Layouts/Folder/FolderInformation/ArchiveModal/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/elements/ArchiveModal/index.tsx similarity index 100% rename from src/front/Components/Layouts/Folder/FolderInformation/ArchiveModal/index.tsx rename to src/front/Components/Layouts/Folder/FolderInformation/elements/ArchiveModal/index.tsx diff --git a/src/front/Components/Layouts/Folder/FolderInformation/DownloadAnchoringProofModal/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/elements/DownloadAnchoringProofModal/index.tsx similarity index 100% rename from src/front/Components/Layouts/Folder/FolderInformation/DownloadAnchoringProofModal/index.tsx rename to src/front/Components/Layouts/Folder/FolderInformation/elements/DownloadAnchoringProofModal/index.tsx diff --git a/src/front/Components/Layouts/Folder/FolderInformation/RequireAnchoringModal/classes.module.scss b/src/front/Components/Layouts/Folder/FolderInformation/elements/RequireAnchoringModal/classes.module.scss similarity index 100% rename from src/front/Components/Layouts/Folder/FolderInformation/RequireAnchoringModal/classes.module.scss rename to src/front/Components/Layouts/Folder/FolderInformation/elements/RequireAnchoringModal/classes.module.scss diff --git a/src/front/Components/Layouts/Folder/FolderInformation/RequireAnchoringModal/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/elements/RequireAnchoringModal/index.tsx similarity index 100% rename from src/front/Components/Layouts/Folder/FolderInformation/RequireAnchoringModal/index.tsx rename to src/front/Components/Layouts/Folder/FolderInformation/elements/RequireAnchoringModal/index.tsx diff --git a/src/front/Components/Layouts/Folder/FolderInformation/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/index.tsx index 2808c41b..c9770a16 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/index.tsx @@ -11,13 +11,13 @@ import classes from "./classes.module.scss"; import ClientView from "./ClientView"; import InformationSection from "./InformationSection"; import NoClientView from "./NoClientView"; -import AnchoringAlertInfo from "./AnchoringAlertInfo"; -import AnchoringModal from "./AnchoringModal"; +import AnchoringAlertInfo from "./elements/AnchoringAlertInfo"; +import AnchoringModal from "./elements/AnchoringModal"; import useOpenable from "@Front/Hooks/useOpenable"; -import AnchoringAlertSuccess from "./AnchoringAlertSuccess"; -import DownloadAnchoringProofModal from "./DownloadAnchoringProofModal"; -import RequireAnchoringModal from "./RequireAnchoringModal"; -import ArchiveModal from "./ArchiveModal"; +import AnchoringAlertSuccess from "./elements/AnchoringAlertSuccess"; +import DownloadAnchoringProofModal from "./elements/DownloadAnchoringProofModal"; +import RequireAnchoringModal from "./elements/RequireAnchoringModal"; +import ArchiveModal from "./elements/ArchiveModal"; export enum AnchorStatus { "VERIFIED_ON_CHAIN" = "VERIFIED_ON_CHAIN", @@ -25,9 +25,10 @@ export enum AnchorStatus { "NOT_ANCHORED" = "NOT_ANCHORED", } -type IProps = {}; +type IProps = { isArchived?: boolean }; export default function FolderInformation(props: IProps) { + const { isArchived = false } = props; const [anchorStatus, setAnchorStatus] = useState(AnchorStatus.NOT_ANCHORED); const [isLoading, setIsLoading] = useState(true); const [folder, setFolder] = useState(null); @@ -40,10 +41,13 @@ export default function FolderInformation(props: IProps) { const folderUid = params["folderUid"] as string; const progress = useMemo(() => { - const documents = folder?.documents; - if (!documents) return 0; - const total = documents.length; - const validatedDocuments = documents.filter((document) => document.document_status === EDocumentStatus.VALIDATED).length ?? 0; + let total = 0; + let validatedDocuments = 0; + folder?.customers?.forEach((customer) => { + const documents = customer.documents; + total += documents?.length ?? 0; + validatedDocuments += documents?.filter((document) => document.document_status === EDocumentStatus.VALIDATED).length ?? 0; + }); if (total === 0) return 0; const percentage = (validatedDocuments / total) * 100; return isNaN(percentage) ? 0 : percentage; @@ -121,15 +125,25 @@ export default function FolderInformation(props: IProps) { }, [anchorStatus, archiveModal, requireAnchoringModal]); return ( - + {!isLoading && (
- + {progress === 100 && anchorStatus === AnchorStatus.NOT_ANCHORED && ( )} {anchorStatus === AnchorStatus.VERIFIED_ON_CHAIN && ( - + )} {folder && !doesFolderHaveClient && } {folder && doesFolderHaveClient && } diff --git a/src/front/Components/Layouts/FolderArchived/FolderInformation/ClientSection/classes.module.scss b/src/front/Components/Layouts/FolderArchived/FolderInformation/ClientSection/classes.module.scss deleted file mode 100644 index 1ac3bba8..00000000 --- a/src/front/Components/Layouts/FolderArchived/FolderInformation/ClientSection/classes.module.scss +++ /dev/null @@ -1,25 +0,0 @@ -@import "@Themes/constants.scss"; - -.root { - width: 100%; - padding-bottom: 32px; - - .no-client { - display: flex; - justify-content: center; - align-items: center; - flex-direction: column; - padding: 72px; - - .title { - margin-bottom: 16px; - text-align: center; - } - } - - .client { - display: grid; - gap: 32px; - margin-bottom: 32px; - } -} diff --git a/src/front/Components/Layouts/FolderArchived/FolderInformation/ClientSection/index.tsx b/src/front/Components/Layouts/FolderArchived/FolderInformation/ClientSection/index.tsx deleted file mode 100644 index e3d4caae..00000000 --- a/src/front/Components/Layouts/FolderArchived/FolderInformation/ClientSection/index.tsx +++ /dev/null @@ -1,74 +0,0 @@ -import React from "react"; -import classes from "./classes.module.scss"; -import { OfficeFolder } from "le-coffre-resources/dist/Notary"; -import Typography, { ETypo, ETypoColor } 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; - getFolderCallback: () => Promise; -}; -type IState = { - openedCustomer: string; -}; - -export default class ClientSection extends React.Component { - public constructor(props: IProps) { - super(props); - this.state = { - openedCustomer: "", - }; - - this.changeUserFolder = this.changeUserFolder.bind(this); - } - - public override render(): JSX.Element { - return ( -
- {this.doesFolderHaveCustomer() ? ( - <> -
{this.renderCustomerFolders()}
- - ) : ( -
- - Aucun client dans ce dossier - -
- )} -
- ); - } - - private renderCustomerFolders() { - const output = this.props.folder.customers?.map((customer) => { - if (!customer) return null; - return ( - - ); - }); - return output ?? null; - } - - private changeUserFolder(uid: string) { - this.setState({ - openedCustomer: uid === this.state.openedCustomer ? "" : uid, - }); - } - - private doesFolderHaveCustomer(): boolean { - if (!this.props.folder?.customers) return false; - return this.props.folder?.customers!.length > 0; - } -} diff --git a/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx b/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx index 600ee8f6..6140b167 100644 --- a/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx +++ b/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx @@ -1,309 +1,5 @@ -import ChevronIcon from "@Assets/Icons/chevron.svg"; -import Folders from "@Front/Api/LeCoffreApi/Notary/Folders/Folders"; -import Button, { EButtonstyletype, EButtonVariant } from "@Front/Components/DesignSystem/Button"; -import FolderBoxInformation, { EFolderBoxInformationType } from "@Front/Components/DesignSystem/FolderBoxInformation"; -import QuantityProgressBar from "@Front/Components/DesignSystem/QuantityProgressBar"; -import Typography, { ETypo, ETypoColor } from "@Front/Components/DesignSystem/Typography"; -import DefaultNotaryDashboard from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; -import Module from "@Front/Config/Module"; -import { OfficeFolder } from "le-coffre-resources/dist/Notary"; -import { NextRouter, useRouter } from "next/router"; +import FolderInformation from "../../Folder/FolderInformation"; -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; - selectedFolder: OfficeFolder | null; - isAnchored: AnchorStatus; - getFolderCallback: () => Promise; -}; - -type IState = { - selectedFolder: OfficeFolder | null; - isArchivedModalOpen: boolean; - loadingAnchoring: boolean; -}; -class FolderInformationClass extends BasePage { - public constructor(props: IPropsClass) { - super(props); - this.state = { - selectedFolder: null, - isArchivedModalOpen: false, - loadingAnchoring: false, - }; - this.onSelectedFolder = this.onSelectedFolder.bind(this); - this.openArchivedModal = this.openArchivedModal.bind(this); - this.closeArchivedModal = this.closeArchivedModal.bind(this); - this.restoreFolder = this.restoreFolder.bind(this); - } - - // TODO: Message if the user has not created any folder yet - // TODO: get the selected folder from the api in componentDidMount - public override render(): JSX.Element { - const redirectPathEditCollaborators = Module.getInstance() - .get() - .modules.pages.Folder.pages.EditCollaborators.props.path.replace("[folderUid]", this.props.selectedFolderUid); - return ( - - {!this.props.isLoading && ( -
- {this.state.selectedFolder ? ( -
-
-
-
- Informations du dossier -
- - - -
- -
- -
-
- -
- -
- -
- {this.doesFolderHaveCustomer() && ( - - )} -
- - {!this.doesFolderHaveCustomer() && ( - - )} - -
- - {this.props.isAnchored === AnchorStatus.VERIFIED_ON_CHAIN && ( - - )} -
-
- ) : ( -
- Informations du dossier -
- - Aucun dossier sélectionné - -
-
- )} -
- )} - {this.props.isLoading && ( -
-
- -
-
- )} -
- ); - } - public override async componentDidMount() { - const folder = await this.getFolder(); - this.setState({ selectedFolder: folder }); - } - - private doesFolderHaveCustomer(): boolean { - return this.state.selectedFolder?.customers !== undefined; - } - - private onSelectedFolder(folder: OfficeFolder): void { - this.setState({ selectedFolder: folder }); - } - - private async restoreFolder() { - if (!this.state.selectedFolder) return; - await Folders.getInstance().restore(this.state.selectedFolder.uid ?? ""); - this.props.router.push( - Module.getInstance() - .get() - .modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.selectedFolderUid), - ); - } - - private openArchivedModal(): void { - this.setState({ isArchivedModalOpen: true }); - } - - private closeArchivedModal(): void { - this.setState({ isArchivedModalOpen: false }); - } - - private async downloadAnchoringProof(uid?: string) { - if (!uid) return; - this.setState({ loadingAnchoring: true }); - try { - const file: Blob = await OfficeFolderAnchors.getInstance().download(uid); - const url = window.URL.createObjectURL(file); - const a = document.createElement("a"); - a.style.display = "none"; - a.href = url; - // the filename you want - a.download = `anchoring_proof_${this.props.selectedFolder?.folder_number}_${this.props.selectedFolder?.name}.zip`; - document.body.appendChild(a); - a.click(); - window.URL.revokeObjectURL(url); - this.setState({ loadingAnchoring: false }); - } catch (e) { - this.setState({ loadingAnchoring: false }); - console.error(e); - } - } - - private async getFolder(): Promise { - const query = { - q: { - deed: { include: { deed_type: "true" } }, - office: "true", - customers: { include: { contact: true } }, - notes: "true", - }, - }; - const folder = await Folders.getInstance().getByUid(this.props.selectedFolderUid, query); - return folder; - } -} - -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; - - 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 ( - - ); +export default function FolderInformationArchived() { + return ; }