Skip to content

Commit

Permalink
Added ended_at time to exam_enrollments and student button for studen…
Browse files Browse the repository at this point in the history
…ts to end exam
  • Loading branch information
Maija Y committed Jun 27, 2024
1 parent d8e19c0 commit ce2ae74
Show file tree
Hide file tree
Showing 17 changed files with 490 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import PageContext, { CoursePageDispatch, getDefaultPageState } from "../../../c
import useTime from "../../../hooks/useTime"
import pageStateReducer from "../../../reducers/pageStateReducer"

import { Block, enrollInExam, fetchExam } from "@/services/backend"
import { Block, endExamTime, enrollInExam, fetchExam } from "@/services/backend"
import Button from "@/shared-module/common/components/Button"
import BreakFromCentered from "@/shared-module/common/components/Centering/BreakFromCentered"
import ErrorBanner from "@/shared-module/common/components/ErrorBanner"
import Spinner from "@/shared-module/common/components/Spinner"
import HideTextInSystemTests from "@/shared-module/common/components/system-tests/HideTextInSystemTests"
import { withSignedIn } from "@/shared-module/common/contexts/LoginStateContext"
import useToastMutation from "@/shared-module/common/hooks/useToastMutation"
import { baseTheme, headingFont } from "@/shared-module/common/styles"
import { respondToOrLarger } from "@/shared-module/common/styles/respond"
import dontRenderUntilQueryParametersReady, {
Expand Down Expand Up @@ -88,6 +90,20 @@ const Exam: React.FC<React.PropsWithChildren<ExamProps>> = ({ query }) => {
await handleRefresh()
}, [handleRefresh])

const handleEndExam = () => {
endExamMutation.mutate({ id: examId })
}

const endExamMutation = useToastMutation(
({ id }: { id: string }) => endExamTime(id),
{ notify: true, method: "POST" },
{
onSuccess: () => {
handleRefresh()
},
},
)

if (exam.isPending) {
return <Spinner variant="medium" />
}
Expand Down Expand Up @@ -316,6 +332,18 @@ const Exam: React.FC<React.PropsWithChildren<ExamProps>> = ({ query }) => {
</div>
)}
<Page onRefresh={handleRefresh} organizationSlug={query.organizationSlug} />
<Button
variant={"primary"}
size={"small"}
onClick={() => {
const confirmation = confirm(t("message-do-you-want-to-end-the-exam"))
if (confirmation) {
handleEndExam()
}
}}
>
{t("button-end-exam")}
</Button>
</PageContext.Provider>
</CoursePageDispatch.Provider>
)
Expand Down
5 changes: 5 additions & 0 deletions services/course-material/src/services/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,3 +653,8 @@ export const fetchExerciseSubmissions = async (
)
return validateResponse(response, isExerciseSlideSubmissionAndUserExerciseStateList)
}

export const endExamTime = async (examId: string): Promise<void> => {
const response = await courseMaterialClient.post(`/exams/${examId}/end-exam-time`)
return response.data
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE exam_enrollments DROP COLUMN ended_at;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE exam_enrollments
ADD COLUMN ended_at TIMESTAMP WITH TIME ZONE;
COMMENT ON COLUMN exam_enrollments.ended_at IS 'Timestamp when the exam has ended. If null, the exam time has not ended.';

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ce2ae74

Please sign in to comment.