2019-12-30 10:47:29 +02:00
import React from 'react' ;
2020-06-04 19:41:27 +03:00
import { defineMessages , FormattedMessage as Message } from 'react-intl' ;
2019-12-30 09:29:39 +02:00
import { Helmet } from 'react-helmet-async' ;
2019-12-07 21:02:00 +02:00
import { Input , Button , Form , FormModel } from 'app/components/ui/form' ;
import { BackButton } from 'app/components/profile/ProfileForm' ;
2016-05-02 20:32:03 +03:00
2019-12-30 10:47:29 +02:00
import styles from '../profileForm.scss' ;
2020-06-04 19:41:27 +03:00
const labels = defineMessages ( {
changeUsernameButton : 'Change nickname' ,
} ) ;
2016-05-02 16:13:18 +03:00
2019-12-30 10:47:29 +02:00
interface Props {
2020-05-24 02:08:24 +03:00
username : string ;
form : FormModel ;
onChange : ( name : string ) = > void ;
onSubmit : ( form : FormModel ) = > Promise < void > ;
2019-12-30 10:47:29 +02:00
}
2019-11-27 11:03:32 +02:00
2019-12-30 10:47:29 +02:00
export default class ChangeUsername extends React . Component < Props > {
2020-05-24 02:08:24 +03:00
static get defaultProps ( ) : Partial < Props > {
return {
form : new FormModel ( ) ,
} ;
}
2019-11-27 11:03:32 +02:00
2020-05-24 02:08:24 +03:00
render() {
const { form , username } = this . props ;
2019-11-27 11:03:32 +02:00
2020-05-24 02:08:24 +03:00
return (
< Form onSubmit = { this . onFormSubmit } form = { form } >
< div className = { styles.contentWithBackButton } >
< BackButton / >
2019-11-27 11:03:32 +02:00
2020-05-24 02:08:24 +03:00
< div className = { styles . form } >
< div className = { styles . formBody } >
2020-06-04 19:41:27 +03:00
< Message key = "changeUsernameTitle" defaultMessage = "Change nickname" >
2020-05-24 02:08:24 +03:00
{ ( pageTitle ) = > (
< h3 className = { styles . title } >
< Helmet title = { pageTitle as string } / >
{ pageTitle }
< / h3 >
) }
< / Message >
2019-11-27 11:03:32 +02:00
2020-05-24 02:08:24 +03:00
< div className = { styles . formRow } >
< p className = { styles . description } >
2020-06-04 19:41:27 +03:00
< Message
key = "changeUsernameDescription"
defaultMessage = "You can change your nickname to any arbitrary value. Remember that it is not recommended to take a nickname of already existing Mojang account."
/ >
2020-05-24 02:08:24 +03:00
< / p >
< / div >
2019-11-27 11:03:32 +02:00
2020-05-24 02:08:24 +03:00
< div className = { styles . formRow } >
< Input
{ . . . form . bindField ( 'username' ) }
2020-07-21 15:30:18 +03:00
defaultValue = { username }
2020-05-24 02:08:24 +03:00
onChange = { this . onUsernameChange }
required
skin = "light"
/ >
< / div >
2019-11-27 11:03:32 +02:00
2020-05-24 02:08:24 +03:00
< div className = { styles . formRow } >
< p className = { styles . description } >
2020-06-04 19:41:27 +03:00
< Message
key = "changeUsernameWarning"
defaultMessage = "Be careful: if you playing on the server with nickname binding, then after changing nickname you may lose all your progress."
/ >
2020-05-24 02:08:24 +03:00
< / p >
< / div >
< / div >
2019-11-27 11:03:32 +02:00
2020-06-04 19:41:27 +03:00
< Button color = "green" block label = { labels . changeUsernameButton } type = "submit" / >
2020-05-24 02:08:24 +03:00
< / div >
< / div >
< / Form >
) ;
}
2019-11-27 11:03:32 +02:00
2020-05-24 02:08:24 +03:00
onUsernameChange = ( event : React.ChangeEvent < HTMLInputElement > ) = > {
this . props . onChange ( event . target . value ) ;
} ;
2019-11-27 11:03:32 +02:00
2020-05-24 02:08:24 +03:00
onFormSubmit = ( ) = > {
const { form } = this . props ;
2019-11-27 11:03:32 +02:00
2020-05-24 02:08:24 +03:00
this . props . onSubmit ( form ) . catch ( ( resp ) = > {
if ( resp . errors ) {
form . setErrors ( resp . errors ) ;
} else {
return Promise . reject ( resp ) ;
}
} ) ;
} ;
2016-05-02 16:13:18 +03:00
}