import React, { Component } from 'react'; import PropTypes from 'prop-types'; import Button from '../../components/ui/button'; export default class NewAccountCreateForm extends Component { static defaultProps = { newAccountNumber: 0, }; state = { newAccountName: '', defaultAccountName: this.context.t('newAccountNumberName', [ this.props.newAccountNumber, ]), }; render() { const { newAccountName, defaultAccountName } = this.state; const { history, createAccount, mostRecentOverviewPage } = this.props; const createClick = (_) => { createAccount(newAccountName || defaultAccountName) .then(() => { this.context.metricsEvent({ eventOpts: { category: 'Accounts', action: 'Add New Account', name: 'Added New Account', }, }); history.push(mostRecentOverviewPage); }) .catch((e) => { this.context.metricsEvent({ eventOpts: { category: 'Accounts', action: 'Add New Account', name: 'Error', }, customVariables: { errorMessage: e.message, }, }); }); }; return (
{this.context.t('accountName')}
this.setState({ newAccountName: event.target.value }) } autoFocus />
); } } NewAccountCreateForm.propTypes = { createAccount: PropTypes.func, newAccountNumber: PropTypes.number, history: PropTypes.object, mostRecentOverviewPage: PropTypes.string.isRequired, }; NewAccountCreateForm.contextTypes = { t: PropTypes.func, metricsEvent: PropTypes.func, };