Updated the code to return to official-exam if they came from that page
This commit is contained in:
@@ -49,9 +49,10 @@ interface Props {
|
||||
isLoading: boolean;
|
||||
assignment?: Assignment;
|
||||
onViewResults: (moduleIndex?: number) => void;
|
||||
destination?: string
|
||||
}
|
||||
|
||||
export default function Finish({user, scores, modules, information, solutions, isLoading, assignment, onViewResults}: Props) {
|
||||
export default function Finish({ user, scores, modules, information, solutions, isLoading, assignment, onViewResults, destination }: Props) {
|
||||
const [selectedModule, setSelectedModule] = useState(modules[0]);
|
||||
const [selectedScore, setSelectedScore] = useState<Score>(scores.find((x) => x.module === modules[0])!);
|
||||
const [isExtraInformationOpen, setIsExtraInformationOpen] = useState(false);
|
||||
@@ -60,6 +61,8 @@ export default function Finish({user, scores, modules, information, solutions, i
|
||||
const exams = useExamStore((state) => state.exams);
|
||||
const { gradingSystem } = useGradingSystem();
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
useEffect(() => setSelectedScore(scores.find((x) => x.module === selectedModule)!), [scores, selectedModule]);
|
||||
|
||||
const moduleColors: { [key in Module]: { progress: string; inner: string } } = {
|
||||
@@ -286,10 +289,8 @@ export default function Finish({user, scores, modules, information, solutions, i
|
||||
<div className="flex gap-8">
|
||||
<div className="flex w-fit cursor-pointer flex-col items-center gap-1">
|
||||
<button
|
||||
onClick={() => window.location.reload()}
|
||||
// disabled={user.type === "admin"}
|
||||
// TODO: temporarily disabled
|
||||
disabled
|
||||
onClick={() => router.push(destination || "/exam")}
|
||||
disabled={!!assignment}
|
||||
className="bg-mti-purple-light hover:bg-mti-purple flex h-11 w-11 items-center justify-center rounded-full transition duration-300 ease-in-out">
|
||||
<BsArrowCounterclockwise className="h-7 w-7 text-white" />
|
||||
</button>
|
||||
@@ -325,7 +326,7 @@ export default function Finish({user, scores, modules, information, solutions, i
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Link href="/" className="w-full max-w-[200px] self-end">
|
||||
<Link href={destination || "/"} className="w-full max-w-[200px] self-end">
|
||||
<Button color="purple" className="w-full max-w-[200px] self-end">
|
||||
Dashboard
|
||||
</Button>
|
||||
|
||||
@@ -31,10 +31,11 @@ import { mapBy } from "@/utils";
|
||||
interface Props {
|
||||
page: "exams" | "exercises";
|
||||
user: User;
|
||||
destination?: string
|
||||
hideSidebar?: boolean
|
||||
}
|
||||
|
||||
export default function ExamPage({page, user, hideSidebar = false}: Props) {
|
||||
export default function ExamPage({ page, user, destination = "/exam", hideSidebar = false }: Props) {
|
||||
const [variant, setVariant] = useState<Variant>("full");
|
||||
const [avoidRepeated, setAvoidRepeated] = useState(false);
|
||||
const [hasBeenUploaded, setHasBeenUploaded] = useState(false);
|
||||
@@ -465,6 +466,7 @@ export default function ExamPage({page, user, hideSidebar = false}: Props) {
|
||||
timeSpent,
|
||||
inactivity: totalInactivity,
|
||||
}}
|
||||
destination={destination}
|
||||
onViewResults={(index?: number) => {
|
||||
if (exams[0].module === "level") {
|
||||
const levelExam = exams[0] as LevelExam;
|
||||
|
||||
@@ -23,33 +23,34 @@ import moment from "moment";
|
||||
|
||||
export const getServerSideProps = withIronSessionSsr(async ({ req, res, query }) => {
|
||||
const user = await requestUser(req, res)
|
||||
const destination = Buffer.from(req.url || "/").toString("base64")
|
||||
if (!user) return redirect(`/login?destination=${destination}`)
|
||||
const loginDestination = Buffer.from(req.url || "/").toString("base64")
|
||||
if (!user) return redirect(`/login?destination=${loginDestination}`)
|
||||
|
||||
if (shouldRedirectHome(user)) return redirect("/")
|
||||
|
||||
const {assignment: assignmentID} = query as {assignment?: string}
|
||||
const { assignment: assignmentID, destination } = query as { assignment?: string, destination?: string }
|
||||
const destinationURL = !!destination ? Buffer.from(destination, 'base64').toString() : undefined
|
||||
|
||||
if (assignmentID) {
|
||||
const assignment = await getAssignment(assignmentID)
|
||||
|
||||
if (!assignment) return redirect("/exam")
|
||||
if (!assignment) return redirect(destinationURL || "/exam")
|
||||
if (!assignment.assignees.includes(user.id) && !["admin", "developer"].includes(user.type))
|
||||
return redirect("/exam")
|
||||
return redirect(destinationURL || "/exam")
|
||||
|
||||
if (filterBy(assignment.results, 'user', user.id).length > 0)
|
||||
return redirect("/exam")
|
||||
return redirect(destinationURL || "/exam")
|
||||
|
||||
const exams = await getExamsByIds(uniqBy(assignment.exams, "id"))
|
||||
const session = await getSessionByAssignment(assignmentID)
|
||||
|
||||
return {
|
||||
props: serialize({user, assignment, exams, session: session ?? undefined})
|
||||
props: serialize({ user, assignment, exams, destinationURL, session: session ?? undefined })
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
props: serialize({user}),
|
||||
props: serialize({ user, destinationURL }),
|
||||
};
|
||||
}, sessionOptions);
|
||||
|
||||
@@ -58,9 +59,10 @@ interface Props {
|
||||
assignment?: Assignment
|
||||
exams?: Exam[]
|
||||
session?: Session
|
||||
destinationURL?: string
|
||||
}
|
||||
|
||||
export default function Page({user, assignment, exams = [], session}: Props) {
|
||||
export default function Page({ user, assignment, exams = [], destinationURL = "/exam", session }: Props) {
|
||||
const router = useRouter()
|
||||
|
||||
const state = useExamStore((state) => state)
|
||||
@@ -117,7 +119,7 @@ export default function Page({user, assignment, exams = [], session}: Props) {
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
</Head>
|
||||
<ExamPage page="exams" user={user} hideSidebar={!!assignment || !!state.assignment} />
|
||||
<ExamPage page="exams" destination={destinationURL} user={user} hideSidebar={!!assignment || !!state.assignment} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -69,6 +69,8 @@ export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
|
||||
return { props: serialize({ user, entities, assignments, exams, sessions }) };
|
||||
}, sessionOptions);
|
||||
|
||||
const destination = Buffer.from("/official-exam").toString("base64")
|
||||
|
||||
export default function OfficialExam({ user, entities, assignments, sessions, exams }: Props) {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
|
||||
@@ -93,7 +95,7 @@ export default function OfficialExam({ user, entities, assignments, sessions, ex
|
||||
state.setSelectedModules(mapBy(assignmentExams.sort(sortByModule), 'module'));
|
||||
state.setAssignment(assignment);
|
||||
|
||||
router.push(`/exam?assignment=${assignment.id}`);
|
||||
router.push(`/exam?assignment=${assignment.id}&destination=${destination}`);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -112,7 +114,7 @@ export default function OfficialExam({ user, entities, assignments, sessions, ex
|
||||
state.setShowSolutions(false);
|
||||
state.setQuestionIndex(session.questionIndex);
|
||||
|
||||
router.push(`/exam?assignment=${session.assignment?.id}`);
|
||||
router.push(`/exam?assignment=${session.assignment?.id}&destination=${destination}`);
|
||||
};
|
||||
|
||||
const logout = async () => {
|
||||
|
||||
Reference in New Issue
Block a user