import React from 'react'; import PropTypes from 'prop-types'; import i18next from 'i18next'; import { translate } from 'react-i18next'; class InstallerForm extends React.Component { constructor(props) { super(props); this.state = { isValidUserName: true, }; this.checkUserName = this.checkUserName.bind(this); } componentWillMount() { this.changeLanguage('en-US'); } checkUserName(event) { const axios = require('axios').create({ headers: { 'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest' }, responseType: 'json' }); axios.get('/_api/check_username', {params: {username: event.target.value}}) .then((res) => this.setState({ isValidUserName: res.data.valid })); } changeLanguage(locale) { i18next.changeLanguage(locale); } render() { const hasErrorClass = this.state.isValidUserName ? '' : ' has-error'; const unavailableUserId = this.state.isValidUserName ? '' : { this.props.t('installer.unavaliable_user_id') }; return (

{ this.props.t('installer.create_initial_account') }
{ this.props.t('installer.initial_account_will_be_administrator_automatically') }

this.changeLanguage('en-US')} />
this.changeLanguage('ja')} />

{ unavailableUserId }

); } } InstallerForm.propTypes = { // i18next t: PropTypes.func.isRequired, // for input value userName: PropTypes.string, name: PropTypes.string, email: PropTypes.string, csrf: PropTypes.string, }; export default translate()(InstallerForm);