Skip to content

Commit

Permalink
Merge pull request #1553 from tomivm/fix/login-after-activate-account
Browse files Browse the repository at this point in the history
Fix/redirect to login page after activate an account
  • Loading branch information
martinbedouret authored Aug 11, 2023
2 parents b703182 + bc9fcaa commit 3c75c69
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 16 deletions.
6 changes: 1 addition & 5 deletions src/components/Account/Activate/Activate.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
40 changes: 33 additions & 7 deletions src/components/Account/Activate/Activate.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 (
<div className="Activate">
{isActivating ? (
'Activating your account...'
<FormattedMessage {...messages.activating} />
) : (
<Fragment>
{activationStatus.message}
{error ? (
<FormattedMessage {...messages.error} />
) : (
<FormattedMessage {...messages.success} />
)}
<br />
<Link to="/" className="Activate_home">
Home page
<Link to="/login-signup" className="Activate_home">
<FormattedMessage {...messages.loginSignUpPage} />
</Link>
</Fragment>
)}
Expand Down
21 changes: 21 additions & 0 deletions src/components/Account/Activate/Activate.messages.js
Original file line number Diff line number Diff line change
@@ -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!'
}
});
14 changes: 10 additions & 4 deletions src/components/Account/Login/Login.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand All @@ -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 },
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/translations/src/cboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 3c75c69

Please sign in to comment.