import React from 'react'; import i18next from 'i18next'; import PropTypes from 'prop-types'; import { useTranslation } from 'react-i18next'; import { localeMetadatas } from '~/client/util/i18n'; import { useCsrfToken } from '~/stores/context'; class InstallerForm extends React.Component { constructor(props) { super(props); this.state = { isValidUserName: true, isSubmittingDisabled: false, selectedLang: {}, }; // this.checkUserName = this.checkUserName.bind(this); this.submitHandler = this.submitHandler.bind(this); } componentWillMount() { const meta = localeMetadatas.find(v => v.id === i18next.language); if (meta == null) { return this.setState({ selectedLang: localeMetadatas[0] }); } this.setState({ selectedLang: meta }); } // 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(meta) { i18next.changeLanguage(meta.id); this.setState({ selectedLang: meta }); } submitHandler() { if (this.state.isSubmittingDisabled) { return; } this.setState({ isSubmittingDisabled: true }); setTimeout(() => { this.setState({ isSubmittingDisabled: false }); }, 3000); } 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') }