🐛 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; selectedFolder: OfficeFolder | null;
selectedOption?: ERadioBoxValue; selectedOption?: ERadioBoxValue;
availableCollaborators: User[]; availableCollaborators: User[];
defaultCheckedAllOffice: boolean;
selectedCollaborators: readonly IOption[]; selectedCollaborators: readonly IOption[];
loading: boolean;
}; };
enum ERadioBoxValue { enum ERadioBoxValue {
@ -39,6 +41,9 @@ class UpdateFolderCollaboratorsClass extends BasePage<IPropsClass, IState> {
selectedFolder: null, selectedFolder: null,
availableCollaborators: [], availableCollaborators: [],
selectedCollaborators: [], selectedCollaborators: [],
defaultCheckedAllOffice: false,
selectedOption: ERadioBoxValue.SELECTION,
loading: true,
}; };
this.onSelectedFolder = this.onSelectedFolder.bind(this); this.onSelectedFolder = this.onSelectedFolder.bind(this);
this.onSelectedOptionAllOffice = this.onSelectedOptionAllOffice.bind(this); this.onSelectedOptionAllOffice = this.onSelectedOptionAllOffice.bind(this);
@ -55,6 +60,7 @@ class UpdateFolderCollaboratorsClass extends BasePage<IPropsClass, IState> {
value: collaborator.uid, value: collaborator.uid,
}; };
}); });
return ( return (
<DefaultNotaryDashboard title={"Ajouter client(s)"} onSelectedFolder={this.onSelectedFolder}> <DefaultNotaryDashboard title={"Ajouter client(s)"} onSelectedFolder={this.onSelectedFolder}>
<div className={classes["root"]}> <div className={classes["root"]}>
@ -63,12 +69,21 @@ class UpdateFolderCollaboratorsClass extends BasePage<IPropsClass, IState> {
</div> </div>
<Typography typo={ITypo.H1Bis}>Modifier les collaborateurs</Typography> <Typography typo={ITypo.H1Bis}>Modifier les collaborateurs</Typography>
{!this.state.loading && (
<Form className={classes["form"]} onSubmit={this.onFormSubmit}> <Form className={classes["form"]} onSubmit={this.onFormSubmit}>
<div className={classes["content"]}> <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 Tout l'office
</RadioBox> </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 Sélectionner des collaborateurs
</RadioBox> </RadioBox>
</div> </div>
@ -91,6 +106,7 @@ class UpdateFolderCollaboratorsClass extends BasePage<IPropsClass, IState> {
<Button type="submit">Enregistrer</Button> <Button type="submit">Enregistrer</Button>
</div> </div>
</Form> </Form>
)}
</div> </div>
</DefaultNotaryDashboard> </DefaultNotaryDashboard>
); );
@ -121,11 +137,6 @@ class UpdateFolderCollaboratorsClass extends BasePage<IPropsClass, IState> {
value: collaborator.uid, 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 // 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 = { const userQuery: IGetUsersParams = {
@ -140,8 +151,19 @@ class UpdateFolderCollaboratorsClass extends BasePage<IPropsClass, IState> {
}; };
const availableCollaborators = await Users.getInstance().get(userQuery); 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>) { private onSelectedOptionAllOffice(event: React.ChangeEvent<HTMLInputElement>) {