From 456fd1d9c25293ef2dca9f02b1b564481c3dce5a Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Tue, 19 Sep 2023 15:34:49 +0200 Subject: [PATCH] :bug: Fix pre selected users --- .../UpdateFolderCollaborators/index.tsx | 108 +++++++++++------- 1 file changed, 65 insertions(+), 43 deletions(-) diff --git a/src/front/Components/Layouts/Folder/UpdateFolderCollaborators/index.tsx b/src/front/Components/Layouts/Folder/UpdateFolderCollaborators/index.tsx index 4c3ea3ea..02245906 100644 --- a/src/front/Components/Layouts/Folder/UpdateFolderCollaborators/index.tsx +++ b/src/front/Components/Layouts/Folder/UpdateFolderCollaborators/index.tsx @@ -24,7 +24,9 @@ type IState = { selectedFolder: OfficeFolder | null; selectedOption?: ERadioBoxValue; availableCollaborators: User[]; + defaultCheckedAllOffice: boolean; selectedCollaborators: readonly IOption[]; + loading: boolean; }; enum ERadioBoxValue { @@ -39,6 +41,9 @@ class UpdateFolderCollaboratorsClass extends BasePage { selectedFolder: null, availableCollaborators: [], selectedCollaborators: [], + defaultCheckedAllOffice: false, + selectedOption: ERadioBoxValue.SELECTION, + loading: true, }; this.onSelectedFolder = this.onSelectedFolder.bind(this); this.onSelectedOptionAllOffice = this.onSelectedOptionAllOffice.bind(this); @@ -55,6 +60,7 @@ class UpdateFolderCollaboratorsClass extends BasePage { value: collaborator.uid, }; }); + return (
@@ -63,34 +69,44 @@ class UpdateFolderCollaboratorsClass extends BasePage {
Modifier les collaborateurs -
-
- - Tout l'office - - - Sélectionner des collaborateurs - -
- - {this.state.selectedOption === ERadioBoxValue.SELECTION && ( -
- + {!this.state.loading && ( + +
+ + Tout l'office + + + Sélectionner des collaborateurs +
- )} -
- - - - -
- + {this.state.selectedOption === ERadioBoxValue.SELECTION && ( +
+ +
+ )} + +
+ + + + +
+ + )}
); @@ -121,27 +137,33 @@ class UpdateFolderCollaboratorsClass extends BasePage { value: collaborator.uid, }; }); - this.setState({ selectedCollaborators: preSelectedCollaborators }); + + // no need to pass query 'where' param here, default query for notaries include only users which are in the same office as the caller + const userQuery: IGetUsersParams = { + include: { + contact: { + select: { + first_name: true, + last_name: true, + }, + }, + }, + }; + + const availableCollaborators = await Users.getInstance().get(userQuery); + + this.setState({ + loading: false, + availableCollaborators, + selectedCollaborators: preSelectedCollaborators, + defaultCheckedAllOffice: preSelectedCollaborators.length === availableCollaborators.length, + selectedOption: + preSelectedCollaborators.length === availableCollaborators.length ? ERadioBoxValue.ALL : ERadioBoxValue.SELECTION, + }); } catch (error) { this.props.router.push(Module.getInstance().get().modules.pages["404"].props.path); return; } - - // no need to pass query 'where' param here, default query for notaries include only users which are in the same office as the caller - const userQuery: IGetUsersParams = { - include: { - contact: { - select: { - first_name: true, - last_name: true, - }, - }, - }, - }; - - const availableCollaborators = await Users.getInstance().get(userQuery); - console.log(availableCollaborators) - this.setState({ availableCollaborators }); } private onSelectedOptionAllOffice(event: React.ChangeEvent) {