diff --git a/src/front/Api/LeCoffreApi/Admin/BaseAdmin.ts b/src/front/Api/LeCoffreApi/Admin/BaseAdmin.ts new file mode 100644 index 00000000..fbcffb4d --- /dev/null +++ b/src/front/Api/LeCoffreApi/Admin/BaseAdmin.ts @@ -0,0 +1,5 @@ +import BaseApiService from "@Front/Api/BaseApiService"; + +export default abstract class BaseAdmin extends BaseApiService { + protected readonly namespaceUrl = this.getBaseUrl().concat("/admin"); +} 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..af2a0ea7 --- /dev/null +++ b/src/front/Api/LeCoffreApi/Admin/Roles/Roles.ts @@ -0,0 +1,42 @@ +import { Role } from "le-coffre-resources/dist/Admin"; + +import BaseAdmin from "../BaseAdmin"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetRolesParams { + where?: {}; + include?: {}; + select?: {}; +} + +export default class Roles extends BaseAdmin { + public static instance: Roles = new this(); + private readonly baseURl = this.namespaceUrl.concat("/roles"); + + private constructor() { + super(); + } + + public async get(q: IGetRolesParams): Promise { + const url = new URL(this.baseURl); + 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 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); + } + } +} diff --git a/src/front/Components/LayoutTemplates/DefaultRoleDashboard/RoleListContainer/classes.module.scss b/src/front/Components/LayoutTemplates/DefaultRoleDashboard/RoleListContainer/classes.module.scss new file mode 100644 index 00000000..300d46f2 --- /dev/null +++ b/src/front/Components/LayoutTemplates/DefaultRoleDashboard/RoleListContainer/classes.module.scss @@ -0,0 +1,21 @@ +@import "@Themes/constants.scss"; + +.root { + width: calc(100vh - 83px); + display: flex; + flex-direction: column; + justify-content: space-between; + + .header { + flex: 1; + } + + .searchbar { + padding: 40px 24px 24px 24px; + } + + .folderlist-container { + height: 100%; + border-right: 1px solid var(--grey-medium); + } +} diff --git a/src/front/Components/LayoutTemplates/DefaultRoleDashboard/RoleListContainer/index.tsx b/src/front/Components/LayoutTemplates/DefaultRoleDashboard/RoleListContainer/index.tsx new file mode 100644 index 00000000..768ecb39 --- /dev/null +++ b/src/front/Components/LayoutTemplates/DefaultRoleDashboard/RoleListContainer/index.tsx @@ -0,0 +1,61 @@ +import BlockList, { IBlock } from "@Front/Components/DesignSystem/BlockList"; +import SearchBar from "@Front/Components/DesignSystem/SearchBar"; +import Module from "@Front/Config/Module"; +import { Role } from "le-coffre-resources/dist/Admin"; +import { useRouter } from "next/router"; +import React, { useCallback, useState } from "react"; + +import classes from "./classes.module.scss"; + +type IProps = { + roles: Role[]; + onSelectedRole?: (role: Role) => void; + onCloseLeftSide?: () => void; +}; + +export default function RoleListContainer(props: IProps) { + const [filteredUsers, setFilteredUsers] = useState(props.roles); + const router = useRouter(); + + const filterRoles = useCallback( + (input: string) => { + const filteredUsers = props.roles.filter((role) => { + return ( + role.name?.toLowerCase().includes(input.toLowerCase()) + ); + }); + setFilteredUsers(filteredUsers); + }, + [props.roles], + ); + + const onSelectedBlock = useCallback( + (block: IBlock) => { + props.onCloseLeftSide && props.onCloseLeftSide(); + const redirectPath = Module.getInstance().get().modules.pages.Collaborators.pages.CollaboratorInformations.props.path; + router.push(redirectPath.replace("[uid]", block.id)); + }, + [props, router], + ); + + return ( +
+
+
+ +
+
+ { + return { + name: role.name, + id: role.uid!, + }; + })} + onSelectedBlock={onSelectedBlock} + /> +
+
+
+ ); +} diff --git a/src/front/Components/LayoutTemplates/DefaultRoleDashboard/classes.module.scss b/src/front/Components/LayoutTemplates/DefaultRoleDashboard/classes.module.scss new file mode 100644 index 00000000..a5ba79a3 --- /dev/null +++ b/src/front/Components/LayoutTemplates/DefaultRoleDashboard/classes.module.scss @@ -0,0 +1,117 @@ +@import "@Themes/constants.scss"; + +@keyframes growWidth { + 0% { + width: 100%; + } + + 100% { + width: 200%; + } +} + +.root { + .content { + display: flex; + overflow: hidden; + height: calc(100vh - 83px); + + .overlay { + position: absolute; + width: 100%; + height: 100%; + background-color: var(--white); + opacity: 0.5; + z-index: 2; + transition: all 0.3s $custom-easing; + } + + .left-side { + background-color: $white; + z-index: 3; + display: flex; + width: 389px; + min-width: 389px; + transition: all 0.3s $custom-easing; + overflow: hidden; + + @media (max-width: ($screen-m - 1px)) { + width: 56px; + min-width: 56px; + transform: translateX(-389px); + + &.opened { + transform: translateX(0px); + width: 389px; + min-width: 389px; + } + } + + @media (max-width: $screen-s) { + width: 0px; + min-width: 0px; + + &.opened { + width: 100vw; + min-width: 100vw; + } + } + } + + .closable-left-side { + position: absolute; + background-color: $white; + z-index: 0; + display: flex; + justify-content: center; + min-width: 56px; + max-width: 56px; + height: calc(100vh - 83px); + border-right: 1px $grey-medium solid; + + @media (min-width: $screen-m) { + display: none; + } + + .chevron-icon { + margin-top: 21px; + transform: rotate(180deg); + cursor: pointer; + } + + @media (max-width: $screen-s) { + display: none; + } + } + + .right-side { + min-width: calc(100vw - 389px); + padding: 64px 48px; + overflow-y: auto; + + @media (max-width: ($screen-m - 1px)) { + min-width: calc(100vw - 56px); + } + + @media (max-width: $screen-s) { + padding: 40px 16px 64px 16px; + flex: 1; + min-width: unset; + } + + .back-arrow-mobile { + display: none; + @media (max-width: $screen-s) { + display: block; + margin-bottom: 24px; + } + } + + .back-arrow-desktop { + @media (max-width: $screen-s) { + display: none; + } + } + } + } +} diff --git a/src/front/Components/LayoutTemplates/DefaultRoleDashboard/index.tsx b/src/front/Components/LayoutTemplates/DefaultRoleDashboard/index.tsx new file mode 100644 index 00000000..64266376 --- /dev/null +++ b/src/front/Components/LayoutTemplates/DefaultRoleDashboard/index.tsx @@ -0,0 +1,129 @@ +import ChevronIcon from "@Assets/Icons/chevron.svg"; +import Roles, { IGetRolesParams } from "@Front/Api/LeCoffreApi/Admin/Roles/Roles"; +import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; +import Header from "@Front/Components/DesignSystem/Header"; +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 { Role } from "le-coffre-resources/dist/Admin"; +import Image from "next/image"; +import React, { ReactNode } from "react"; + +import classes from "./classes.module.scss"; +import RoleListContainer from "./RoleListContainer"; + +type IProps = { + title: string; + children?: ReactNode; + onSelectedRole: (role: Role) => void; + hasBackArrow: boolean; + backArrowUrl?: string; + mobileBackText?: string; +}; +type IState = { + roles: Role[] | null; + isLeftSideOpen: boolean; + leftSideCanBeClosed: boolean; +}; + +export default class DefaultRoleDashboard extends React.Component { + private onWindowResize = () => {}; + public static defaultProps: Partial = { + hasBackArrow: false, + }; + + public constructor(props: IProps) { + super(props); + this.state = { + roles: null, + isLeftSideOpen: false, + leftSideCanBeClosed: typeof window !== "undefined" ? window.innerWidth < 1024 : false, + }; + this.onOpenLeftSide = this.onOpenLeftSide.bind(this); + this.onCloseLeftSide = this.onCloseLeftSide.bind(this); + } + + public override render(): JSX.Element { + return ( +
+
+
+ {this.state.isLeftSideOpen &&
} +
+ {this.state.roles && } +
+
+ open side menu +
+ +
+ {this.props.hasBackArrow && ( +
+ +
+ )} + {this.props.mobileBackText && ( +
+ +
+ )} + {this.props.children} +
+
+ +
+ ); + } + + public override async componentDidMount() { + this.onWindowResize = WindowStore.getInstance().onResize((window) => this.onResize(window)); + // const query: IGetRolesParams = { + // include: { rules: true }, + // }; + + // const roles = await Roles.instance.get(query); + const roles: Role[] = [ + Role.hydrate({ + name: "Notaire", + uid: "1", + }), + Role.hydrate({ + name: "Clerc de notaire", + uid: "2", + }), + Role.hydrate({ + name: "Collaborateur", + uid: "3", + }), + ]; + this.setState({ roles }); + } + public override componentWillUnmount() { + this.onWindowResize(); + } + + private onOpenLeftSide() { + this.setState({ isLeftSideOpen: true }); + } + + private onCloseLeftSide() { + if (!this.state.leftSideCanBeClosed) return; + this.setState({ isLeftSideOpen: false }); + } + + private onResize(window: Window) { + if (window.innerWidth > 1023) { + if (!this.state.leftSideCanBeClosed) return; + this.setState({ leftSideCanBeClosed: false }); + } + this.setState({ leftSideCanBeClosed: true }); + } +} diff --git a/src/front/Components/Layouts/Collaborators/CollaboratorInformations/index.tsx b/src/front/Components/Layouts/Collaborators/CollaboratorInformations/index.tsx index 685986c5..84113d9a 100644 --- a/src/front/Components/Layouts/Collaborators/CollaboratorInformations/index.tsx +++ b/src/front/Components/Layouts/Collaborators/CollaboratorInformations/index.tsx @@ -1,15 +1,18 @@ +import ChevronIcon from "@Assets/Icons/chevron.svg"; import Users from "@Front/Api/LeCoffreApi/SuperAdmin/Users/Users"; +import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; +import CheckBox from "@Front/Components/DesignSystem/CheckBox"; +import SelectField from "@Front/Components/DesignSystem/Form/SelectField"; import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography"; import DefaultCollaboratorDashboard from "@Front/Components/LayoutTemplates/DefaultCollaboratorDashboard"; import User from "le-coffre-resources/dist/Notary"; +import Link from "next/link"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; + import classes from "./classes.module.scss"; -import Link from "next/link"; -import SelectField from "@Front/Components/DesignSystem/Form/SelectField"; -import CheckBox from "@Front/Components/DesignSystem/CheckBox"; -import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; -import ChevronIcon from "@Assets/Icons/chevron.svg"; +import Module from "@Front/Config/Module"; + type IProps = {}; export default function CollaboratorInformations(props: IProps) { const router = useRouter(); @@ -70,7 +73,7 @@ export default function CollaboratorInformations(props: IProps) {
Modifier le rôle
- + + +
+
+
+ +
+
+ +
+
+ + + ); +} diff --git a/src/front/Components/Layouts/Roles/classes.module.scss b/src/front/Components/Layouts/Roles/classes.module.scss new file mode 100644 index 00000000..4eca97a6 --- /dev/null +++ b/src/front/Components/Layouts/Roles/classes.module.scss @@ -0,0 +1,17 @@ +@import "@Themes/constants.scss"; + +.root { + display: flex; + align-items: center; + flex-direction: column; + min-height: 100%; + + .no-role-selected { + width: 100%; + + .choose-a-role { + margin-top: 96px; + text-align: center; + } + } +} diff --git a/src/front/Components/Layouts/Roles/index.tsx b/src/front/Components/Layouts/Roles/index.tsx new file mode 100644 index 00000000..333601eb --- /dev/null +++ b/src/front/Components/Layouts/Roles/index.tsx @@ -0,0 +1,26 @@ +import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography"; +import DefaultRoleDashboard from "@Front/Components/LayoutTemplates/DefaultRoleDashboard"; + +import BasePage from "../Base"; +import classes from "./classes.module.scss"; + +type IProps = {}; +type IState = {}; +export default class Collaborators extends BasePage { + public override render(): JSX.Element { + return ( + +
+
+ Gestion des rôles +
+ + Sélectionnez un rôle + +
+
+
+
+ ); + } +} diff --git a/src/front/Config/Module/development.json b/src/front/Config/Module/development.json index 86554edc..23c5a15e 100644 --- a/src/front/Config/Module/development.json +++ b/src/front/Config/Module/development.json @@ -135,6 +135,22 @@ } } }, + "Roles": { + "enabled": true, + "props": { + "path": "/roles", + "labelKey": "roles" + }, + "pages": { + "RolesInformations": { + "enabled": true, + "props": { + "path": "/roles/[uid]", + "labelKey": "roles_informations" + } + } + } + }, "404": { "enabled": true, "props": { diff --git a/src/front/Config/Module/preprod.json b/src/front/Config/Module/preprod.json index 86554edc..23c5a15e 100644 --- a/src/front/Config/Module/preprod.json +++ b/src/front/Config/Module/preprod.json @@ -135,6 +135,22 @@ } } }, + "Roles": { + "enabled": true, + "props": { + "path": "/roles", + "labelKey": "roles" + }, + "pages": { + "RolesInformations": { + "enabled": true, + "props": { + "path": "/roles/[uid]", + "labelKey": "roles_informations" + } + } + } + }, "404": { "enabled": true, "props": { diff --git a/src/front/Config/Module/production.json b/src/front/Config/Module/production.json index 86554edc..23c5a15e 100644 --- a/src/front/Config/Module/production.json +++ b/src/front/Config/Module/production.json @@ -135,6 +135,22 @@ } } }, + "Roles": { + "enabled": true, + "props": { + "path": "/roles", + "labelKey": "roles" + }, + "pages": { + "RolesInformations": { + "enabled": true, + "props": { + "path": "/roles/[uid]", + "labelKey": "roles_informations" + } + } + } + }, "404": { "enabled": true, "props": { diff --git a/src/front/Config/Module/staging.json b/src/front/Config/Module/staging.json index 86554edc..23c5a15e 100644 --- a/src/front/Config/Module/staging.json +++ b/src/front/Config/Module/staging.json @@ -135,6 +135,22 @@ } } }, + "Roles": { + "enabled": true, + "props": { + "path": "/roles", + "labelKey": "roles" + }, + "pages": { + "RolesInformations": { + "enabled": true, + "props": { + "path": "/roles/[uid]", + "labelKey": "roles_informations" + } + } + } + }, "404": { "enabled": true, "props": { diff --git a/src/pages/roles/index.tsx b/src/pages/roles/index.tsx new file mode 100644 index 00000000..99d5bdcb --- /dev/null +++ b/src/pages/roles/index.tsx @@ -0,0 +1,5 @@ +import Roles from "@Front/Components/Layouts/Roles"; + +export default function Route() { + return ; +}