fix: Rework reset progress saga to wait for the updated user
This commit is contained in:
@ -152,13 +152,9 @@ function getUnlinkSocial(req, res, next) {
|
||||
|
||||
function postResetProgress(req, res, next) {
|
||||
const { user } = req;
|
||||
user.updateAttributes(
|
||||
return user.updateAttributes(
|
||||
{
|
||||
progressTimestamps: [
|
||||
{
|
||||
timestamp: Date.now()
|
||||
}
|
||||
],
|
||||
progressTimestamps: [Date.now()],
|
||||
currentChallengeId: '',
|
||||
isRespWebDesignCert: false,
|
||||
is2018DataVisCert: false,
|
||||
@ -177,10 +173,7 @@ function postResetProgress(req, res, next) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
return res.status(200).json({
|
||||
messageType: 'success',
|
||||
message: 'You have successfully reset your progress'
|
||||
});
|
||||
return res.sendStatus(200);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -1,12 +1,8 @@
|
||||
import { navigate } from 'gatsby';
|
||||
import { call, put, takeEvery } from 'redux-saga/effects';
|
||||
import { call, put, takeEvery, take } from 'redux-saga/effects';
|
||||
|
||||
import {
|
||||
deleteAccountError,
|
||||
resetProgressComplete,
|
||||
resetProgressError
|
||||
} from './';
|
||||
import { resetUserData, fetchUser } from '../';
|
||||
import { deleteAccountError, resetProgressError } from './';
|
||||
import { resetUserData, fetchUser, types as appTypes } from '../';
|
||||
import { postResetProgress, postDeleteAccount } from '../../utils/ajax';
|
||||
import { createFlashMessage } from '../../components/Flash/redux';
|
||||
|
||||
@ -29,12 +25,19 @@ function* deleteAccountSaga() {
|
||||
|
||||
function* resetProgressSaga() {
|
||||
try {
|
||||
const { data: response } = yield call(postResetProgress);
|
||||
yield put(resetProgressComplete(response));
|
||||
yield call(postResetProgress);
|
||||
yield put(
|
||||
createFlashMessage({
|
||||
type: 'info',
|
||||
message: 'Your progress has been reset'
|
||||
})
|
||||
);
|
||||
// refresh current user data in application state
|
||||
yield put(fetchUser());
|
||||
// wait for the refresh to complete
|
||||
yield take(appTypes.fetchUserComplete);
|
||||
// the complete action has been called
|
||||
yield call(navigate, '/welcome');
|
||||
yield put(createFlashMessage(response));
|
||||
} catch (e) {
|
||||
yield put(resetProgressError(e));
|
||||
}
|
||||
|
@ -93,7 +93,6 @@ export const verifyCertComplete = createAction(
|
||||
export const verifyCertError = createAction(types.verifyCertError);
|
||||
|
||||
export const resetProgress = createAction(types.resetProgress);
|
||||
export const resetProgressComplete = createAction(types.resetProgressComplete);
|
||||
export const resetProgressError = createAction(types.resetProgressError);
|
||||
|
||||
export const deleteAccount = createAction(types.deleteAccount);
|
||||
|
Reference in New Issue
Block a user