diff --git a/src/components/Account/Activate/Activate.actions.js b/src/components/Account/Activate/Activate.actions.js index d6def3fed..37b6be693 100644 --- a/src/components/Account/Activate/Activate.actions.js +++ b/src/components/Account/Activate/Activate.actions.js @@ -7,11 +7,7 @@ export function activate(url) { return axios .post(`${API_URL}user/activate/${url}`) .then(response => { - setTimeout(() => { - window.location.href = '/'; - }, 1000); - - return response.data; + return { ...response.data, success: true }; }) .catch(get('response.data')); } diff --git a/src/components/Account/Activate/Activate.container.js b/src/components/Account/Activate/Activate.container.js index 601c7bda6..65ec108bc 100644 --- a/src/components/Account/Activate/Activate.container.js +++ b/src/components/Account/Activate/Activate.container.js @@ -3,6 +3,9 @@ import { Link } from 'react-router-dom'; import { activate } from './Activate.actions'; import './Activate.css'; +import { FormattedMessage } from 'react-intl'; +import messages from './Activate.messages'; + class ActivateContainer extends PureComponent { state = { isActivating: false, @@ -19,24 +22,47 @@ class ActivateContainer extends PureComponent { this.setState({ isActivating: true }); activate(url) - .then(activationStatus => this.setState({ activationStatus })) - .catch(activationStatus => this.setState({ activationStatus })) + .then(activationStatus => { + this.setState({ activationStatus }); + if (activationStatus.success) { + setTimeout(() => { + this.props.history.replace('/login-signup'); + }, 2000); + return; + } + this.handleError(); + }) + .catch(activationStatus => { + this.setState({ activationStatus }); + this.handleError(); + }) .finally(() => this.setState({ isActivating: false })); } + handleError() { + this.setState({ error: true }); + setTimeout(() => { + this.props.history.replace('/login-signup'); + }, 2000); + } + render() { - const { isActivating, activationStatus } = this.state; + const { isActivating, error } = this.state; return (
{isActivating ? ( - 'Activating your account...' + ) : ( - {activationStatus.message} + {error ? ( + + ) : ( + + )}
- - Home page + +
)} diff --git a/src/components/Account/Activate/Activate.messages.js b/src/components/Account/Activate/Activate.messages.js new file mode 100644 index 000000000..43ad16a87 --- /dev/null +++ b/src/components/Account/Activate/Activate.messages.js @@ -0,0 +1,21 @@ +import { defineMessages } from 'react-intl'; + +export default defineMessages({ + activating: { + id: 'cboard.components.Activate.activating', + defaultMessage: 'Activating your account...' + }, + loginSignUpPage: { + id: 'cboard.components.Activate.LoginSignUpPage', + defaultMessage: 'Login or sign up page' + }, + error: { + id: 'cboard.components.Activate.error', + defaultMessage: + 'ERROR: confirming your temporary user FAILED, please try to login again' + }, + success: { + id: 'cboard.components.Activate.success', + defaultMessage: 'CONFIRMED!' + } +}); diff --git a/src/components/Account/Login/Login.actions.js b/src/components/Account/Login/Login.actions.js index c309a1841..94417c2f5 100644 --- a/src/components/Account/Login/Login.actions.js +++ b/src/components/Account/Login/Login.actions.js @@ -31,8 +31,12 @@ export function loginSuccess(payload) { }; } -function firstLoginActions(dispatch, payload) { - API.updateUser({ ...payload, isFirstLogin: false }); +async function firstLoginActions(dispatch, payload) { + try { + await API.updateUser({ ...payload, isFirstLogin: false }); + } catch (err) { + console.error(err); + } dispatch(enableAllTours()); } @@ -56,7 +60,7 @@ function logoutSuccess() { }; } -export function login({ email, password }, type = 'local') { +export function login({ email, password, activatedData }, type = 'local') { const setAVoice = ({ loginData, dispatch, getState }) => { const { language: { lang: appLang }, @@ -130,7 +134,9 @@ export function login({ email, password }, type = 'local') { return async (dispatch, getState) => { try { const apiMethod = type === 'local' ? 'login' : 'oAuthLogin'; - const loginData = await API[apiMethod](email, password); + const loginData = activatedData + ? activatedData + : await API[apiMethod](email, password); const { communicator, board } = getState(); const activeCommunicatorId = communicator.activeCommunicatorId; diff --git a/src/translations/src/cboard.json b/src/translations/src/cboard.json index 6c054df26..0f73a044c 100644 --- a/src/translations/src/cboard.json +++ b/src/translations/src/cboard.json @@ -12,6 +12,10 @@ "cboard.components.WelcomeScreenInformation.text": "Cboard helps users with speech and language impairments to communicate with symbols and text-to-speech.", "cboard.components.AuthScreenInformation.heading": "Cboard", "cboard.components.AuthScreenInformation.text": "Sign up to sync your settings!", + "cboard.components.Activate.activating": "Activating your account...", + "cboard.components.Activate.loginSignUpPage": "Login or sign up page", + "cboard.components.Activate.error": "ERROR: confirming your temporary user FAILED, please try to login again", + "cboard.components.Activate.success": "CONFIRMED!", "cboard.components.Login.loginToCboard": "Login to Cboard", "cboard.components.Login.login": "Login", "cboard.components.Login.email": "Email",