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