import React from 'react'; import PropTypes from 'prop-types'; import styles from './ChangeUsernameContentDialog.css'; import InputField from './InputField'; import { Button } from 'plugin-api/beta/client/components/ui'; import { t } from 'plugin-api/beta/client/services'; class ChangeUsernameContentDialog extends React.Component { state = { showError: false, }; showError = () => { this.setState({ showError: true, }); }; confirmChanges = async e => { e.preventDefault(); if (this.formHasError()) { this.showError(); return; } if (!this.props.canUsernameBeUpdated) { this.props.notify( 'error', t('talk-plugin-local-auth.change_username.change_username_attempt') ); return; } await this.props.save(); this.props.next(); }; formHasError = () => this.props.formData.confirmNewUsername !== this.props.formData.newUsername; render() { return (
×

{t('talk-plugin-local-auth.change_username.confirm_username_change')}

{t('talk-plugin-local-auth.change_username.description')}

{t('talk-plugin-local-auth.change_username.old_username')}:{' '} {this.props.username} {t('talk-plugin-local-auth.change_username.new_username')}:{' '} {this.props.formData.newUsername}
{t('talk-plugin-local-auth.change_username.bottom_note')}
); } } ChangeUsernameContentDialog.propTypes = { save: PropTypes.func, next: PropTypes.func, cancel: PropTypes.func, onChange: PropTypes.func, formData: PropTypes.object, username: PropTypes.string, canUsernameBeUpdated: PropTypes.bool.isRequired, notify: PropTypes.func.isRequired, }; export default ChangeUsernameContentDialog;