import React, { Component } from 'react' import PropTypes from 'prop-types' import { DEFAULT_ROUTE } from '../../helpers/constants/routes' import Button from '../../components/ui/button' export default class NewAccountCreateForm extends Component { constructor (props, context) { super(props) const { newAccountNumber = 0 } = props this.state = { newAccountName: '', defaultAccountName: context.t('newAccountNumberName', [newAccountNumber]), } } render () { const { newAccountName, defaultAccountName } = this.state const { history, createAccount } = this.props const createClick = _ => { createAccount(newAccountName || defaultAccountName) .then(() => { this.context.metricsEvent({ eventOpts: { category: 'Accounts', action: 'Add New Account', name: 'Added New Account', }, }) history.push(DEFAULT_ROUTE) }) .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 })} />
) } } NewAccountCreateForm.propTypes = { hideModal: PropTypes.func, showImportPage: PropTypes.func, showConnectPage: PropTypes.func, createAccount: PropTypes.func, numberOfExistingAccounts: PropTypes.number, newAccountNumber: PropTypes.number, history: PropTypes.object, t: PropTypes.func, } NewAccountCreateForm.contextTypes = { t: PropTypes.func, metricsEvent: PropTypes.func, }