import React from 'react'; import PropTypes from 'prop-types'; import i18next from 'i18next'; import { withTranslation } from 'react-i18next'; import FormGroup from 'react-bootstrap/es/FormGroup'; import Radio from 'react-bootstrap/es/Radio'; class InstallerForm extends React.Component { constructor(props) { super(props); this.state = { isValidUserName: true, checkedBtn: 'en-US', }; 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) => { return this.setState({ isValidUserName: res.data.valid }) }); } changeLanguage(locale) { i18next.changeLanguage(locale); this.setState({ checkedBtn: locale }); } render() { const hasErrorClass = this.state.isValidUserName ? '' : ' has-error'; const unavailableUserId = this.state.isValidUserName ? '' : { this.props.t('installer.unavaliable_user_id') }; const checkedBtn = this.state.checkedBtn; return (

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

{ if (e.target.checked) { this.changeLanguage('en-US') } }} > English { if (e.target.checked) { 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 withTranslation()(InstallerForm);