-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not show continue button on ready_to_submit pages if timer re…
…ached 0 (#22)
- Loading branch information
1 parent
7e74a25
commit 586a81d
Showing
8 changed files
with
96 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,49 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Container } from '@edx/paragon'; | ||
import React, { useContext, useEffect, useState } from 'react'; | ||
import { Button, Container } from '@edx/paragon'; | ||
import { FormattedMessage } from '@edx/frontend-platform/i18n'; | ||
import Emitter from '../data/emitter'; | ||
import { ExamType } from '../constants'; | ||
import { SubmitProctoredExamInstructions } from './proctored_exam'; | ||
import { SubmitTimedExamInstructions } from './timed_exam'; | ||
import Footer from './proctored_exam/Footer'; | ||
import ExamStateContext from '../context'; | ||
import { TIMER_REACHED_NULL } from '../timer/events'; | ||
|
||
const SubmitExamInstructions = ({ examType }) => ( | ||
<div> | ||
<Container className="border py-5 mb-4"> | ||
{examType === ExamType.TIMED | ||
? <SubmitTimedExamInstructions /> | ||
: <SubmitProctoredExamInstructions />} | ||
</Container> | ||
{examType !== ExamType.TIMED && <Footer />} | ||
</div> | ||
); | ||
const SubmitExamInstructions = () => { | ||
const state = useContext(ExamStateContext); | ||
const { exam, continueExam, activeAttempt } = state; | ||
const { time_remaining_seconds: timeRemaining } = activeAttempt; | ||
const { type: examType } = exam || {}; | ||
const [canContinue, setCanContinue] = useState(timeRemaining > 0); | ||
|
||
SubmitExamInstructions.propTypes = { | ||
examType: PropTypes.string.isRequired, | ||
const hideContinueButton = () => setCanContinue(false); | ||
|
||
useEffect(() => { | ||
Emitter.once(TIMER_REACHED_NULL, hideContinueButton); | ||
|
||
return () => { | ||
Emitter.off(TIMER_REACHED_NULL, hideContinueButton); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<div> | ||
<Container className="border py-5 mb-4"> | ||
{examType === ExamType.TIMED | ||
? <SubmitTimedExamInstructions /> | ||
: <SubmitProctoredExamInstructions />} | ||
{canContinue && ( | ||
<Button variant="outline-primary" onClick={continueExam} data-testid="continue-exam-button"> | ||
<FormattedMessage | ||
id="exam.SubmitExamInstructions.continueButton" | ||
defaultMessage="No, I'd like to continue working" | ||
/> | ||
</Button> | ||
)} | ||
</Container> | ||
{examType !== ExamType.TIMED && <Footer />} | ||
</div> | ||
); | ||
}; | ||
|
||
export default SubmitExamInstructions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const TIMER_IS_LOW = 'timer_is_low'; | ||
export const TIMER_IS_CRITICALLY_LOW = 'timer_is_critical'; | ||
export const TIMER_LIMIT_REACHED = 'timer_time_is_over'; | ||
export const TIMER_REACHED_NULL = 'timer_reached_null'; |