diff --git a/components/signup/signup_controller/signup_controller.jsx b/components/signup/signup_controller/signup_controller.jsx index 4f926d86d153b93d9e56968290d86d6d2ca89f0f..2158e0ae2735737990dbf70dc17c6c609690d41a 100644 --- a/components/signup/signup_controller/signup_controller.jsx +++ b/components/signup/signup_controller/signup_controller.jsx @@ -113,14 +113,14 @@ export default class SignupController extends React.Component { } getInviteInfo = async (inviteId) => { - const {data} = await this.props.actions.getTeamInviteInfo(inviteId); + const {data, error} = await this.props.actions.getTeamInviteInfo(inviteId); if (data) { this.setState({ serverError: '', loading: false, }); - } else { - this.handleInvalidInvite(); + } else if (error) { + this.handleInvalidInvite(error); } } diff --git a/components/signup/signup_email/signup_email.jsx b/components/signup/signup_email/signup_email.jsx index d06184736d99a1af7bcdbc60fb9822d8b7d79a33..2db3be13f86c9ade004957bf7b45490f303d8fa6 100644 --- a/components/signup/signup_email/signup_email.jsx +++ b/components/signup/signup_email/signup_email.jsx @@ -42,72 +42,63 @@ export default class SignupEmail extends React.Component { constructor(props) { super(props); - this.state = this.getInviteInfo(); + const data = (new URLSearchParams(this.props.location.search)).get('d'); + const token = (new URLSearchParams(this.props.location.search)).get('t'); + const inviteId = (new URLSearchParams(this.props.location.search)).get('id'); + + this.state = {}; + if (token && token.length > 0) { + this.state = this.getTokenData(token, data); + } else if (inviteId && inviteId.length > 0) { + this.state = { + loading: true, + inviteId, + }; + } } componentDidMount() { trackEvent('signup', 'signup_user_01_welcome'); - } - getInviteInfo = async () => { - let data = (new URLSearchParams(this.props.location.search)).get('d'); - let token = (new URLSearchParams(this.props.location.search)).get('t'); - const inviteId = (new URLSearchParams(this.props.location.search)).get('id'); - let email = ''; - let teamDisplayName = ''; - let teamName = ''; - let teamId = ''; - let loading = false; - const serverError = ''; - const noOpenServerError = false; - - if (token && token.length > 0) { - const parsedData = JSON.parse(data); - email = parsedData.email; - teamDisplayName = parsedData.display_name; - teamName = parsedData.name; - teamId = parsedData.id; - } else if (inviteId && inviteId.length > 0) { - loading = true; - data = null; - token = null; - const {data: inviteData, error} = await this.props.actions.getTeamInviteInfo(inviteId); - if (inviteData) { - this.setState({ - loading: false, - serverError: '', - teamDisplayName: inviteData.display_name, - teamName: inviteData.name, - teamId: inviteData.id, - }); - } else if (error) { - this.setState({ - loading: false, - noOpenServerError: true, - serverError: ( - - ), - }); - } + const {inviteId} = this.state; + if (inviteId && inviteId.length > 0) { + this.getInviteInfo(inviteId); } + } + + getTokenData = (token, data) => { + const parsedData = JSON.parse(data); return { - data, + loading: false, token, - email, - teamDisplayName, - teamName, - teamId, - inviteId, - loading, - serverError, - noOpenServerError, + email: parsedData.email, + teamName: parsedData.name, }; } + getInviteInfo = async (inviteId) => { + const {data, error} = await this.props.actions.getTeamInviteInfo(inviteId); + if (data) { + this.setState({ + loading: false, + noOpenServerError: false, + serverError: '', + teamName: data.name, + }); + } else if (error) { + this.setState({loading: false, + noOpenServerError: true, + serverError: ( + + ), + }); + } + } + handleSignupSuccess = (user, data) => { trackEvent('signup', 'signup_user_02_complete');