import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import Form from "@Front/Components/DesignSystem/Form"; import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography"; import BackArrow from "@Front/Components/Elements/BackArrow"; import DefaultNotaryDashboard, { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; import BasePage from "../../Base"; import classes from "./classes.module.scss"; import Link from "next/link"; import { NextRouter, useRouter } from "next/router"; import RadioBox from "@Front/Components/DesignSystem/RadioBox"; import MultiSelect from "@Front/Components/DesignSystem/MultiSelect"; import Module from "@Front/Config/Module"; import Users, { IGetUsersparams } from "@Front/Api/LeCoffreApi/SuperAdmin/Users/Users"; import Folders from "@Front/Api/LeCoffreApi/SuperAdmin/Folders/Folders"; import { OfficeFolderHasStakeholder } from "le-coffre-resources/dist/Customer"; import { IOption } from "@Front/Components/DesignSystem/Select"; import User from "le-coffre-resources/dist/Notary"; type IPropsClass = { selectedFolderUid: string; router: NextRouter; }; type IState = { selectedFolder: IDashBoardFolder | null; selectedOption?: ERadioBoxValue; availableCollaborators: User[]; selectedCollaborators: readonly IOption[]; }; enum ERadioBoxValue { ALL = "all", SELECTION = "selection", } class UpdateFolderCollaboratorsClass extends BasePage { constructor(props: IPropsClass) { super(props); this.state = { selectedFolder: null, availableCollaborators: [], selectedCollaborators: [], }; this.onSelectedFolder = this.onSelectedFolder.bind(this); this.onSelectedOptionAllOffice = this.onSelectedOptionAllOffice.bind(this); this.onSelectedOptionSpecific = this.onSelectedOptionSpecific.bind(this); this.onFormSubmit = this.onFormSubmit.bind(this); this.onChangeSelectedCollaborators = this.onChangeSelectedCollaborators.bind(this); } public override render(): JSX.Element { const foldersInformationPath = Module.getInstance().get().modules.pages.Folder.pages.FolderInformation.props.path; const backwardPath = foldersInformationPath.replace("[folderUid]", this.props.selectedFolderUid); const selectOptions : IOption[]= this.state.availableCollaborators.map((collaborator) => { return { label: collaborator.contact.first_name + " " + collaborator.contact.last_name, value: collaborator.uid, } }) return (
Modifier les collaborateurs
Tout l'office Sélectionner des collaborateurs
{this.state.selectedOption === ERadioBoxValue.SELECTION && (
)}
); } public override async componentDidMount(){ await this.getFolderAvailableCollaborators(this.props.selectedFolderUid); } private async getFolderAvailableCollaborators(folderUid: string){ const query = { q: { office: true, office_folder_has_stakeholder: { include: { user_stakeholder: { include: { contact: true, } } } }, }, }; let folder = null; try { folder = await Folders.getInstance().getByUid(folderUid, query); const preSelectedCollaborators : IOption[]= folder.office_folder_has_stakeholder!.map((collaborator) => { return { label: collaborator.user_stakeholder.contact.first_name + " " + collaborator.user_stakeholder.contact.last_name, value: collaborator.user_stakeholder.uid, } }) this.setState({selectedCollaborators: preSelectedCollaborators}) } catch (error) { this.props.router.push(Module.getInstance().get().modules.pages["404"].props.path); return; } const userQuery: IGetUsersparams = { where: { office_uid: folder.office.uid, }, include:{ contact: { select:{ first_name:true, last_name:true, } } } }; const availableCollaborators = await Users.getInstance().get(userQuery); this.setState({availableCollaborators}); } private onSelectedOptionAllOffice(event: React.ChangeEvent) { if (event.target.value !== ERadioBoxValue.ALL) return; this.setState({ selectedOption: ERadioBoxValue.ALL, }); } private onChangeSelectedCollaborators(selectedCollaborators: readonly IOption[]) { this.setState({ selectedCollaborators }); } private onSelectedOptionSpecific(event: React.ChangeEvent) { if (event.target.value !== ERadioBoxValue.SELECTION) return; this.setState({ selectedOption: ERadioBoxValue.SELECTION, }); } private onSelectedFolder(folder: IDashBoardFolder): void { this.setState({ selectedFolder: folder }); } private async onFormSubmit(e: React.FormEvent | null, values: { [key: string]: string }) { try { let collaboratorsUid : OfficeFolderHasStakeholder[]; if(this.state.selectedOption === ERadioBoxValue.SELECTION){ collaboratorsUid = this.state.selectedCollaborators.map((collaborator) => ({user_stakeholder: {uid: collaborator.value}} as OfficeFolderHasStakeholder)); } else{ collaboratorsUid = this.state.availableCollaborators.map((collaborator) => ({user_stakeholder: {uid: collaborator.uid}} as OfficeFolderHasStakeholder)); } await Folders.getInstance().put(this.props.selectedFolderUid, {office_folder_has_stakeholder: collaboratorsUid}); this.props.router.push(Module.getInstance().get().modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.selectedFolderUid)); } catch (error) { console.error(error) } } } export default function UpdateFolderCollaborators() { const router = useRouter(); let { folderUid } = router.query; folderUid = folderUid as string; return ; }