Skip to content

Commit 60c9ffa

Browse files
authored
Redirect user back to student list if address bar is invalid student id (#253)
1 parent 8118f2f commit 60c9ffa

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/pages/students/[student_id].tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,17 @@ const ViewStudentPage = () => {
4141

4242
const { data: student, isLoading } = trpc.student.getStudentById.useQuery(
4343
{ student_id: student_id as string },
44-
{ enabled: Boolean(student_id) }
44+
{
45+
enabled: Boolean(student_id),
46+
retry: false,
47+
onError: () => returnToStudentList(),
48+
}
4549
);
4650

51+
const returnToStudentList = async () => {
52+
await router.push(`/students`);
53+
};
54+
4755
const buttonSX = {
4856
"&:hover": {
4957
background: "#3023B8",
@@ -83,7 +91,7 @@ const ViewStudentPage = () => {
8391
return;
8492
}
8593
await archiveMutation.mutateAsync({ student_id: student.student_id });
86-
await router.push(`/students`);
94+
await returnToStudentList();
8795
};
8896

8997
const iepMutation = trpc.student.addIep.useMutation({
@@ -120,6 +128,8 @@ const ViewStudentPage = () => {
120128
return <div>Loading...</div>;
121129
}
122130

131+
if (!student) return;
132+
123133
return (
124134
<Stack
125135
spacing={2}

0 commit comments

Comments
 (0)