Skip to content

Commit 1c61ca8

Browse files
committed
Add publish module modal to ViewModulePage
1 parent c531735 commit 1c61ca8

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

frontend/src/components/pages/ViewModulePage.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import "./ViewModulePage.css";
9090
import { useCourseUnits } from "../../contexts/CourseUnitsContext";
9191
import EditPublishedModuleModal from "../course_viewing/modals/EditPublishedModuleModal";
9292
import { useSocket } from "../../contexts/SocketContext";
93+
import PublishModuleModal from "../course_viewing/modals/PublishModuleModal";
9394

9495
pdfjs.GlobalWorkerOptions.workerSrc = new URL(
9596
"pdfjs-dist/build/pdf.worker.min.mjs",
@@ -133,6 +134,7 @@ const ViewModulePage = () => {
133134
const numPages = module?.pages.length || 0;
134135
const [editPublishedModuleModalOpen, setEditPublishedModuleModalOpen] =
135136
useState(false);
137+
const [publishModuleModalOpen, setPublishModuleModalOpen] = useState(false);
136138

137139
const isFeedbackSurveyPage = role === "Learner" && currentPage === numPages;
138140
const isEmptyModuleEditing =
@@ -907,18 +909,7 @@ const ViewModulePage = () => {
907909
width: "100%",
908910
height: "40px",
909911
}}
910-
onClick={async () => {
911-
CourseAPIClient.publishModule(module.id)
912-
.then(() => {
913-
history.push(
914-
`${COURSE_PAGE}${unit ? `?selectedUnit=${unit.id}` : ""}`,
915-
);
916-
})
917-
.catch(() => {
918-
/* eslint-disable-next-line no-alert */
919-
alert("Failed to publish module. Please try again later.");
920-
});
921-
}}
912+
onClick={() => setPublishModuleModalOpen(true)}
922913
>
923914
<Typography variant="labelLarge">Publish Module</Typography>
924915
</Button>
@@ -944,7 +935,6 @@ const ViewModulePage = () => {
944935
handleDragLeave,
945936
handleDrop,
946937
unit,
947-
history,
948938
],
949939
);
950940

@@ -1653,6 +1643,18 @@ const ViewModulePage = () => {
16531643
editorName={currentEditorName}
16541644
unitId={requestedUnitId}
16551645
/>
1646+
{module && (
1647+
<PublishModuleModal
1648+
openPublishModuleModal={publishModuleModalOpen}
1649+
handleClosePublishModuleModal={() => setPublishModuleModalOpen(false)}
1650+
moduleId={module.id}
1651+
onUpdateModule={() =>
1652+
history.push(
1653+
`${COURSE_PAGE}${unit ? `?selectedUnit=${unit?.id}` : ""}`,
1654+
)
1655+
}
1656+
/>
1657+
)}
16561658
</>
16571659
);
16581660
};

0 commit comments

Comments
 (0)