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