From 78cd1ec0b39713bdc87a1c0cd668b16365b40872 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Tue, 25 Jul 2023 10:36:16 +0200 Subject: [PATCH 01/13] :bug: Fixing build --- .../FolderBoxInformation/index.tsx | 6 ++-- .../DesignSystem/FolderContainer/index.tsx | 8 ++--- .../DesignSystem/FolderList/index.tsx | 12 ++++---- .../FolderListContainer/index.tsx | 16 +++++----- .../UserFolder/UserFolderHeader/index.tsx | 4 +-- .../DesignSystem/UserFolder/index.tsx | 6 ++-- .../DefaultNotaryDashboard/index.tsx | 19 ++---------- .../Layouts/Folder/AskDocuments/index.tsx | 19 ++++-------- .../FolderInformation/ClientSection/index.tsx | 7 ++--- .../Folder/FolderInformation/index.tsx | 10 +++---- .../Layouts/Folder/UpdateClient/index.tsx | 15 +++++----- .../UpdateFolderCollaborators/index.tsx | 8 ++--- .../Folder/UpdateFolderDescription/index.tsx | 9 +++--- .../Folder/UpdateFolderMetadata/index.tsx | 12 ++++---- src/front/Components/Layouts/Folder/index.tsx | 7 +++-- .../FolderInformation/ClientSection/index.tsx | 4 +-- .../FolderInformation/index.tsx | 8 ++--- .../UpdateFolderMetadata/index.tsx | 13 ++++---- .../Layouts/FolderArchived/index.tsx | 10 ++++--- src/front/Config/Module/preprod.json | 30 +++++++++++++++++++ src/front/Config/Module/production.json | 30 +++++++++++++++++++ src/front/Config/Module/staging.json | 30 +++++++++++++++++++ 22 files changed, 179 insertions(+), 104 deletions(-) diff --git a/src/front/Components/DesignSystem/FolderBoxInformation/index.tsx b/src/front/Components/DesignSystem/FolderBoxInformation/index.tsx index 27b61983..a2e95014 100644 --- a/src/front/Components/DesignSystem/FolderBoxInformation/index.tsx +++ b/src/front/Components/DesignSystem/FolderBoxInformation/index.tsx @@ -1,7 +1,7 @@ import PenICon from "@Assets/Icons/pen.svg"; -import { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; import Module from "@Front/Config/Module"; import classNames from "classnames"; +import { OfficeFolder } from "le-coffre-resources/dist/Notary"; import Image from "next/image"; import Link from "next/link"; import React from "react"; @@ -10,7 +10,7 @@ import Typography, { ITypo } from "../Typography"; import classes from "./classes.module.scss"; type IProps = { - folder: IDashBoardFolder; + folder: OfficeFolder; type: EFolderBoxInformationType; isArchived?: boolean; }; @@ -42,7 +42,7 @@ export default function FolderBoxInformation(props: IProps) { ); - function renderContentByType(folder: IDashBoardFolder, type: EFolderBoxInformationType) { + function renderContentByType(folder: OfficeFolder, type: EFolderBoxInformationType) { switch (type) { case EFolderBoxInformationType.DESCRIPTION: return ( diff --git a/src/front/Components/DesignSystem/FolderContainer/index.tsx b/src/front/Components/DesignSystem/FolderContainer/index.tsx index 0dbdf597..b35a87d9 100644 --- a/src/front/Components/DesignSystem/FolderContainer/index.tsx +++ b/src/front/Components/DesignSystem/FolderContainer/index.tsx @@ -1,16 +1,16 @@ import ChevronIcon from "@Assets/Icons/chevron.svg"; -import { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; +import { OfficeFolder } from "le-coffre-resources/dist/Notary"; +import { EDocumentStatus } from "le-coffre-resources/dist/Notary/Document"; import Image from "next/image"; import React from "react"; import Typography, { ITypo } from "../Typography"; import WarningBadge from "../WarningBadge"; import classes from "./classes.module.scss"; -import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document"; type IProps = { - folder: IDashBoardFolder; - onSelectedFolder?: (folder: IDashBoardFolder) => void; + folder: OfficeFolder; + onSelectedFolder?: (folder: OfficeFolder) => void; }; type IState = {}; diff --git a/src/front/Components/DesignSystem/FolderList/index.tsx b/src/front/Components/DesignSystem/FolderList/index.tsx index a472a435..c319582a 100644 --- a/src/front/Components/DesignSystem/FolderList/index.tsx +++ b/src/front/Components/DesignSystem/FolderList/index.tsx @@ -1,18 +1,18 @@ -import { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; import Module from "@Front/Config/Module"; -import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document"; +import classNames from "classnames"; +import { OfficeFolder } from "le-coffre-resources/dist/Notary"; +import { EDocumentStatus } from "le-coffre-resources/dist/Notary/Document"; import Link from "next/link"; import { useRouter } from "next/router"; import React from "react"; import FolderContainer from "../FolderContainer"; import classes from "./classes.module.scss"; -import classNames from "classnames"; type IProps = { - folders: IDashBoardFolder[]; + folders: OfficeFolder[]; isArchived: boolean; - onSelectedFolder?: (folder: IDashBoardFolder) => void; + onSelectedFolder?: (folder: OfficeFolder) => void; onCloseLeftSide?: () => void; }; @@ -27,7 +27,7 @@ class FolderListClass extends React.Component { ? Module.getInstance().get().modules.pages.Folder.pages.FolderArchived.pages.FolderInformation.props.path : Module.getInstance().get().modules.pages.Folder.pages.FolderInformation.props.path; public override render(): JSX.Element { - return
{this.renderFolders()}
; + return
{this.renderFolders()}
; } private renderFolders(): JSX.Element[] { diff --git a/src/front/Components/DesignSystem/FolderListContainer/index.tsx b/src/front/Components/DesignSystem/FolderListContainer/index.tsx index 2302050b..77f54d7d 100644 --- a/src/front/Components/DesignSystem/FolderListContainer/index.tsx +++ b/src/front/Components/DesignSystem/FolderListContainer/index.tsx @@ -1,19 +1,19 @@ -import { IDashBoardFolder } 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 React from "react"; +import BlockList, { IBlock } from "../BlockList"; import Button from "../Button"; import SearchBar from "../SearchBar"; import classes from "./classes.module.scss"; -import BlockList, { IBlock } from "../BlockList"; -import { NextRouter, useRouter } from "next/router"; -import { EDocumentStatus } from "le-coffre-resources/dist/SuperAdmin/Document"; type IProps = { - folders: IDashBoardFolder[]; + folders: OfficeFolder[]; isArchived: boolean; - onSelectedFolder?: (folder: IDashBoardFolder) => void; + onSelectedFolder?: (folder: OfficeFolder) => void; onCloseLeftSide?: () => void; }; @@ -22,7 +22,7 @@ type IPropsClass = IProps & { }; type IState = { - filteredFolders: IDashBoardFolder[]; + filteredFolders: OfficeFolder[]; }; class FolderListContainerClass extends React.Component { @@ -97,7 +97,7 @@ class FolderListContainerClass extends React.Component { } private filterFolders(value: string): void { - const filteredFolders: IDashBoardFolder[] = this.props.folders.filter((folder) => { + const filteredFolders: OfficeFolder[] = this.props.folders.filter((folder) => { const name = folder.name.toLowerCase(); const number = folder.folder_number.toLowerCase(); diff --git a/src/front/Components/DesignSystem/UserFolder/UserFolderHeader/index.tsx b/src/front/Components/DesignSystem/UserFolder/UserFolderHeader/index.tsx index 1568a2c5..e6060bfe 100644 --- a/src/front/Components/DesignSystem/UserFolder/UserFolderHeader/index.tsx +++ b/src/front/Components/DesignSystem/UserFolder/UserFolderHeader/index.tsx @@ -1,5 +1,5 @@ import PenIcon from "@Assets/Icons/pen.svg"; -import { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; +import { OfficeFolder } from "le-coffre-resources/dist/Notary"; import Module from "@Front/Config/Module"; import { Customer } from "le-coffre-resources/dist/Notary"; import Image from "next/image"; @@ -13,7 +13,7 @@ import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document"; type IProps = { customer: Customer; - folder: IDashBoardFolder; + folder: OfficeFolder; isArchived?: boolean; }; type IState = {}; diff --git a/src/front/Components/DesignSystem/UserFolder/index.tsx b/src/front/Components/DesignSystem/UserFolder/index.tsx index 2a95a9b8..805f9033 100644 --- a/src/front/Components/DesignSystem/UserFolder/index.tsx +++ b/src/front/Components/DesignSystem/UserFolder/index.tsx @@ -1,11 +1,11 @@ import ChevronIcon from "@Assets/Icons/chevron.svg"; import PlusIcon from "@Assets/Icons/plus.svg"; import Documents from "@Front/Api/LeCoffreApi/SuperAdmin/Documents/Documents"; -import { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; import Module from "@Front/Config/Module"; import classNames from "classnames"; -import Customer, { Document } from "le-coffre-resources/dist/Customer"; import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document"; +import { Customer, Document } from "le-coffre-resources/dist/Notary"; +import { OfficeFolder } from "le-coffre-resources/dist/Notary"; import Image from "next/image"; import Link from "next/link"; import React from "react"; @@ -20,7 +20,7 @@ import UserFolderHeader from "./UserFolderHeader"; type IProps = { customer: Customer; animationDelay?: number; - folder: IDashBoardFolder; + folder: OfficeFolder; isArchived?: boolean; isOpened: boolean; onChange: (id: string) => void; diff --git a/src/front/Components/LayoutTemplates/DefaultNotaryDashboard/index.tsx b/src/front/Components/LayoutTemplates/DefaultNotaryDashboard/index.tsx index bacb0a23..911d7385 100644 --- a/src/front/Components/LayoutTemplates/DefaultNotaryDashboard/index.tsx +++ b/src/front/Components/LayoutTemplates/DefaultNotaryDashboard/index.tsx @@ -7,8 +7,8 @@ import Version from "@Front/Components/DesignSystem/Version"; import BackArrow from "@Front/Components/Elements/BackArrow"; import WindowStore from "@Front/Stores/WindowStore"; import classNames from "classnames"; -import { OfficeFolder } from "le-coffre-resources/dist/Customer"; import EFolderStatus from "le-coffre-resources/dist/Customer/EFolderStatus"; +import { OfficeFolder } from "le-coffre-resources/dist/Notary"; import Image from "next/image"; import React, { ReactNode } from "react"; @@ -18,30 +18,17 @@ type IProps = { title: string; children?: ReactNode; isArchived?: boolean; - onSelectedFolder: (folder: IDashBoardFolder) => void; + onSelectedFolder: (folder: OfficeFolder) => void; hasBackArrow: boolean; backArrowUrl?: string; mobileBackText?: string; }; type IState = { - folders: IDashBoardFolder[] | null; + folders: OfficeFolder[] | null; isLeftSideOpen: boolean; leftSideCanBeClosed: boolean; }; -export type IDashBoardFolder = { - uid?: OfficeFolder["uid"]; - name: OfficeFolder["name"]; - folder_number: OfficeFolder["folder_number"]; - documents?: OfficeFolder["documents"]; - description: OfficeFolder["description"]; - deed?: OfficeFolder["deed"]; - created_at: OfficeFolder["created_at"]; - customers?: OfficeFolder["customers"]; - archived_description: OfficeFolder["archived_description"]; - status: OfficeFolder["status"]; -}; - export default class DefaultNotaryDashboard extends React.Component { private onWindowResize = () => {}; public static defaultProps: Partial = { diff --git a/src/front/Components/Layouts/Folder/AskDocuments/index.tsx b/src/front/Components/Layouts/Folder/AskDocuments/index.tsx index eedec845..67c19ab5 100644 --- a/src/front/Components/Layouts/Folder/AskDocuments/index.tsx +++ b/src/front/Components/Layouts/Folder/AskDocuments/index.tsx @@ -6,20 +6,20 @@ import Folders from "@Front/Api/LeCoffreApi/SuperAdmin/Folders/Folders"; import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import CheckBox from "@Front/Components/DesignSystem/CheckBox"; import Form from "@Front/Components/DesignSystem/Form"; +import { IOption } from "@Front/Components/DesignSystem/Form/SelectField"; +import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField"; +import TextField from "@Front/Components/DesignSystem/Form/TextField"; import Confirm from "@Front/Components/DesignSystem/Modal/Confirm"; import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography"; import BackArrow from "@Front/Components/Elements/BackArrow"; import DefaultNotaryDashboard from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; import Module from "@Front/Config/Module"; -import { OfficeFolder } from "le-coffre-resources/dist/Customer"; +import { OfficeFolder } from "le-coffre-resources/dist/Notary"; import { NextRouter, useRouter } from "next/router"; import React from "react"; import BasePage from "../../Base"; import classes from "./classes.module.scss"; -import { IOption } from "@Front/Components/DesignSystem/Form/SelectField"; -import TextField from "@Front/Components/DesignSystem/Form/TextField"; -import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField"; type IProps = {}; type IPropsClass = IProps & { @@ -110,11 +110,7 @@ class AskDocumentsClass extends BasePage { cancelText={"Annuler"} confirmText={"Ajouter"}>
- + { const oldDocumentsType = this.state.folder?.deed?.document_types!; await Deeds.getInstance().put(this.state.folder?.deed?.uid!, { - document_types: [ - ...oldDocumentsType, - documentType, - ], + document_types: [...oldDocumentsType, documentType], }); await this.loadData(); diff --git a/src/front/Components/Layouts/Folder/FolderInformation/ClientSection/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/ClientSection/index.tsx index aa5f46b0..95e24b4d 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/ClientSection/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/ClientSection/index.tsx @@ -2,7 +2,7 @@ import PlusIcon from "@Assets/Icons/plus.svg"; import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography"; import UserFolder from "@Front/Components/DesignSystem/UserFolder"; -import { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; +import { OfficeFolder } from "le-coffre-resources/dist/Notary"; import Module from "@Front/Config/Module"; import Link from "next/link"; import React from "react"; @@ -10,7 +10,7 @@ import React from "react"; import classes from "./classes.module.scss"; type IProps = { - folder: IDashBoardFolder; + folder: OfficeFolder; }; type IState = { openedCustomer: string; @@ -75,13 +75,12 @@ export default class ClientSection extends React.Component { 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/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/index.tsx index 4f335c3b..b2dfb2ec 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/index.tsx @@ -6,9 +6,9 @@ import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField"; import Confirm from "@Front/Components/DesignSystem/Modal/Confirm"; import QuantityProgressBar from "@Front/Components/DesignSystem/QuantityProgressBar"; import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography"; -import DefaultNotaryDashboard, { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; +import DefaultNotaryDashboard from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; import Module from "@Front/Config/Module"; -import { OfficeFolder } from "le-coffre-resources/dist/Customer"; +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"; @@ -26,7 +26,7 @@ type IPropsClass = IProps & { }; type IState = { - selectedFolder: IDashBoardFolder | null; + selectedFolder: OfficeFolder | null; isArchivedModalOpen: boolean; inputArchivedDescripton: string; }; @@ -133,7 +133,7 @@ class FolderInformationClass extends BasePage { } public override async componentDidMount() { this.setState({ - selectedFolder: (await this.getFolder()) as IDashBoardFolder, + selectedFolder: (await this.getFolder()) as OfficeFolder, }); } @@ -159,7 +159,7 @@ class FolderInformationClass extends BasePage { return this.state.selectedFolder?.customers!.length > 0; } - private onSelectedFolder(folder: IDashBoardFolder): void { + private onSelectedFolder(folder: OfficeFolder): void { this.setState({ selectedFolder: folder }); } diff --git a/src/front/Components/Layouts/Folder/UpdateClient/index.tsx b/src/front/Components/Layouts/Folder/UpdateClient/index.tsx index 0fd59e0d..0905f976 100644 --- a/src/front/Components/Layouts/Folder/UpdateClient/index.tsx +++ b/src/front/Components/Layouts/Folder/UpdateClient/index.tsx @@ -1,5 +1,3 @@ -import BasePage from "../../Base"; -import classes from "./classes.module.scss"; import Customers from "@Front/Api/LeCoffreApi/SuperAdmin/Customers/Customers"; import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import Form from "@Front/Components/DesignSystem/Form"; @@ -7,13 +5,16 @@ import TextField from "@Front/Components/DesignSystem/Form/TextField"; import Confirm from "@Front/Components/DesignSystem/Modal/Confirm"; import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography"; import BackArrow from "@Front/Components/Elements/BackArrow"; -import DefaultNotaryDashboard, { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; +import DefaultNotaryDashboard from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; import Module from "@Front/Config/Module"; -import Customer, { Contact } from "le-coffre-resources/dist/Customer"; +import { Contact, Customer, OfficeFolder } from "le-coffre-resources/dist/Notary"; import Link from "next/link"; import { NextRouter, useRouter } from "next/router"; import { ChangeEvent } from "react"; +import BasePage from "../../Base"; +import classes from "./classes.module.scss"; + type IProps = {}; type IPropsClass = IProps & { @@ -22,7 +23,7 @@ type IPropsClass = IProps & { customerUid: string; }; type IState = { - selectedFolder: IDashBoardFolder | null; + selectedFolder: OfficeFolder | null; inputNameValue: string; inputFirstNameValue: string; inputEmailValue: string; @@ -31,7 +32,7 @@ type IState = { doesInputHaveValues: boolean; inputBirthdate: Date | null; inputAddress: string; - folder: IDashBoardFolder | null; + folder: OfficeFolder | null; customer: Customer | null; }; class UpdateClientClass extends BasePage { @@ -222,7 +223,7 @@ class UpdateClientClass extends BasePage { this.setState({ inputPhoneNumberValue: event.target.value }); } - private onSelectedFolder(folder: IDashBoardFolder): void { + private onSelectedFolder(folder: OfficeFolder): void { this.setState({ selectedFolder: folder }); } diff --git a/src/front/Components/Layouts/Folder/UpdateFolderCollaborators/index.tsx b/src/front/Components/Layouts/Folder/UpdateFolderCollaborators/index.tsx index 02f600ba..c207f938 100644 --- a/src/front/Components/Layouts/Folder/UpdateFolderCollaborators/index.tsx +++ b/src/front/Components/Layouts/Folder/UpdateFolderCollaborators/index.tsx @@ -7,9 +7,9 @@ import MultiSelect from "@Front/Components/DesignSystem/MultiSelect"; import RadioBox from "@Front/Components/DesignSystem/RadioBox"; import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography"; import BackArrow from "@Front/Components/Elements/BackArrow"; -import DefaultNotaryDashboard, { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; +import DefaultNotaryDashboard from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; import Module from "@Front/Config/Module"; -import User from "le-coffre-resources/dist/Notary"; +import User, { OfficeFolder } from "le-coffre-resources/dist/Notary"; import Link from "next/link"; import { NextRouter, useRouter } from "next/router"; @@ -21,7 +21,7 @@ type IPropsClass = { router: NextRouter; }; type IState = { - selectedFolder: IDashBoardFolder | null; + selectedFolder: OfficeFolder | null; selectedOption?: ERadioBoxValue; availableCollaborators: User[]; selectedCollaborators: readonly IOption[]; @@ -163,7 +163,7 @@ class UpdateFolderCollaboratorsClass extends BasePage { }); } - private onSelectedFolder(folder: IDashBoardFolder): void { + private onSelectedFolder(folder: OfficeFolder): void { this.setState({ selectedFolder: folder }); } diff --git a/src/front/Components/Layouts/Folder/UpdateFolderDescription/index.tsx b/src/front/Components/Layouts/Folder/UpdateFolderDescription/index.tsx index 20d12138..fb572b5d 100644 --- a/src/front/Components/Layouts/Folder/UpdateFolderDescription/index.tsx +++ b/src/front/Components/Layouts/Folder/UpdateFolderDescription/index.tsx @@ -1,16 +1,17 @@ +import Folders from "@Front/Api/LeCoffreApi/SuperAdmin/Folders/Folders"; import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import Form from "@Front/Components/DesignSystem/Form"; +import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField"; import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography"; import BackArrow from "@Front/Components/Elements/BackArrow"; -import DefaultNotaryDashboard, { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; +import DefaultNotaryDashboard from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; import Module from "@Front/Config/Module"; +import { OfficeFolder } from "le-coffre-resources/dist/Notary"; import Link from "next/link"; import { NextRouter, useRouter } from "next/router"; import BasePage from "../../Base"; import classes from "./classes.module.scss"; -import Folders from "@Front/Api/LeCoffreApi/SuperAdmin/Folders/Folders"; -import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField"; type IProps = {}; @@ -20,7 +21,7 @@ type IPropsClass = IProps & { }; type IState = { - folder: IDashBoardFolder | null; + folder: OfficeFolder | null; }; class UpdateFolderDescriptionClass extends BasePage { private backwardPath = Module.getInstance() diff --git a/src/front/Components/Layouts/Folder/UpdateFolderMetadata/index.tsx b/src/front/Components/Layouts/Folder/UpdateFolderMetadata/index.tsx index f1e2ca9a..b66a90f0 100644 --- a/src/front/Components/Layouts/Folder/UpdateFolderMetadata/index.tsx +++ b/src/front/Components/Layouts/Folder/UpdateFolderMetadata/index.tsx @@ -5,14 +5,14 @@ import Select, { IOption } from "@Front/Components/DesignSystem/Form/SelectField import TextField from "@Front/Components/DesignSystem/Form/TextField"; import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography"; import BackArrow from "@Front/Components/Elements/BackArrow"; -import DefaultNotaryDashboard, { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; +import DefaultNotaryDashboard from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; import Module from "@Front/Config/Module"; +import { Deed, OfficeFolder } from "le-coffre-resources/dist/Notary"; import Link from "next/link"; import { NextRouter, useRouter } from "next/router"; import BasePage from "../../Base"; import classes from "./classes.module.scss"; -import { Deed, OfficeFolder } from "le-coffre-resources/dist/Notary"; type IProps = {}; @@ -22,7 +22,7 @@ type IPropsClass = IProps & { }; type IState = { - selectedFolder: IDashBoardFolder | null; + selectedFolder: OfficeFolder | null; }; class UpdateFolderMetadataClass extends BasePage { constructor(props: IPropsClass) { @@ -93,7 +93,7 @@ class UpdateFolderMetadataClass extends BasePage { ...values, deed: Deed.hydrate({ uid: values["deed"], - }) + }), }); await Folders.getInstance().put(this.props.folderUid, newValues); @@ -106,7 +106,7 @@ class UpdateFolderMetadataClass extends BasePage { } } - private async getFolder(): Promise { + private async getFolder(): Promise { const query = { q: { deed: { include: { deed_type: true } }, @@ -118,7 +118,7 @@ class UpdateFolderMetadataClass extends BasePage { return folder; } - private onSelectedFolder(folder: IDashBoardFolder): void { + private onSelectedFolder(folder: OfficeFolder): void { this.setState({ selectedFolder: folder }); } } diff --git a/src/front/Components/Layouts/Folder/index.tsx b/src/front/Components/Layouts/Folder/index.tsx index 89aed8ef..6601c2e3 100644 --- a/src/front/Components/Layouts/Folder/index.tsx +++ b/src/front/Components/Layouts/Folder/index.tsx @@ -1,12 +1,13 @@ import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography"; -import DefaultNotaryDashboard, { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; +import DefaultNotaryDashboard from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; +import { OfficeFolder } from "le-coffre-resources/dist/Notary"; import BasePage from "../Base"; import classes from "./classes.module.scss"; type IProps = {}; type IState = { - selectedFolder: IDashBoardFolder | null; + selectedFolder: OfficeFolder | null; isArchivedModalOpen: boolean; }; export default class Folder extends BasePage { @@ -37,7 +38,7 @@ export default class Folder extends BasePage { ); } - private onSelectedFolder(folder: IDashBoardFolder): void { + private onSelectedFolder(folder: OfficeFolder): void { this.setState({ selectedFolder: folder }); } } diff --git a/src/front/Components/Layouts/FolderArchived/FolderInformation/ClientSection/index.tsx b/src/front/Components/Layouts/FolderArchived/FolderInformation/ClientSection/index.tsx index 33143af1..cf19ee59 100644 --- a/src/front/Components/Layouts/FolderArchived/FolderInformation/ClientSection/index.tsx +++ b/src/front/Components/Layouts/FolderArchived/FolderInformation/ClientSection/index.tsx @@ -1,11 +1,11 @@ import React from "react"; import classes from "./classes.module.scss"; -import { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; +import { OfficeFolder } from "le-coffre-resources/dist/Notary"; import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography"; import UserFolder from "@Front/Components/DesignSystem/UserFolder"; type IProps = { - folder: IDashBoardFolder; + folder: OfficeFolder; }; type IState = { openedCustomer: string; diff --git a/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx b/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx index e681b9da..0e8b2cc0 100644 --- a/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx +++ b/src/front/Components/Layouts/FolderArchived/FolderInformation/index.tsx @@ -4,9 +4,9 @@ import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import FolderBoxInformation, { EFolderBoxInformationType } from "@Front/Components/DesignSystem/FolderBoxInformation"; import QuantityProgressBar from "@Front/Components/DesignSystem/QuantityProgressBar"; import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography"; -import DefaultNotaryDashboard, { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; +import DefaultNotaryDashboard from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; import Module from "@Front/Config/Module"; -import { OfficeFolder } from "le-coffre-resources/dist/Customer"; +import { OfficeFolder } from "le-coffre-resources/dist/Notary"; import { NextRouter, useRouter } from "next/router"; import BasePage from "../../Base"; @@ -21,7 +21,7 @@ type IPropsClass = IProps & { }; type IState = { - selectedFolder: IDashBoardFolder | null; + selectedFolder: OfficeFolder | null; isArchivedModalOpen: boolean; }; class FolderInformationClass extends BasePage { @@ -111,7 +111,7 @@ class FolderInformationClass extends BasePage { return this.state.selectedFolder?.customers !== undefined; } - private onSelectedFolder(folder: IDashBoardFolder): void { + private onSelectedFolder(folder: OfficeFolder): void { this.setState({ selectedFolder: folder }); } diff --git a/src/front/Components/Layouts/FolderArchived/UpdateFolderMetadata/index.tsx b/src/front/Components/Layouts/FolderArchived/UpdateFolderMetadata/index.tsx index 5c48f290..57dcf16a 100644 --- a/src/front/Components/Layouts/FolderArchived/UpdateFolderMetadata/index.tsx +++ b/src/front/Components/Layouts/FolderArchived/UpdateFolderMetadata/index.tsx @@ -1,22 +1,23 @@ import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import Form from "@Front/Components/DesignSystem/Form"; -import TextField from "@Front/Components/DesignSystem/Form/TextField"; import Select, { IOption } from "@Front/Components/DesignSystem/Form/SelectField"; +import TextField from "@Front/Components/DesignSystem/Form/TextField"; import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography"; import BackArrow from "@Front/Components/Elements/BackArrow"; -import DefaultNotaryDashboard, { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; +import DefaultNotaryDashboard from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; +import Module from "@Front/Config/Module"; +import { OfficeFolder } from "le-coffre-resources/dist/Notary"; +import Link from "next/link"; import { useRouter } from "next/router"; import BasePage from "../../Base"; import classes from "./classes.module.scss"; -import Link from "next/link"; -import Module from "@Front/Config/Module"; type IProps = { selectedFolderUid: string; }; type IState = { - selectedFolder: IDashBoardFolder | null; + selectedFolder: OfficeFolder | null; selectedOption?: IOption; }; class UpdateFolderMetadataClass extends BasePage { @@ -77,7 +78,7 @@ class UpdateFolderMetadataClass extends BasePage { }); } - private onSelectedFolder(folder: IDashBoardFolder): void { + private onSelectedFolder(folder: OfficeFolder): void { this.setState({ selectedFolder: folder }); } } diff --git a/src/front/Components/Layouts/FolderArchived/index.tsx b/src/front/Components/Layouts/FolderArchived/index.tsx index 7b71e800..cda457a3 100644 --- a/src/front/Components/Layouts/FolderArchived/index.tsx +++ b/src/front/Components/Layouts/FolderArchived/index.tsx @@ -1,11 +1,13 @@ -import DefaultNotaryDashboard, { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; -import BasePage from "../Base"; import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography"; +import DefaultNotaryDashboard from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; +import { OfficeFolder } from "le-coffre-resources/dist/Notary"; + +import BasePage from "../Base"; import classes from "./classes.module.scss"; type IProps = {}; type IState = { - selectedFolder: IDashBoardFolder | null; + selectedFolder: OfficeFolder | null; isArchivedModalOpen: boolean; }; export default class FolderArchived extends BasePage { @@ -40,7 +42,7 @@ export default class FolderArchived extends BasePage { ); } - private onSelectedFolder(folder: IDashBoardFolder): void { + private onSelectedFolder(folder: OfficeFolder): void { this.setState({ selectedFolder: folder }); } } diff --git a/src/front/Config/Module/preprod.json b/src/front/Config/Module/preprod.json index 8540ba0d..3dde562b 100644 --- a/src/front/Config/Module/preprod.json +++ b/src/front/Config/Module/preprod.json @@ -213,6 +213,36 @@ } } }, + "DocumentTypes": { + "enabled": true, + "props": { + "path": "/document-types", + "labelKey": "documentTypes" + }, + "pages": { + "DocumentTypesInformations": { + "enabled": true, + "props": { + "path": "/document-types/[uid]", + "labelKey": "documentInformations" + } + }, + "Create": { + "enabled": true, + "props": { + "path": "/document-types/create", + "labelKey": "createDocumentType" + } + }, + "Edit": { + "enabled": true, + "props": { + "path": "/document-types/[uid]/edit", + "labelKey": "editDocumentType" + } + } + } + }, "404": { "enabled": true, "props": { diff --git a/src/front/Config/Module/production.json b/src/front/Config/Module/production.json index 8540ba0d..3dde562b 100644 --- a/src/front/Config/Module/production.json +++ b/src/front/Config/Module/production.json @@ -213,6 +213,36 @@ } } }, + "DocumentTypes": { + "enabled": true, + "props": { + "path": "/document-types", + "labelKey": "documentTypes" + }, + "pages": { + "DocumentTypesInformations": { + "enabled": true, + "props": { + "path": "/document-types/[uid]", + "labelKey": "documentInformations" + } + }, + "Create": { + "enabled": true, + "props": { + "path": "/document-types/create", + "labelKey": "createDocumentType" + } + }, + "Edit": { + "enabled": true, + "props": { + "path": "/document-types/[uid]/edit", + "labelKey": "editDocumentType" + } + } + } + }, "404": { "enabled": true, "props": { diff --git a/src/front/Config/Module/staging.json b/src/front/Config/Module/staging.json index 8540ba0d..3dde562b 100644 --- a/src/front/Config/Module/staging.json +++ b/src/front/Config/Module/staging.json @@ -213,6 +213,36 @@ } } }, + "DocumentTypes": { + "enabled": true, + "props": { + "path": "/document-types", + "labelKey": "documentTypes" + }, + "pages": { + "DocumentTypesInformations": { + "enabled": true, + "props": { + "path": "/document-types/[uid]", + "labelKey": "documentInformations" + } + }, + "Create": { + "enabled": true, + "props": { + "path": "/document-types/create", + "labelKey": "createDocumentType" + } + }, + "Edit": { + "enabled": true, + "props": { + "path": "/document-types/[uid]/edit", + "labelKey": "editDocumentType" + } + } + } + }, "404": { "enabled": true, "props": { From 7cbd73c048684da39292c25cc0f411a3e7b5e668 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Tue, 25 Jul 2023 10:52:10 +0200 Subject: [PATCH 02/13] :sparkles: Fixing login --- src/front/Components/Layouts/Login/index.tsx | 70 ++++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/front/Components/Layouts/Login/index.tsx b/src/front/Components/Layouts/Login/index.tsx index 59da4eb7..b4c10d64 100644 --- a/src/front/Components/Layouts/Login/index.tsx +++ b/src/front/Components/Layouts/Login/index.tsx @@ -1,48 +1,48 @@ import CoffreIcon from "@Assets/Icons/coffre.svg"; -// import { FrontendVariables } from "@Front/Config/VariablesFront"; import idNoteLogo from "@Assets/Icons/id-note-logo.svg"; import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography"; import DefaultDoubleSidePage from "@Front/Components/LayoutTemplates/DefaultDoubleSidePage"; +import Module from "@Front/Config/Module"; +import JwtService from "@Front/Services/JwtService/JwtService"; import UserStore from "@Front/Stores/UserStore"; import Image from "next/image"; +import { useRouter } from "next/router"; +import { useCallback } from "react"; -import BasePage from "../Base"; import classes from "./classes.module.scss"; import LandingImage from "./landing-connect.jpeg"; -export default class LoginClass extends BasePage { - public override render(): JSX.Element { - return ( - -
- coffre - -
Connexion espace professionnel
-
- - -
Vous n'arrivez pas à vous connecter ?
-
- -
-
- ); - } +export default function Login() { + const router = useRouter(); + const redirectUserOnConnection = useCallback(() => { + async function getUser() { + try { + await UserStore.instance.connect(process.env["NEXT_PUBLIC_ADMIN_ID"] as string); + await JwtService.getInstance().checkJwt(); + router.push(Module.getInstance().get().modules.pages.Folder.props.path); + } catch (e) { + console.error(e); + } + } - private async redirectUserOnConnection() { - // const variables = FrontendVariables.getInstance(); - // const baseFronturl = variables.BACK_API_PROTOCOL + variables.FRONT_APP_HOST; - - await UserStore.instance.connect(process.env["NEXT_PUBLIC_ADMIN_ID"] as string); - // await JwtService.getInstance().checkJwt(); - // window.location.assign("http://localhost:3000" + "/folders"); - - // const authorizeEndPoint = variables.IDNOT_AUTHORIZE_ENDPOINT; - // const clientId = variables.IDNOT_CLIENT_ID; - // const url = `${authorizeEndPoint}?client_id=${clientId}&redirect_uri=${baseFronturl}/authorized-client&scope=openid,profile,offline_access&response_type=code`; - // window.location.assign(url); - } + getUser(); + }, [router]); + return ( + +
+ coffre + +
Connexion espace professionnel
+
+ + +
Vous n'arrivez pas à vous connecter ?
+
+ +
+
+ ); } From d3d27ff75d38416c40910ee6ffd951b9db13fe6e Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Tue, 25 Jul 2023 11:40:37 +0200 Subject: [PATCH 03/13] :bug: Fixing deed types --- .../Layouts/DeedTypes/DeedTypesInformations/index.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx index ea85a5d1..35fd704c 100644 --- a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx +++ b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx @@ -37,6 +37,15 @@ export default function DeedTypesInformations(props: IProps) { }, }); setDeedTypeSelected(deedType); + + if (!deedType.document_types) return; + const documentsOptions: IOption[] = deedType.document_types?.map((documentType) => { + return { + label: documentType.name, + value: documentType.uid, + }; + }); + setSelectedDocuments(documentsOptions); } async function getDocuments() { @@ -44,7 +53,6 @@ export default function DeedTypesInformations(props: IProps) { setAvailableDocuments(documents); } - setSelectedDocuments([]); getDocuments(); getDeedType(); }, [deedTypeUid]); From 1d5c094a20a72d53ab536a631e6e327b50071b0f Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Tue, 25 Jul 2023 14:01:40 +0200 Subject: [PATCH 04/13] :sparkles: Modifying deed types document types --- .../LeCoffreApi/Admin/DeedTypes/DeedTypes.ts | 20 +++++++++++++++++++ .../DeedTypes/DeedTypesInformations/index.tsx | 9 ++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/front/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes.ts b/src/front/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes.ts index a9254f9d..efeee6f2 100644 --- a/src/front/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes.ts +++ b/src/front/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes.ts @@ -2,6 +2,16 @@ import { DeedType } from "le-coffre-resources/dist/Admin"; import BaseAdmin from "../BaseAdmin"; +export type IPutDeedTypesParams = { + uid?: DeedType["uid"]; + name?: DeedType["name"]; + description?: DeedType["description"]; + deed?: DeedType["deed"]; + office?: DeedType["office"]; + archived_at?: DeedType["archived_at"]; + document_types?: DeedType["document_types"]; +}; + export type IGetDeedTypesParams = { where?: {}; include?: {}; @@ -46,4 +56,14 @@ export default class DeedTypes extends BaseAdmin { return Promise.reject(err); } } + + public async put(uid: string, body: IPutDeedTypesParams) { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } } diff --git a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx index 35fd704c..a403dce2 100644 --- a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx +++ b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx @@ -57,7 +57,14 @@ export default function DeedTypesInformations(props: IProps) { getDeedType(); }, [deedTypeUid]); - const onSubmitHandler = useCallback(async (e: React.FormEvent | null, values: { [key: string]: string }) => {}, []); + const onSubmitHandler = useCallback( + async (e: React.FormEvent | null, values: { [key: string]: string }) => { + await DeedTypes.getInstance().put(deedTypeUid as string, { + document_types: selectedDocuments.map((document) => DocumentType.hydrate({ uid: document.value as string })), + }); + }, + [deedTypeUid, selectedDocuments], + ); const onDocumentChangeHandler = useCallback((values: MultiValue) => { setSelectedDocuments(values as IOption[]); From 1c9c4f896c566964e37902bebed6024438fe5023 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Tue, 25 Jul 2023 14:07:38 +0200 Subject: [PATCH 05/13] :sparkles: Updating deed types informations --- .../Layouts/DeedTypes/DeedTypesEdit/index.tsx | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/front/Components/Layouts/DeedTypes/DeedTypesEdit/index.tsx b/src/front/Components/Layouts/DeedTypes/DeedTypesEdit/index.tsx index 7b05fc31..fa27ed15 100644 --- a/src/front/Components/Layouts/DeedTypes/DeedTypesEdit/index.tsx +++ b/src/front/Components/Layouts/DeedTypes/DeedTypesEdit/index.tsx @@ -1,15 +1,16 @@ import DeedTypes from "@Front/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes"; +import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import Form from "@Front/Components/DesignSystem/Form"; +import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField"; +import TextField from "@Front/Components/DesignSystem/Form/TextField"; import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography"; import DefaultDeedTypesDashboard from "@Front/Components/LayoutTemplates/DefaultDeedTypeDashboard"; +import Module from "@Front/Config/Module"; import { DeedType } from "le-coffre-resources/dist/Admin"; import { useRouter } from "next/router"; import { useCallback, useEffect, useState } from "react"; import classes from "./classes.module.scss"; -import TextField from "@Front/Components/DesignSystem/Form/TextField"; -import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField"; -import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; export default function DeedTypesEdit() { const router = useRouter(); @@ -31,7 +32,27 @@ export default function DeedTypesEdit() { getDeedType(); }, [deedTypeUid]); - const onSubmitHandler = useCallback(async (e: React.FormEvent | null, values: { [key: string]: string }) => {}, []); + const onSubmitHandler = useCallback( + async (e: React.FormEvent | null, values: { [key: string]: string }) => { + try { + await DeedTypes.getInstance().put( + deedTypeUid as string, + DeedType.hydrate({ + name: values["name"], + description: values["description"], + }), + ); + router.push( + Module.getInstance() + .get() + .modules.pages.DeedTypes.pages.DeedTypesInformations.props.path.replace("[uid]", deedTypeUid as string), + ); + } catch (e) { + console.error(e); + } + }, + [deedTypeUid, router], + ); return ( From cc68b85bc22ae4f687334d9d229d5178367702d1 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Tue, 25 Jul 2023 14:12:24 +0200 Subject: [PATCH 06/13] :sparkles: Create deed type --- .../LeCoffreApi/Admin/DeedTypes/DeedTypes.ts | 15 ++++++++ .../DeedTypes/DeedTypesCreate/index.tsx | 36 +++++++++++++++++-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/front/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes.ts b/src/front/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes.ts index efeee6f2..896427c6 100644 --- a/src/front/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes.ts +++ b/src/front/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes.ts @@ -12,6 +12,11 @@ export type IPutDeedTypesParams = { document_types?: DeedType["document_types"]; }; +export type IPostDeedTypesParams = { + name?: DeedType["name"]; + description?: DeedType["description"]; +}; + export type IGetDeedTypesParams = { where?: {}; include?: {}; @@ -66,4 +71,14 @@ export default class DeedTypes extends BaseAdmin { return Promise.reject(err); } } + + public async post(body: IPostDeedTypesParams) { + const url = new URL(this.baseURl); + try { + return await this.postRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } } diff --git a/src/front/Components/Layouts/DeedTypes/DeedTypesCreate/index.tsx b/src/front/Components/Layouts/DeedTypes/DeedTypesCreate/index.tsx index 274b4205..39d22720 100644 --- a/src/front/Components/Layouts/DeedTypes/DeedTypesCreate/index.tsx +++ b/src/front/Components/Layouts/DeedTypes/DeedTypesCreate/index.tsx @@ -1,16 +1,46 @@ +import DeedTypes from "@Front/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes"; import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import Form from "@Front/Components/DesignSystem/Form"; +import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField"; +import TextField from "@Front/Components/DesignSystem/Form/TextField"; import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography"; import DefaultDeedTypesDashboard from "@Front/Components/LayoutTemplates/DefaultDeedTypeDashboard"; +import Module from "@Front/Config/Module"; +import JwtService from "@Front/Services/JwtService/JwtService"; +import { DeedType, Office } from "le-coffre-resources/dist/Admin"; +import { useRouter } from "next/router"; import { useCallback } from "react"; import classes from "./classes.module.scss"; -import TextField from "@Front/Components/DesignSystem/Form/TextField"; -import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField"; type IProps = {}; export default function DeedTypesCreate(props: IProps) { - const onSubmitHandler = useCallback(async (e: React.FormEvent | null, values: { [key: string]: string }) => {}, []); + const router = useRouter(); + const onSubmitHandler = useCallback( + async (e: React.FormEvent | null, values: { [key: string]: string }) => { + try { + const jwt = JwtService.getInstance().decodeJwt(); + const deedType = await DeedTypes.getInstance().post( + DeedType.hydrate({ + name: values["name"], + description: values["description"], + office: Office.hydrate({ + uid: jwt?.office_Id + }) + }), + ); + + router.push( + Module.getInstance() + .get() + .modules.pages.DeedTypes.pages.DeedTypesInformations.props.path.replace("[uid]", deedType.uid!), + ); + } catch (e) { + console.error(e); + } + }, + [router], + ); return ( From dfc3b79eb8a9142c38094d581c3c03ab0c7d6a05 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Tue, 25 Jul 2023 14:37:02 +0200 Subject: [PATCH 07/13] :sparkles: Change roles in collaborators --- .../CollaboratorInformations/index.tsx | 97 +++++++++++++++++-- 1 file changed, 90 insertions(+), 7 deletions(-) diff --git a/src/front/Components/Layouts/Collaborators/CollaboratorInformations/index.tsx b/src/front/Components/Layouts/Collaborators/CollaboratorInformations/index.tsx index e0ee6c70..958ea2dc 100644 --- a/src/front/Components/Layouts/Collaborators/CollaboratorInformations/index.tsx +++ b/src/front/Components/Layouts/Collaborators/CollaboratorInformations/index.tsx @@ -1,16 +1,17 @@ import ChevronIcon from "@Assets/Icons/chevron.svg"; import OfficeRoles from "@Front/Api/LeCoffreApi/Admin/OfficeRoles/OfficeRoles"; -import Users from "@Front/Api/LeCoffreApi/SuperAdmin/Users/Users"; +import Users from "@Front/Api/LeCoffreApi/Admin/Users/Users"; import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import CheckBox from "@Front/Components/DesignSystem/CheckBox"; import SelectField, { IOption } from "@Front/Components/DesignSystem/Form/SelectField"; +import Confirm from "@Front/Components/DesignSystem/Modal/Confirm"; import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography"; import DefaultCollaboratorDashboard from "@Front/Components/LayoutTemplates/DefaultCollaboratorDashboard"; import Module from "@Front/Config/Module"; -import User from "le-coffre-resources/dist/Notary"; +import User, { OfficeRole } from "le-coffre-resources/dist/Admin"; import Link from "next/link"; import { useRouter } from "next/router"; -import { useEffect, useState } from "react"; +import { useCallback, useEffect, useState } from "react"; import classes from "./classes.module.scss"; @@ -22,6 +23,56 @@ export default function CollaboratorInformations(props: IProps) { const [userSelected, setUserSelected] = useState(null); const [availableRoles, setAvailableRoles] = useState([]); + const [roleModalOpened, setRoleModalOpened] = useState(false); + const [adminModalOpened, setAdminModalOpened] = useState(false); + + const [selectedOption, setSelectedOption] = useState(null); + + const handleRoleChange = useCallback((option: IOption) => { + setSelectedOption(option); + setRoleModalOpened(true); + }, []); + + const closeRoleModal = useCallback(() => { + setRoleModalOpened(false); + setSelectedOption({ + value: userSelected?.office_role ? userSelected?.office_role?.uid : userSelected?.role?.uid, + label: userSelected?.office_role ? userSelected?.office_role?.name : userSelected?.role?.name!, + }); + }, [userSelected?.office_role, userSelected?.role?.name, userSelected?.role?.uid]); + + const changeRole = useCallback(async () => { + await Users.getInstance().put( + userSelected?.uid as string, + User.hydrate({ + office_role: OfficeRole.hydrate({ + uid: selectedOption?.value as string, + }), + }), + ); + setRoleModalOpened(false); + }, [selectedOption, userSelected]); + + const changeAdmin = useCallback(async () => { + await Users.getInstance().put( + userSelected?.uid as string, + User.hydrate({ + office_role: OfficeRole.hydrate({ + uid: selectedOption?.value as string, + }), + }), + ); + setRoleModalOpened(false); + }, [selectedOption, userSelected]); + + const openAdminModal = useCallback(() => { + setAdminModalOpened(true); + }, []); + + const closeAdminModal = useCallback(() => { + setAdminModalOpened(false); + }, []); + useEffect(() => { async function getUser() { if (!collaboratorUid) return; @@ -38,6 +89,10 @@ export default function CollaboratorInformations(props: IProps) { if (!roles) return; setAvailableRoles(roles.map((role) => ({ value: role.uid, label: role.name }))); setUserSelected(user); + setSelectedOption({ + value: user?.office_role ? user?.office_role?.uid : user?.role?.uid, + label: user?.office_role ? user?.office_role?.name : user?.role?.name!, + }); } getUser(); @@ -96,14 +151,13 @@ export default function CollaboratorInformations(props: IProps) { placeholder="Rôle" name="role" options={availableRoles} - selectedOption={{ - value: userSelected?.office_role ? userSelected?.office_role?.uid : userSelected?.role?.uid, - label: userSelected?.office_role ? userSelected?.office_role?.name : userSelected?.role?.name!, - }} + selectedOption={selectedOption!} + onChange={handleRoleChange} />
+ +
+ + Attributer le rôle de {selectedOption?.label} à{" "} + {userSelected?.contact?.first_name} {userSelected?.contact?.last_name} ? + +
+
+ +
+ + Attributer le rôle d'administrateur à {userSelected?.contact?.first_name} {userSelected?.contact?.last_name} ? + +
+
); From df3f4ff59089a7b5862989b1e00c7b93f715787b Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Tue, 25 Jul 2023 14:44:01 +0200 Subject: [PATCH 08/13] :sparkles: Archiving deed types --- .../LeCoffreApi/Admin/DeedTypes/DeedTypes.ts | 10 +++++ .../DefaultDeedTypeDashboard/index.tsx | 6 ++- .../DeedTypes/DeedTypesInformations/index.tsx | 39 ++++++++++++++++++- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/front/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes.ts b/src/front/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes.ts index 896427c6..9cb83d35 100644 --- a/src/front/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes.ts +++ b/src/front/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes.ts @@ -81,4 +81,14 @@ export default class DeedTypes extends BaseAdmin { return Promise.reject(err); } } + + public async delete(uid: string) { + const url = new URL(this.baseURl); + try { + return await this.deleteRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } } diff --git a/src/front/Components/LayoutTemplates/DefaultDeedTypeDashboard/index.tsx b/src/front/Components/LayoutTemplates/DefaultDeedTypeDashboard/index.tsx index da41c677..f85aa32a 100644 --- a/src/front/Components/LayoutTemplates/DefaultDeedTypeDashboard/index.tsx +++ b/src/front/Components/LayoutTemplates/DefaultDeedTypeDashboard/index.tsx @@ -87,7 +87,11 @@ export default class DefaultDeedTypesDashboard extends React.Component this.onResize(window)); - const query: IGetDeedTypesParams = {}; + const query: IGetDeedTypesParams = { + where: { + archived_at: null, + }, + }; const deedTypes = await DeedTypes.getInstance().get(query); this.setState({ deedTypes }); diff --git a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx index a403dce2..8494cdc0 100644 --- a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx +++ b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx @@ -5,6 +5,7 @@ import DocumentTypes from "@Front/Api/LeCoffreApi/Admin/DocumentTypes/DocumentTy import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import Form from "@Front/Components/DesignSystem/Form"; import { IOption } from "@Front/Components/DesignSystem/Form/SelectField"; +import Confirm from "@Front/Components/DesignSystem/Modal/Confirm"; import MultiSelect from "@Front/Components/DesignSystem/MultiSelect"; import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography"; import DefaultDeedTypesDashboard from "@Front/Components/LayoutTemplates/DefaultDeedTypeDashboard"; @@ -28,6 +29,26 @@ export default function DeedTypesInformations(props: IProps) { const [availableDocuments, setAvailableDocuments] = useState([]); const [selectedDocuments, setSelectedDocuments] = useState([]); + const [isDeleteModalOpened, setIsDeleteModalOpened] = useState(false); + + const openDeleteModal = useCallback(() => { + setIsDeleteModalOpened(true); + }, []); + + const closeDeleteModal = useCallback(() => { + setIsDeleteModalOpened(false); + }, []); + + const deleteDeedType = useCallback(async () => { + await DeedTypes.getInstance().put( + deedTypeUid as string, + DeedType.hydrate({ + archived_at: new Date(), + }), + ); + router.push(Module.getInstance().get().modules.pages.DeedTypes.props.path); + }, [deedTypeUid, router]); + useEffect(() => { async function getDeedType() { if (!deedTypeUid) return; @@ -136,8 +157,24 @@ export default function DeedTypesInformations(props: IProps) {
- +
+ +
+ + Êtes-vous sûr de vouloir archiver ce type d'acte ? + +
+
); From 6a091581f75c14762ab9e176bb4a1c8acb84b887 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Tue, 25 Jul 2023 14:55:46 +0200 Subject: [PATCH 09/13] :sparkles: Vote popups done --- .../Layouts/Users/UserInformations/index.tsx | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/src/front/Components/Layouts/Users/UserInformations/index.tsx b/src/front/Components/Layouts/Users/UserInformations/index.tsx index 02a9b43b..22ebaf28 100644 --- a/src/front/Components/Layouts/Users/UserInformations/index.tsx +++ b/src/front/Components/Layouts/Users/UserInformations/index.tsx @@ -3,6 +3,7 @@ import OfficeRoles from "@Front/Api/LeCoffreApi/Admin/OfficeRoles/OfficeRoles"; import Users from "@Front/Api/LeCoffreApi/SuperAdmin/Users/Users"; import CheckBox from "@Front/Components/DesignSystem/CheckBox"; import SelectField, { IOption } from "@Front/Components/DesignSystem/Form/SelectField"; +import Confirm from "@Front/Components/DesignSystem/Modal/Confirm"; import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography"; import DefaultUserDashboard from "@Front/Components/LayoutTemplates/DefaultUserDashboard"; import User from "le-coffre-resources/dist/Notary"; @@ -20,6 +21,42 @@ export default function UserInformations(props: IProps) { const [userSelected, setUserSelected] = useState(null); const [availableRoles, setAvailableRoles] = useState([]); + const [addSuperAdminModalOpened, setAddSuperAdminModalOpened] = useState(false); + const [removeSuperAdminModalOpened, setRemoveSuperAdminModalOpened] = useState(false); + + const openAddSuperAdminModal = () => { + setAddSuperAdminModalOpened(true); + }; + + const closeAddSuperAdminModal = () => { + setAddSuperAdminModalOpened(false); + }; + + const openRemoveSuperAdminModal = () => { + setRemoveSuperAdminModalOpened(true); + }; + + const closeRemoveSuperAdminModal = () => { + setRemoveSuperAdminModalOpened(false); + }; + + const handleCheckboxAdminChanged = (e: React.ChangeEvent) => { + const checked = e.target.checked; + if (checked) { + openAddSuperAdminModal(); + } else { + openRemoveSuperAdminModal(); + } + }; + + const addSuperAdmin = async () => { + closeAddSuperAdminModal(); + }; + + const removeSuperAdmin = async () => { + closeRemoveSuperAdminModal(); + }; + useEffect(() => { async function getUser() { if (!userUid) return; @@ -109,6 +146,7 @@ export default function UserInformations(props: IProps) { toolTip="tooltip" /> + +
+ + Nommer une personne Super Administrateur nécessite 3 votes de super administrateurs existants. Souhaitez-vous + attribuer un vote ? + +
+
+ +
+ + Retirer un collaborateur du rôle de Super Administrateur nécessite 3 votes de super administrateurs existants. + Souhaitez-vous attribuer un vote ? + +
+
); From d3078696338b14d83af5566e87873dba9855a49b Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Tue, 25 Jul 2023 15:27:10 +0200 Subject: [PATCH 10/13] :sparkles: Validation popup on rules modifying --- .../CollaboratorInformations/index.tsx | 1 + .../DeedTypes/DeedTypesInformations/index.tsx | 6 +- .../Layouts/Roles/RolesInformations/index.tsx | 56 +++++++++++++------ 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/src/front/Components/Layouts/Collaborators/CollaboratorInformations/index.tsx b/src/front/Components/Layouts/Collaborators/CollaboratorInformations/index.tsx index 958ea2dc..4c61c577 100644 --- a/src/front/Components/Layouts/Collaborators/CollaboratorInformations/index.tsx +++ b/src/front/Components/Layouts/Collaborators/CollaboratorInformations/index.tsx @@ -163,6 +163,7 @@ export default function CollaboratorInformations(props: IProps) { label: "Nommer administrateur de l'office", }} toolTip="blabla" + checked={userSelected?.office_role?.name! === "admin"} /> diff --git a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx index 8494cdc0..46347524 100644 --- a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx +++ b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx @@ -158,7 +158,7 @@ export default function DeedTypesInformations(props: IProps) {
- Êtes-vous sûr de vouloir archiver ce type d'acte ? + Êtes-vous sûr de vouloir supprimer ce type d'acte ?
diff --git a/src/front/Components/Layouts/Roles/RolesInformations/index.tsx b/src/front/Components/Layouts/Roles/RolesInformations/index.tsx index 7d8bca16..9d6674b9 100644 --- a/src/front/Components/Layouts/Roles/RolesInformations/index.tsx +++ b/src/front/Components/Layouts/Roles/RolesInformations/index.tsx @@ -3,11 +3,13 @@ import Rules from "@Front/Api/LeCoffreApi/Admin/Rules/Rules"; import Button from "@Front/Components/DesignSystem/Button"; import CheckBox from "@Front/Components/DesignSystem/CheckBox"; import Form from "@Front/Components/DesignSystem/Form"; +import Confirm from "@Front/Components/DesignSystem/Modal/Confirm"; import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography"; import DefaultRoleDashboard from "@Front/Components/LayoutTemplates/DefaultRoleDashboard"; import { Role, Rule } from "le-coffre-resources/dist/Admin"; import { useRouter } from "next/router"; import { useCallback, useEffect, useState } from "react"; +import React from "react"; import classes from "./classes.module.scss"; @@ -22,6 +24,17 @@ export default function RolesInformations(props: IProps) { const [roleSelected, setRoleSelected] = useState(null); const [rulesCheckboxes, setRulesCheckboxes] = useState([]); const [selectAll, setSelectAll] = useState(false); + + const [isConfirmModalOpened, setIsConfirmModalOpened] = useState(false); + + const openConfirmModal = useCallback(() => { + setIsConfirmModalOpened(true); + }, []); + + const closeConfirmModal = useCallback(() => { + setIsConfirmModalOpened(false); + }, []); + useEffect(() => { setSelectAll(false); async function getUser() { @@ -64,20 +77,17 @@ export default function RolesInformations(props: IProps) { [rulesCheckboxes], ); - const onSubmitHandler = useCallback( - async (e: React.FormEvent | null, values: { [key: string]: string }) => { - if (!roleSelected || !roleSelected.uid) return; - const rules = rulesCheckboxes.filter((rule) => rule.checked)?.map((rule) => Rule.hydrate(rule)); - const role = await Roles.getInstance().put(roleSelected.uid, { - rules, - }); - if (!role) return; - setRoleSelected(role); - if (!role.rules) return; - setRulesCheckboxes(role.rules.map((rule) => ({ ...rule, checked: false }))); - }, - [roleSelected, rulesCheckboxes], - ); + const modifyRules = useCallback(async () => { + if (!roleSelected || !roleSelected.uid) return; + const rules = rulesCheckboxes.filter((rule) => rule.checked)?.map((rule) => Rule.hydrate(rule)); + const role = await Roles.getInstance().put(roleSelected.uid, { + rules, + }); + if (!role) return; + setRoleSelected(role); + if (!role.rules) return; + setRulesCheckboxes(role.rules.map((rule) => ({ ...rule, checked: false }))); + }, [roleSelected, rulesCheckboxes]); return ( @@ -103,7 +113,7 @@ export default function RolesInformations(props: IProps) { checked={selectAll} /> -
+
{rulesCheckboxes.map((rule) => (
@@ -112,10 +122,24 @@ export default function RolesInformations(props: IProps) { ))}
- +
+ +
+ + En enregistrant vous modifier les droits des rôles. + +
+
); From 0365880e88118bf0e8759430ce3536b8c70bccf3 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Tue, 25 Jul 2023 15:54:39 +0200 Subject: [PATCH 11/13] :sparkles: Fixing uids and popups --- src/front/Api/LeCoffreApi/Admin/OfficeRoles/OfficeRoles.ts | 1 + .../Collaborators/CollaboratorInformations/index.tsx | 1 + .../Layouts/DeedTypes/DeedTypesInformations/index.tsx | 1 + .../Components/Layouts/Roles/RolesInformations/index.tsx | 7 ++++--- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/front/Api/LeCoffreApi/Admin/OfficeRoles/OfficeRoles.ts b/src/front/Api/LeCoffreApi/Admin/OfficeRoles/OfficeRoles.ts index fe541fa2..0c82cc4e 100644 --- a/src/front/Api/LeCoffreApi/Admin/OfficeRoles/OfficeRoles.ts +++ b/src/front/Api/LeCoffreApi/Admin/OfficeRoles/OfficeRoles.ts @@ -9,6 +9,7 @@ export type IGetRolesParams = { }; export type IPutRoleParams = { + uid: OfficeRole["uid"]; rules: OfficeRole["rules"]; }; diff --git a/src/front/Components/Layouts/Collaborators/CollaboratorInformations/index.tsx b/src/front/Components/Layouts/Collaborators/CollaboratorInformations/index.tsx index 4c61c577..6ff896e9 100644 --- a/src/front/Components/Layouts/Collaborators/CollaboratorInformations/index.tsx +++ b/src/front/Components/Layouts/Collaborators/CollaboratorInformations/index.tsx @@ -45,6 +45,7 @@ export default function CollaboratorInformations(props: IProps) { await Users.getInstance().put( userSelected?.uid as string, User.hydrate({ + uid: userSelected?.uid as string, office_role: OfficeRole.hydrate({ uid: selectedOption?.value as string, }), diff --git a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx index 46347524..defe4c56 100644 --- a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx +++ b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx @@ -81,6 +81,7 @@ export default function DeedTypesInformations(props: IProps) { const onSubmitHandler = useCallback( async (e: React.FormEvent | null, values: { [key: string]: string }) => { await DeedTypes.getInstance().put(deedTypeUid as string, { + uid: deedTypeUid as string, document_types: selectedDocuments.map((document) => DocumentType.hydrate({ uid: document.value as string })), }); }, diff --git a/src/front/Components/Layouts/Roles/RolesInformations/index.tsx b/src/front/Components/Layouts/Roles/RolesInformations/index.tsx index 9d6674b9..0fb33770 100644 --- a/src/front/Components/Layouts/Roles/RolesInformations/index.tsx +++ b/src/front/Components/Layouts/Roles/RolesInformations/index.tsx @@ -1,4 +1,4 @@ -import Roles from "@Front/Api/LeCoffreApi/Admin/OfficeRoles/OfficeRoles"; +import OfficeRoles from "@Front/Api/LeCoffreApi/Admin/OfficeRoles/OfficeRoles"; import Rules from "@Front/Api/LeCoffreApi/Admin/Rules/Rules"; import Button from "@Front/Components/DesignSystem/Button"; import CheckBox from "@Front/Components/DesignSystem/CheckBox"; @@ -39,7 +39,7 @@ export default function RolesInformations(props: IProps) { setSelectAll(false); async function getUser() { if (!roleUid) return; - const role = await Roles.getInstance().getByUid(roleUid as string, { + const role = await OfficeRoles.getInstance().getByUid(roleUid as string, { q: { rules: true, }, @@ -80,7 +80,8 @@ export default function RolesInformations(props: IProps) { const modifyRules = useCallback(async () => { if (!roleSelected || !roleSelected.uid) return; const rules = rulesCheckboxes.filter((rule) => rule.checked)?.map((rule) => Rule.hydrate(rule)); - const role = await Roles.getInstance().put(roleSelected.uid, { + const role = await OfficeRoles.getInstance().put(roleSelected.uid, { + uid: roleSelected.uid, rules, }); if (!role) return; From 42aaef902b8ca5c66ba59364ee3bdec2ea946180 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Tue, 25 Jul 2023 15:57:38 +0200 Subject: [PATCH 12/13] :bug: Fixing edit deed types --- src/front/Components/Layouts/DeedTypes/DeedTypesEdit/index.tsx | 1 + .../Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx | 1 + 2 files changed, 2 insertions(+) diff --git a/src/front/Components/Layouts/DeedTypes/DeedTypesEdit/index.tsx b/src/front/Components/Layouts/DeedTypes/DeedTypesEdit/index.tsx index fa27ed15..5838bffc 100644 --- a/src/front/Components/Layouts/DeedTypes/DeedTypesEdit/index.tsx +++ b/src/front/Components/Layouts/DeedTypes/DeedTypesEdit/index.tsx @@ -38,6 +38,7 @@ export default function DeedTypesEdit() { await DeedTypes.getInstance().put( deedTypeUid as string, DeedType.hydrate({ + uid: deedTypeUid as string, name: values["name"], description: values["description"], }), diff --git a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx index defe4c56..b4a9f32a 100644 --- a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx +++ b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx @@ -43,6 +43,7 @@ export default function DeedTypesInformations(props: IProps) { await DeedTypes.getInstance().put( deedTypeUid as string, DeedType.hydrate({ + uid: deedTypeUid as string, archived_at: new Date(), }), ); From 5b2126460fe4d18510bcb7b1fe40f70a863a818b Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Tue, 25 Jul 2023 16:20:39 +0200 Subject: [PATCH 13/13] :sparkles: Editing rules in roles working --- .../Api/LeCoffreApi/Admin/Roles/Roles.ts | 83 +++++++++++++++++++ .../DefaultRoleDashboard/index.tsx | 1 - .../CollaboratorInformations/index.tsx | 41 +++++---- .../Layouts/Roles/RolesInformations/index.tsx | 35 ++++++-- 4 files changed, 136 insertions(+), 24 deletions(-) create mode 100644 src/front/Api/LeCoffreApi/Admin/Roles/Roles.ts diff --git a/src/front/Api/LeCoffreApi/Admin/Roles/Roles.ts b/src/front/Api/LeCoffreApi/Admin/Roles/Roles.ts new file mode 100644 index 00000000..b0e51a69 --- /dev/null +++ b/src/front/Api/LeCoffreApi/Admin/Roles/Roles.ts @@ -0,0 +1,83 @@ +import { Role } from "le-coffre-resources/dist/Admin"; + +import BaseAdmin from "../BaseAdmin"; + +export type IGetRolesParams = { + where?: {}; + include?: {}; + select?: {}; +}; + +export type IPutRoleParams = { + uid: Role["uid"]; + rules: Role["rules"]; +}; + +export default class Roles extends BaseAdmin { + private static instance: Roles; + private readonly baseURl = this.namespaceUrl.concat("/roles"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new Roles(); + } else { + return this.instance; + } + } + + public async get(q?: IGetRolesParams): Promise { + const url = new URL(this.baseURl); + if (q) { + const query = { q }; + Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + } + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getOne(q?: IGetRolesParams): Promise { + const url = new URL(this.baseURl); + if (q) { + const query = { q }; + Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + } + try { + const res = await this.getRequest(url); + if (!res) return null; + if (res.length > 1) throw new Error("More than one role found"); + return res[0] ? res[0] : null; + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getByUid(uid: string, q?: any): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + if (q) Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async put(uid: string, body: IPutRoleParams): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/front/Components/LayoutTemplates/DefaultRoleDashboard/index.tsx b/src/front/Components/LayoutTemplates/DefaultRoleDashboard/index.tsx index 3ee9f0ff..a50ac12e 100644 --- a/src/front/Components/LayoutTemplates/DefaultRoleDashboard/index.tsx +++ b/src/front/Components/LayoutTemplates/DefaultRoleDashboard/index.tsx @@ -90,7 +90,6 @@ export default class DefaultRoleDashboard extends React.Component { + const adminRole = await Roles.getInstance().getOne({ + where: { + name: "admin", + }, + }); + + if (!adminRole) return; await Users.getInstance().put( userSelected?.uid as string, User.hydrate({ - office_role: OfficeRole.hydrate({ - uid: selectedOption?.value as string, - }), + uid: userSelected?.uid as string, + office_role: undefined, + role: adminRole, }), ); setRoleModalOpened(false); - }, [selectedOption, userSelected]); + }, [userSelected]); const openAdminModal = useCallback(() => { setAdminModalOpened(true); @@ -154,19 +162,22 @@ export default function CollaboratorInformations(props: IProps) { options={availableRoles} selectedOption={selectedOption!} onChange={handleRoleChange} + disabled={userSelected?.role?.name === "super-admin"} /> -
- -
+ {userSelected?.role?.name !== "super-admin" && ( +
+ +
+ )} { if (!roleSelected || !roleSelected.uid) return; const rules = rulesCheckboxes.filter((rule) => rule.checked)?.map((rule) => Rule.hydrate(rule)); - const role = await OfficeRoles.getInstance().put(roleSelected.uid, { + await OfficeRoles.getInstance().put(roleSelected.uid, { uid: roleSelected.uid, rules, }); - if (!role) return; - setRoleSelected(role); - if (!role.rules) return; - setRulesCheckboxes(role.rules.map((rule) => ({ ...rule, checked: false }))); - }, [roleSelected, rulesCheckboxes]); + + const roleUpdated = await OfficeRoles.getInstance().getByUid(roleSelected.uid, { + q: { + rules: true, + }, + }); + setRoleSelected(roleUpdated); + closeConfirmModal(); + }, [closeConfirmModal, roleSelected, rulesCheckboxes]); + + const handleRuleChange = useCallback( + (e: React.ChangeEvent) => { + const ruleUid = e.target.value; + const rule = rulesCheckboxes.find((rule) => rule.uid === ruleUid); + if (!rule) return; + rule.checked = e.target.checked; + setRulesCheckboxes([...rulesCheckboxes]); + }, + [rulesCheckboxes], + ); return ( @@ -118,7 +133,11 @@ export default function RolesInformations(props: IProps) {
{rulesCheckboxes.map((rule) => (
- +
))}
@@ -137,7 +156,7 @@ export default function RolesInformations(props: IProps) { cancelText={"Annuler"}>
- En enregistrant vous modifier les droits des rôles. + En enregistrant vous modifiez les droits des rôles.