Skip to content

Commit

Permalink
feat: Add missed decline attempt link for DownloadSoftwareProctoredEx…
Browse files Browse the repository at this point in the history
…amInstructions page (#25)
  • Loading branch information
UvgenGen authored Jun 16, 2021
1 parent 660b007 commit 75edad1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const ExamAction = Object.freeze({
ERROR: 'error',
RESET: 'reset_attempt',
CLICK_DOWNLOAD_SOFTWARE: 'click_download_software',
DECLINE: 'decline',
});

export const VerificationStatus = Object.freeze({
Expand Down
4 changes: 4 additions & 0 deletions src/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export async function softwareDownloadAttempt(attemptId) {
return updateAttemptStatus(attemptId, ExamAction.CLICK_DOWNLOAD_SOFTWARE);
}

export async function declineAttempt(attemptId) {
return updateAttemptStatus(attemptId, ExamAction.DECLINE);
}

export async function fetchExamReviewPolicy(examId) {
const url = new URL(
`${getConfig().LMS_BASE_URL}/api/edx_proctoring/v1/proctored_exam/review_policy/exam_id/${examId}/`,
Expand Down
14 changes: 11 additions & 3 deletions src/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
fetchVerificationStatus,
fetchExamReviewPolicy,
resetAttempt,
declineAttempt,
} from './api';
import { isEmpty } from '../helpers';
import {
Expand Down Expand Up @@ -167,9 +168,16 @@ export function skipProctoringExam() {
logError('Failed to skip proctored exam. No exam id.');
return;
}
await updateAttemptAfter(
exam.course_id, exam.content_id, createExamAttempt(exam.id, true, false),
)(dispatch);
const attemptId = exam.attempt.attempt_id;
if (attemptId) {
await updateAttemptAfter(
exam.course_id, exam.content_id, declineAttempt(attemptId),
)(dispatch);
} else {
await updateAttemptAfter(
exam.course_id, exam.content_id, createExamAttempt(exam.id, true, false),
)(dispatch);
}
};
}

Expand Down
5 changes: 2 additions & 3 deletions src/exam/Exam.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ const Exam = ({ isTimeLimited, children }) => {
const {
isLoading, activeAttempt, showTimer, stopExam, exam,
expireExam, pollAttempt, apiErrorMsg, pingAttempt,
getVerificationData, getAllowProctoringOptOut, getProctoringSettings,
getVerificationData, getProctoringSettings,
} = state;

const { type: examType, content_id: sequenceId, id: examId } = exam || {};
const { type: examType, id: examId } = exam || {};

useEffect(() => {
if (examId) {
getProctoringSettings();
}
if (examType === ExamType.PROCTORED) {
getVerificationData();
getAllowProctoringOptOut(sequenceId);
}

// this makes sure useEffect gets called only one time after the exam has been fetched
Expand Down
12 changes: 5 additions & 7 deletions src/instructions/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,8 @@ const Instructions = ({ children }) => {

const renderEmptyAttemptInstructions = () => {
let component = <EntranceExamInstructions examType={examType} skipProctoredExam={toggleSkipProctoredExam} />;
if (examType === ExamType.PROCTORED) {
if (skipProctoring) {
component = <SkipProctoredExamInstruction cancelSkipProctoredExam={toggleSkipProctoredExam} />;
} else if (!prerequisitesPassed) {
component = <PrerequisitesProctoredExamInstructions skipProctoredExam={toggleSkipProctoredExam} />;
}
if (examType === ExamType.PROCTORED && !prerequisitesPassed) {
component = <PrerequisitesProctoredExamInstructions skipProctoredExam={toggleSkipProctoredExam} />;
}
return component;
};
Expand All @@ -59,12 +55,14 @@ const Instructions = ({ children }) => {
}

switch (true) {
case examType === ExamType.PROCTORED && skipProctoring:
return <SkipProctoredExamInstruction cancelSkipProctoredExam={toggleSkipProctoredExam} />;
case isEmpty(attempt) || !attempt.attempt_id:
return renderEmptyAttemptInstructions();
case attempt.attempt_status === ExamStatus.CREATED:
return examType === ExamType.PROCTORED && verificationStatus !== VerificationStatus.APPROVED
? <VerificationProctoredExamInstructions status={verificationStatus} verificationUrl={verificationUrl} />
: <DownloadSoftwareProctoredExamInstructions />;
: <DownloadSoftwareProctoredExamInstructions skipProctoredExam={toggleSkipProctoredExam} />;
case attempt.attempt_status === ExamStatus.DOWNLOAD_SOFTWARE_CLICKED:
return <DownloadSoftwareProctoredExamInstructions />;
case attempt.attempt_status === ExamStatus.READY_TO_START:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useContext, useState } from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage, injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { Container } from '@edx/paragon';
import ExamStateContext from '../../../context';
Expand All @@ -10,13 +11,15 @@ import ProviderInstructions from './ProviderInstructions';
import DefaultInstructions from './DefaultInstructions';
import DownloadButtons from './DownloadButtons';
import Footer from '../Footer';
import SkipProctoredExamButton from '../SkipProctoredExamButton';

const DownloadSoftwareProctoredExamInstructions = ({ intl }) => {
const DownloadSoftwareProctoredExamInstructions = ({ intl, skipProctoredExam }) => {
const state = useContext(ExamStateContext);
const {
proctoringSettings,
exam,
getExamAttemptsData,
allowProctoringOptOut,
} = state;
const {
attempt,
Expand Down Expand Up @@ -120,13 +123,15 @@ const DownloadSoftwareProctoredExamInstructions = ({ intl }) => {
</p>
)}
</Container>
{allowProctoringOptOut && <SkipProctoredExamButton handleClick={skipProctoredExam} />}
<Footer />
</div>
);
};

DownloadSoftwareProctoredExamInstructions.propTypes = {
intl: intlShape.isRequired,
skipProctoredExam: PropTypes.func.isRequired,
};

export default injectIntl(DownloadSoftwareProctoredExamInstructions);

0 comments on commit 75edad1

Please sign in to comment.