fix(client): sync Redux store and DB (#39034)

This commit is contained in:
Oliver Eyton-Williams
2020-06-10 08:54:19 +02:00
committed by GitHub
parent 0fd8b7a6db
commit 6b8c2e74b6
3 changed files with 16 additions and 9 deletions

View File

@ -370,7 +370,11 @@ function createVerifyCert(certTypeIds, app) {
type: message.includes('Congratulations') ? 'success' : 'info', type: message.includes('Congratulations') ? 'success' : 'info',
message message
}, },
isCertMap: getUserIsCertMap(user) isCertMap: getUserIsCertMap(user),
// send back the completed challenges
// NOTE: we could just send back the latest challenge, but this
// ensures the challenges are synced.
completedChallenges: user.completedChallenges
}); });
}, next); }, next);
}; };

View File

@ -482,12 +482,10 @@ export const reducer = handleActions(
error: payload error: payload
} }
}), }),
[types.submitComplete]: (state, { payload: { id, challArray } }) => { [types.submitComplete]: (state, { payload }) => {
// TODO: possibly more of the payload (files?) should be added let submittedchallenges = [{ ...payload, completedDate: Date.now() }];
// to the completedChallenges array. if (payload.challArray) {
let submittedchallenges = [{ id, completedDate: Date.now() }]; submittedchallenges = payload.challArray;
if (challArray) {
submittedchallenges = challArray;
} }
const { appUsername } = state; const { appUsername } = state;
return { return {

View File

@ -79,9 +79,14 @@ function* validateUsernameSaga({ payload }) {
function* verifyCertificationSaga({ payload }) { function* verifyCertificationSaga({ payload }) {
try { try {
const { const {
data: { response, isCertMap } data: { response, isCertMap, completedChallenges }
} = yield call(putVerifyCert, payload); } = yield call(putVerifyCert, payload);
yield put(verifyCertComplete({ ...response, payload: isCertMap })); yield put(
verifyCertComplete({
...response,
payload: { ...isCertMap, completedChallenges }
})
);
yield put(createFlashMessage(response)); yield put(createFlashMessage(response));
} catch (e) { } catch (e) {
yield put(verifyCertError(e)); yield put(verifyCertError(e));