Commit 58ed174d authored by Antoine's avatar Antoine
Browse files

[client] Make AccountSelect a controlled component. Fix #1031.

parent 6276d2b7
Pipeline #359311 passed with stage
in 4 minutes and 2 seconds
......@@ -17,6 +17,7 @@ export default connect(
return {
accessIds: get.accessIds(state),
isDemoMode: get.isDemoMode(state),
defaultAccountId: get.defaultAccountId(state),
};
},
dispatch => {
......@@ -31,7 +32,12 @@ export default connect(
<FormRow
label={$t('client.accesses.default_account')}
inputId="default-account-selector"
input={<AccountSelector onChange={props.setDefault} />}
input={
<AccountSelector
onChange={props.setDefault}
selectedAccountId={props.defaultAccountId}
/>
}
help={$t('client.accesses.default_account_helper')}
/>
<DisplayIf condition={!props.isDemoMode}>
......
......@@ -16,6 +16,7 @@ const AlertCreationModal = connect(
state => {
return {
type: get.modal(state).state,
defaultAccountId: get.defaultAccountId(state),
};
},
dispatch => {
......@@ -34,7 +35,7 @@ const AlertCreationModal = connect(
class Content extends React.Component {
state = {
limit: null,
accountId: null,
accountId: this.props.defaultAccountId,
};
refOrderSelect = node => (this.order = node);
......@@ -67,7 +68,11 @@ const AlertCreationModal = connect(
<form id={MODAL_SLUG} onSubmit={this.handleSubmit}>
<div className="cols-with-label">
<label htmlFor="account">{$t('client.settings.emails.account')}</label>
<AccountSelector onChange={this.handleChangeAccount} id="account" />
<AccountSelector
onChange={this.handleChangeAccount}
id="account"
selectedAccountId={this.state.accountId}
/>
</div>
<div className="cols-with-label">
......
......@@ -2,7 +2,7 @@ import React from 'react';
import { connect } from 'react-redux';
import { translate as $t } from '../../../helpers';
import { actions } from '../../../store';
import { actions, get } from '../../../store';
import { registerModal } from '../../ui/modal';
import AccountSelector from '../../ui/account-select';
......@@ -11,21 +11,28 @@ import CancelAndSubmit from '../../ui/modal/cancel-and-submit-buttons';
export const MODAL_SLUG = 'report-creation';
const ReportCreationModal = connect(null, dispatch => {
return {
async createAlert(newAlert) {
try {
await actions.createAlert(dispatch, newAlert);
actions.hideModal(dispatch);
} catch (err) {
// TODO properly report.
}
},
};
})(
const ReportCreationModal = connect(
state => {
return {
defaultAccountId: get.defaultAccountId(state),
};
},
dispatch => {
return {
async createAlert(newAlert) {
try {
await actions.createAlert(dispatch, newAlert);
actions.hideModal(dispatch);
} catch (err) {
// TODO properly report.
}
},
};
}
)(
class Content extends React.Component {
state = {
accountId: null,
accountId: this.props.defaultAccountId,
};
refFrequencySelect = node => (this.frequency = node);
......@@ -52,7 +59,11 @@ const ReportCreationModal = connect(null, dispatch => {
<form id={MODAL_SLUG} onSubmit={this.handleSubmit}>
<div className="cols-with-label">
<label htmlFor="account">{$t('client.settings.emails.account')}</label>
<AccountSelector onChange={this.handleChangeAccount} id="account" />
<AccountSelector
onChange={this.handleChangeAccount}
id="account"
selectedAccountId={this.state.accountId}
/>
</div>
<div className="cols-with-label">
......
......@@ -22,7 +22,6 @@ const AccountSelector = connect(state => {
return {
pairs,
defaultAccount: get.defaultAccountId(state),
};
})(
class Selector extends React.Component {
......@@ -40,7 +39,7 @@ const AccountSelector = connect(state => {
<select
onChange={this.handleChange}
className="form-element-block"
value={this.props.defaultAccount}>
value={this.props.selectedAccountId}>
{options}
</select>
);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment