From 7e74a25274e7df7c76adaf524eeadf5375aad7fb Mon Sep 17 00:00:00 2001 From: Sagirov Evgeniy <34642612+UvgenGen@users.noreply.github.com> Date: Tue, 15 Jun 2021 16:26:16 +0300 Subject: [PATCH] fix: End Exam Button doesn't work from outside special exam sequence (#24) --- src/data/thunks.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/data/thunks.js b/src/data/thunks.js index 5150c129..4d64a405 100644 --- a/src/data/thunks.js +++ b/src/data/thunks.js @@ -211,19 +211,25 @@ export function pollAttempt(url) { export function stopExam() { return async (dispatch, getState) => { - const { exam } = getState().examState; - const attemptId = exam.attempt.attempt_id; - if (!attemptId) { - logError('Failed to stop exam. No attempt id.'); + const { exam, activeAttempt } = getState().examState; + + if (!activeAttempt) { + logError('Failed to stop exam. No active attempt.'); handleAPIError( - { message: 'Failed to stop exam. No attempt id was found.' }, + { message: 'Failed to stop exam. No active attempt was found.' }, dispatch, ); return; } + + const { attempt_id: attemptId, exam_url_path: examUrl } = activeAttempt; await updateAttemptAfter( exam.course_id, exam.content_id, stopAttempt(attemptId), true, )(dispatch); + + if (attemptId !== exam.attempt.attempt_id) { + window.location.href = examUrl; + } }; } @@ -293,8 +299,7 @@ export function submitExam() { export function expireExam() { return async (dispatch, getState) => { const { exam, activeAttempt } = getState().examState; - const attemptId = exam.attempt.attempt_id; - const { desktop_application_js_url: workerUrl } = activeAttempt || {}; + const { desktop_application_js_url: workerUrl, attempt_id: attemptId } = activeAttempt || {}; const useWorker = window.Worker && activeAttempt && workerUrl; if (!attemptId) {