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',
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);
};

View File

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

View File

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