You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.6 KiB
96 lines
2.6 KiB
4 years ago
|
import React, { Component } from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
|
import Button from '../../components/ui/button';
|
||
5 years ago
|
|
||
|
export default class NewAccountCreateForm extends Component {
|
||
5 years ago
|
static defaultProps = {
|
||
|
newAccountNumber: 0,
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
5 years ago
|
state = {
|
||
|
newAccountName: '',
|
||
|
defaultAccountName: this.context.t('newAccountNumberName', [
|
||
|
this.props.newAccountNumber,
|
||
|
]),
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
4 years ago
|
render() {
|
||
4 years ago
|
const { newAccountName, defaultAccountName } = this.state;
|
||
|
const { history, createAccount, mostRecentOverviewPage } = this.props;
|
||
5 years ago
|
const createClick = (_) => {
|
||
5 years ago
|
createAccount(newAccountName || defaultAccountName)
|
||
|
.then(() => {
|
||
|
this.context.metricsEvent({
|
||
|
eventOpts: {
|
||
|
category: 'Accounts',
|
||
|
action: 'Add New Account',
|
||
|
name: 'Added New Account',
|
||
|
},
|
||
4 years ago
|
});
|
||
|
history.push(mostRecentOverviewPage);
|
||
5 years ago
|
})
|
||
|
.catch((e) => {
|
||
|
this.context.metricsEvent({
|
||
|
eventOpts: {
|
||
|
category: 'Accounts',
|
||
|
action: 'Add New Account',
|
||
|
name: 'Error',
|
||
|
},
|
||
|
customVariables: {
|
||
|
errorMessage: e.message,
|
||
|
},
|
||
4 years ago
|
});
|
||
|
});
|
||
|
};
|
||
5 years ago
|
|
||
|
return (
|
||
|
<div className="new-account-create-form">
|
||
|
<div className="new-account-create-form__input-label">
|
||
|
{this.context.t('accountName')}
|
||
|
</div>
|
||
5 years ago
|
<div>
|
||
5 years ago
|
<input
|
||
|
className="new-account-create-form__input"
|
||
5 years ago
|
value={newAccountName}
|
||
|
placeholder={defaultAccountName}
|
||
4 years ago
|
onChange={(event) =>
|
||
|
this.setState({ newAccountName: event.target.value })
|
||
|
}
|
||
4 years ago
|
autoFocus
|
||
5 years ago
|
/>
|
||
5 years ago
|
<div className="new-account-create-form__buttons">
|
||
|
<Button
|
||
|
type="default"
|
||
|
large
|
||
|
className="new-account-create-form__button"
|
||
5 years ago
|
onClick={() => history.push(mostRecentOverviewPage)}
|
||
5 years ago
|
>
|
||
|
{this.context.t('cancel')}
|
||
|
</Button>
|
||
|
<Button
|
||
|
type="secondary"
|
||
|
large
|
||
|
className="new-account-create-form__button"
|
||
|
onClick={createClick}
|
||
|
>
|
||
|
{this.context.t('create')}
|
||
|
</Button>
|
||
|
</div>
|
||
5 years ago
|
</div>
|
||
|
</div>
|
||
4 years ago
|
);
|
||
5 years ago
|
}
|
||
|
}
|
||
|
|
||
|
NewAccountCreateForm.propTypes = {
|
||
|
createAccount: PropTypes.func,
|
||
|
newAccountNumber: PropTypes.number,
|
||
|
history: PropTypes.object,
|
||
5 years ago
|
mostRecentOverviewPage: PropTypes.string.isRequired,
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
|
NewAccountCreateForm.contextTypes = {
|
||
|
t: PropTypes.func,
|
||
|
metricsEvent: PropTypes.func,
|
||
4 years ago
|
};
|