Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | 30x 30x 30x 30x 30x 30x 30x 30x 10x 2x 2x 1x 2x 2x 30x 1x | import React, { useEffect, useState } from "react";
import { useBackend } from "main/utils/useBackend";
import BasicLayout from "main/layouts/BasicLayout/BasicLayout";
import { useCurrentUser } from "main/utils/currentUser";
import { useNavigate, useParams } from "react-router";
import Modal from "react-bootstrap/Modal";
import { Button, Tab, Tabs, OverlayTrigger, Tooltip } from "react-bootstrap";
import EnrollmentTabComponent from "main/components/Courses/TabComponent/EnrollmentTabComponent";
import StaffTabComponent from "main/components/Courses/TabComponent/StaffTabComponent";
import SettingsTabComponent from "main/components/Courses/TabComponent/SettingsTabComponent";
import JobTabComponent from "main/components/Courses/TabComponent/JobTabComponent";
import { hasRole } from "main/utils/currentUser";
import DownloadsTabComponent from "main/components/Courses/TabComponent/DownloadsTabComponent";
import LinkToScaffold from "main/components/Scaffold/LinkToScaffold";
import ScaffoldTabComponent from "main/components/Courses/TabComponent/ScaffoldTabComponent";
import ConceptTabComponent from "main/components/Courses/TabComponent/ConceptTabComponent";
import SubConceptTabComponent from "main/components/Courses/TabComponent/SubConceptTabComponent";
import EdgeConceptTabComponent from "main/components/Courses/TabComponent/EdgeConceptTabComponent";
import PLTabComponent from "main/components/Courses/TabComponent/PLTabComponent";
export default function InstructorCourseShowPage({
testId = "InstructorCourseShowPage",
showSettingsTab = true,
staffTabIsInstructor = true,
canEditStudents = undefined,
canManageTeams = undefined,
}) {
const currentUser = useCurrentUser();
const courseId = useParams().id;
const [showErrorModal, setShowErrorModal] = useState(false);
const {
data: course,
error: _errorCourse,
status: _statusCourse,
failureCount: courseBackendFailureCount,
} = useBackend(
[`/api/courses/${courseId}`],
// Stryker disable next-line StringLiteral : GET and empty string are equivalent
{ method: "GET", url: `/api/courses/${courseId}` },
null,
true,
);
// Stryker disable OptionalChaining -- course?.instructorEmail is more readable than course && course.instructorEmail
const getCourseFailed = courseBackendFailureCount > 0;
const canEditCourseOptions =
hasRole(currentUser, "ROLE_ADMIN") ||
currentUser?.root?.user?.email === course?.instructorEmail;
// Stryker enable OptionalChaining
const navigate = useNavigate();
useEffect(() => {
if (getCourseFailed) {
setShowErrorModal(true);
const timer = setTimeout(() => {
navigate("/", { replace: true });
}, 3000);
// Stryker disable next-line BlockStatement
return () => {
clearTimeout(timer);
};
}
}, [getCourseFailed, navigate]);
return (
<BasicLayout>
<Modal show={showErrorModal}>
<Modal.Header>
<Modal.Title>Course Not Found</Modal.Title>
</Modal.Header>
<Modal.Body>
Course not found. You will be returned to the course list in 3
seconds.
</Modal.Body>
<Modal.Footer>
<Button onClick={() => setShowErrorModal(false)} variant={"primary"}>
Close
</Button>
</Modal.Footer>
</Modal>
{!course ? (
<div data-testid={`${testId}-loading`}>Course: Loading...</div>
) : (
<div className="border rounded-3 p-4 mb-4 tabsGroup">
<div className="border rounded-3 p-4 mb-4">
<div className="d-flex align-items-center gap-3">
{course.orgName && (
<img
src={`https://github.com/${course.orgName}.png?size=64`}
alt={course.orgName}
data-testid={`${testId}-github-org-image`}
className="rounded-circle border"
style={{ width: 48, height: 48 }}
/>
)}
<div>
<div className="d-flex align-items-center gap-2">
<h1
data-testid={`${testId}-title`}
className="h3 mb-0 fw-semibold"
>
<LinkToScaffold
course={course}
testId={`${testId}-title-linkToScaffold`}
/>
</h1>
<span className="badge bg-primary-subtle text-primary-emphasis rounded-pill">
{course.term}
</span>
</div>
</div>
</div>
</div>
<Tabs defaultActiveKey={"students"}>
<Tab eventKey={"students"} title={"Students"} className="pt-2">
<EnrollmentTabComponent
courseId={courseId}
testIdPrefix={testId}
currentUser={currentUser}
canEditStudents={canEditStudents}
/>
</Tab>
<Tab eventKey={"staff"} title={"Staff"} className="pt-2">
<StaffTabComponent
courseId={courseId}
testIdPrefix={testId}
currentUser={currentUser}
isInstructor={staffTabIsInstructor}
/>
</Tab>
<Tab eventKey={"scaffold"} title={"Scaffold"} className="pt-2">
<ScaffoldTabComponent
courseId={courseId}
courseName={course.courseName}
term={course.term}
school={course.school}
testIdPrefix={testId}
/>
</Tab>
<Tab eventKey={"concepts"} title={"Concepts"} className="pt-2">
<ConceptTabComponent courseId={courseId} testIdPrefix={testId} />
</Tab>
<Tab
eventKey={"subconcepts"}
title={"SubConcepts"}
className="pt-2"
>
<SubConceptTabComponent
courseId={courseId}
testIdPrefix={testId}
/>
</Tab>
<Tab eventKey={"edges"} title={"Edges"} className="pt-2">
<EdgeConceptTabComponent
courseId={courseId}
testIdPrefix={testId}
/>
</Tab>
<Tab
eventKey={"prairielearn"}
title={"PrairieLearn"}
className="pt-2"
>
<PLTabComponent courseId={courseId} testIdPrefix={testId} />
</Tab>
<Tab eventKey={"jobs"} title={"Jobs"} className="pt-2">
<JobTabComponent courseId={courseId} testIdPrefix={testId} />
</Tab>
</Tabs>
</div>
)}
</BasicLayout>
);
}
|