2021-02-04 19:15:23 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import Button from '../../components/ui/button';
|
2019-10-29 17:12:41 +01:00
|
|
|
|
|
|
|
export default class NewAccountCreateForm extends Component {
|
2019-12-19 23:00:22 +01:00
|
|
|
static defaultProps = {
|
|
|
|
newAccountNumber: 0,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-10-29 17:12:41 +01:00
|
|
|
|
2019-12-19 23:00:22 +01:00
|
|
|
state = {
|
|
|
|
newAccountName: '',
|
|
|
|
defaultAccountName: this.context.t('newAccountNumberName', [
|
|
|
|
this.props.newAccountNumber,
|
|
|
|
]),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-10-29 17:12:41 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { newAccountName, defaultAccountName } = this.state;
|
|
|
|
const { history, createAccount, mostRecentOverviewPage } = this.props;
|
2020-02-15 21:34:12 +01:00
|
|
|
const createClick = (_) => {
|
2019-10-29 17:12:41 +01:00
|
|
|
createAccount(newAccountName || defaultAccountName)
|
|
|
|
.then(() => {
|
|
|
|
this.context.metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Accounts',
|
|
|
|
action: 'Add New Account',
|
|
|
|
name: 'Added New Account',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
history.push(mostRecentOverviewPage);
|
2019-10-29 17:12:41 +01:00
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
this.context.metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Accounts',
|
|
|
|
action: 'Add New Account',
|
|
|
|
name: 'Error',
|
|
|
|
},
|
|
|
|
customVariables: {
|
|
|
|
errorMessage: e.message,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2019-10-29 17:12:41 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="new-account-create-form">
|
|
|
|
<div className="new-account-create-form__input-label">
|
|
|
|
{this.context.t('accountName')}
|
|
|
|
</div>
|
2020-05-28 22:23:50 +02:00
|
|
|
<div>
|
2019-12-03 17:35:44 +01:00
|
|
|
<input
|
|
|
|
className="new-account-create-form__input"
|
2019-10-29 17:12:41 +01:00
|
|
|
value={newAccountName}
|
|
|
|
placeholder={defaultAccountName}
|
2020-11-03 00:41:28 +01:00
|
|
|
onChange={(event) =>
|
|
|
|
this.setState({ newAccountName: event.target.value })
|
|
|
|
}
|
2020-10-14 18:43:26 +02:00
|
|
|
autoFocus
|
2019-10-29 17:12:41 +01:00
|
|
|
/>
|
2020-05-28 22:23:50 +02:00
|
|
|
<div className="new-account-create-form__buttons">
|
|
|
|
<Button
|
|
|
|
type="default"
|
|
|
|
large
|
|
|
|
className="new-account-create-form__button"
|
2020-06-01 19:54:32 +02:00
|
|
|
onClick={() => history.push(mostRecentOverviewPage)}
|
2020-05-28 22:23:50 +02:00
|
|
|
>
|
|
|
|
{this.context.t('cancel')}
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
type="secondary"
|
|
|
|
large
|
|
|
|
className="new-account-create-form__button"
|
|
|
|
onClick={createClick}
|
|
|
|
>
|
|
|
|
{this.context.t('create')}
|
|
|
|
</Button>
|
|
|
|
</div>
|
2019-10-29 17:12:41 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-10-29 17:12:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NewAccountCreateForm.propTypes = {
|
|
|
|
createAccount: PropTypes.func,
|
|
|
|
newAccountNumber: PropTypes.number,
|
|
|
|
history: PropTypes.object,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: PropTypes.string.isRequired,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-10-29 17:12:41 +01:00
|
|
|
|
|
|
|
NewAccountCreateForm.contextTypes = {
|
|
|
|
t: PropTypes.func,
|
|
|
|
metricsEvent: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|