🐛 Fix pre selected users

This commit is contained in:
Maxime Lalo 2023-09-19 15:34:49 +02:00
parent d3ae82f245
commit 456fd1d9c2

View File

@ -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<IPropsClass, IState> {
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<IPropsClass, IState> {
value: collaborator.uid,
};
});
return (
<DefaultNotaryDashboard title={"Ajouter client(s)"} onSelectedFolder={this.onSelectedFolder}>
<div className={classes["root"]}>
@ -63,12 +69,21 @@ class UpdateFolderCollaboratorsClass extends BasePage<IPropsClass, IState> {
</div>
<Typography typo={ITypo.H1Bis}>Modifier les collaborateurs</Typography>
{!this.state.loading && (
<Form className={classes["form"]} onSubmit={this.onFormSubmit}>
<div className={classes["content"]}>
<RadioBox name="office" value={ERadioBoxValue.ALL} defaultChecked onChange={this.onSelectedOptionAllOffice}>
<RadioBox
name="office"
value={ERadioBoxValue.ALL}
defaultChecked={this.state.defaultCheckedAllOffice}
onChange={this.onSelectedOptionAllOffice}>
Tout l'office
</RadioBox>
<RadioBox name="office" value={ERadioBoxValue.SELECTION} onChange={this.onSelectedOptionSpecific}>
<RadioBox
name="office"
value={ERadioBoxValue.SELECTION}
defaultChecked={!this.state.defaultCheckedAllOffice}
onChange={this.onSelectedOptionSpecific}>
Sélectionner des collaborateurs
</RadioBox>
</div>
@ -91,6 +106,7 @@ class UpdateFolderCollaboratorsClass extends BasePage<IPropsClass, IState> {
<Button type="submit">Enregistrer</Button>
</div>
</Form>
)}
</div>
</DefaultNotaryDashboard>
);
@ -121,11 +137,6 @@ class UpdateFolderCollaboratorsClass extends BasePage<IPropsClass, IState> {
value: collaborator.uid,
};
});
this.setState({ selectedCollaborators: preSelectedCollaborators });
} 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 = {
@ -140,8 +151,19 @@ class UpdateFolderCollaboratorsClass extends BasePage<IPropsClass, IState> {
};
const availableCollaborators = await Users.getInstance().get(userQuery);
console.log(availableCollaborators)
this.setState({ availableCollaborators });
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;
}
}
private onSelectedOptionAllOffice(event: React.ChangeEvent<HTMLInputElement>) {