feat: add message to warn users before changing name (#37527)

Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
Co-authored-by: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com>
This commit is contained in:
Parth Parth
2019-11-04 18:54:18 +05:30
committed by mrugesh
parent 94340c7b1a
commit c2e7809ccd

View File

@ -47,11 +47,14 @@ const mapDispatchToProps = dispatch =>
const invalidCharsRE = /[/\s?:@=&"'<>#%{}|\\^~[\]`,.;!*()$]/;
const invlaidCharError = {
valid: false,
error: 'Username contains invalid characters'
error: 'Username contains invalid characters.'
};
const valididationSuccess = { valid: true, error: null };
const usernameTooShort = { valid: false, error: 'Username is too short' };
const hex = '[0-9a-f]';
const tempUserRegex = new RegExp(`^fcc${hex}{8}-(${hex}{4}-){3}${hex}{12}$`);
class UsernameSettings extends Component {
constructor(props) {
super(props);
@ -60,7 +63,8 @@ class UsernameSettings extends Component {
isFormPristine: true,
formValue: props.username,
characterValidation: { valid: false, error: null },
submitClicked: false
submitClicked: false,
isUserNew: tempUserRegex.test(props.username)
};
this.handleChange = this.handleChange.bind(this);
@ -77,7 +81,8 @@ class UsernameSettings extends Component {
/* eslint-disable-next-line react/no-did-update-set-state */
return this.setState({
isFormPristine: username === formValue,
submitClicked: false
submitClicked: false,
isUserNew: tempUserRegex.test(username)
});
}
return null;
@ -138,21 +143,31 @@ class UsernameSettings extends Component {
if (!validating && !isValidUsername) {
return (
<FullWidthRow>
<Alert bsStyle='warning'>Username not available</Alert>
<Alert bsStyle='warning'>Username not available.</Alert>
</FullWidthRow>
);
}
if (validating) {
return (
<FullWidthRow>
<Alert bsStyle='info'>Validating username</Alert>
<Alert bsStyle='info'>Validating username...</Alert>
</FullWidthRow>
);
}
if (!validating && isValidUsername) {
if (!validating && isValidUsername && this.state.isUserNew) {
return (
<FullWidthRow>
<Alert bsStyle='success'>Username is available</Alert>
<Alert bsStyle='success'>Username is available.</Alert>
</FullWidthRow>
);
} else if (!validating && isValidUsername && !this.state.isUserNew) {
return (
<FullWidthRow>
<Alert bsStyle='success'>Username is available.</Alert>
<Alert bsStyle='info'>
Please note, changing your username will also change the URL to your
profile and your certifications.
</Alert>
</FullWidthRow>
);
}