Skip to content

Commit

Permalink
Update LessonFinishedDialog.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
dtiwarATS committed Apr 17, 2024
1 parent a21227a commit f1b700f
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Fragment, useCallback, useEffect, useState } from 'react';
import { useSelector } from 'react-redux';
import { ActionFailure, ActionResult, finalizePageAttempt } from 'data/persistence/page_lifecycle';
import {
selectIsGraded,
selectPageSlug,
selectPreviewMode,
selectResourceAttemptGuid,
Expand All @@ -23,6 +24,7 @@ const LessonFinishedDialog: React.FC<LessonFinishedDialogProps> = ({
const [redirectURL, setRedirectURL] = useState('');
const [finalizeError, setFinalizeError] = useState<string | null>(null);
const isPreviewMode = useSelector(selectPreviewMode);
const graded = useSelector(selectIsGraded);
const revisionSlug = useSelector(selectPageSlug);
const sectionSlug = useSelector(selectSectionSlug);
const resourceAttemptGuid = useSelector(selectResourceAttemptGuid);
Expand All @@ -37,7 +39,7 @@ const LessonFinishedDialog: React.FC<LessonFinishedDialogProps> = ({
return;
}
setIsOpen(false);
if (isPreviewMode) {
if (!graded || isPreviewMode) {
window.location.reload();
} else {
window.location.href = redirectURL;
Expand All @@ -46,7 +48,7 @@ const LessonFinishedDialog: React.FC<LessonFinishedDialogProps> = ({

const handleFinalization = useCallback(async () => {
setFinalizationCalled(true);
if (!isPreviewMode) {
if (!isPreviewMode && graded) {
// only graded pages are finalized
try {
const finalizeResult = await finalizePageAttempt(
Expand Down Expand Up @@ -84,7 +86,7 @@ const LessonFinishedDialog: React.FC<LessonFinishedDialogProps> = ({
}
}
setIsFinalized(true);
}, [sectionSlug, revisionSlug, resourceAttemptGuid, isPreviewMode]);
}, [sectionSlug, revisionSlug, resourceAttemptGuid, graded, isPreviewMode]);

useEffect(() => {
// TODO: maybe we should call finalization elsewhere than in this modal
Expand Down

0 comments on commit f1b700f

Please sign in to comment.