Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Migrated string refs in signup_email
Browse files Browse the repository at this point in the history
  • Loading branch information
varunks99 committed Oct 1, 2020
1 parent 51185f6 commit 9657da8
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions components/signup/signup_email/signup_email.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,18 @@ export default class SignupEmail extends React.PureComponent {
inviteId,
};
}

this.email = React.createRef();
this.name = React.createRef();
this.password = React.createRef();
}

componentDidMount() {
trackEvent('signup', 'signup_user_01_welcome');

this.setDocumentTitle(this.props.siteName);

const {inviteId} = this.state;
const { inviteId } = this.state;
if (inviteId && inviteId.length > 0) {
this.getInviteInfo(inviteId);
}
Expand Down Expand Up @@ -96,7 +100,7 @@ export default class SignupEmail extends React.PureComponent {
}

getInviteInfo = async (inviteId) => {
const {data, error} = await this.props.actions.getTeamInviteInfo(inviteId);
const { data, error } = await this.props.actions.getTeamInviteInfo(inviteId);
if (data) {
this.setState({
loading: false,
Expand All @@ -105,7 +109,8 @@ export default class SignupEmail extends React.PureComponent {
teamName: data.name,
});
} else if (error) {
this.setState({loading: false,
this.setState({
loading: false,
noOpenServerError: true,
serverError: (
<FormattedMessage
Expand All @@ -121,7 +126,7 @@ export default class SignupEmail extends React.PureComponent {
trackEvent('signup', 'signup_user_02_complete');
const redirectTo = (new URLSearchParams(this.props.location.search)).get('redirect_to');

this.props.actions.loginById(data.id, user.password, '').then(({error}) => {
this.props.actions.loginById(data.id, user.password, '').then(({ error }) => {
if (error) {
if (error.server_error_id === 'api.user.login.not_verified.app_error') {
let verifyUrl = '/should_verify_email?email=' + encodeURIComponent(user.email);
Expand All @@ -143,7 +148,7 @@ export default class SignupEmail extends React.PureComponent {
}

if (this.state.token > 0) {
this.props.actions.setGlobalItem(this.state.token, JSON.stringify({usedBefore: true}));
this.props.actions.setGlobalItem(this.state.token, JSON.stringify({ usedBefore: true }));
}

if (redirectTo) {
Expand All @@ -155,11 +160,11 @@ export default class SignupEmail extends React.PureComponent {
}

isUserValid = () => {
const providedEmail = this.refs.email.value.trim();
const providedEmail = this.email.current.value.trim();
if (!providedEmail) {
this.setState({
nameError: '',
emailError: (<FormattedMessage id='signup_user_completed.required'/>),
emailError: (<FormattedMessage id='signup_user_completed.required' />),
passwordError: '',
serverError: '',
});
Expand All @@ -169,17 +174,17 @@ export default class SignupEmail extends React.PureComponent {
if (!isEmail(providedEmail)) {
this.setState({
nameError: '',
emailError: (<FormattedMessage id='signup_user_completed.validEmail'/>),
emailError: (<FormattedMessage id='signup_user_completed.validEmail' />),
passwordError: '',
serverError: '',
});
return false;
}

const providedUsername = this.refs.name.value.trim().toLowerCase();
const providedUsername = this.name.current.value.trim().toLowerCase();
if (!providedUsername) {
this.setState({
nameError: (<FormattedMessage id='signup_user_completed.required'/>),
nameError: (<FormattedMessage id='signup_user_completed.required' />),
emailError: '',
passwordError: '',
serverError: '',
Expand All @@ -190,7 +195,7 @@ export default class SignupEmail extends React.PureComponent {
const usernameError = Utils.isValidUsername(providedUsername);
if (usernameError === 'Cannot use a reserved word as a username.') {
this.setState({
nameError: (<FormattedMessage id='signup_user_completed.reserved'/>),
nameError: (<FormattedMessage id='signup_user_completed.reserved' />),
emailError: '',
passwordError: '',
serverError: '',
Expand All @@ -214,8 +219,8 @@ export default class SignupEmail extends React.PureComponent {
return false;
}

const providedPassword = this.refs.password.value;
const {valid, error} = Utils.isValidPassword(providedPassword, this.props.passwordConfig);
const providedPassword = this.password.current.value;
const { valid, error } = Utils.isValidPassword(providedPassword, this.props.passwordConfig);
if (!valid && error) {
this.setState({
nameError: '',
Expand Down Expand Up @@ -248,9 +253,9 @@ export default class SignupEmail extends React.PureComponent {
});

const user = {
email: this.refs.email.value.trim(),
username: this.refs.name.value.trim().toLowerCase(),
password: this.refs.password.value,
email: this.email.current.value.trim(),
username: this.name.current.value.trim().toLowerCase(),
password: this.password.current.value,
allow_marketing: true,
};

Expand Down Expand Up @@ -351,7 +356,7 @@ export default class SignupEmail extends React.PureComponent {
<input
id='email'
type='email'
ref='email'
ref={this.email}
className='form-control'
defaultValue={this.state.email}
placeholder=''
Expand All @@ -378,7 +383,7 @@ export default class SignupEmail extends React.PureComponent {
<input
id='name'
type='text'
ref='name'
ref={this.name}
className='form-control'
placeholder=''
maxLength={Constants.MAX_USERNAME_LENGTH}
Expand All @@ -402,7 +407,7 @@ export default class SignupEmail extends React.PureComponent {
<input
id='password'
type='password'
ref='password'
ref={this.password}
className='form-control'
placeholder=''
maxLength='128'
Expand Down Expand Up @@ -454,7 +459,7 @@ export default class SignupEmail extends React.PureComponent {
}

if (this.state.loading) {
return (<LoadingScreen/>);
return (<LoadingScreen />);
}

let emailSignup;
Expand Down Expand Up @@ -487,7 +492,7 @@ export default class SignupEmail extends React.PureComponent {

return (
<div>
{hasAccounts && <BackButton onClick={() => trackEvent('signup_email', 'click_back')}/>}
{hasAccounts && <BackButton onClick={() => trackEvent('signup_email', 'click_back')} />}
<div
id='signup_email_section'
className='col-sm-12'
Expand Down

0 comments on commit 9657da8

Please sign in to comment.