Skip to content

Commit

Permalink
Redirect user back to student list if address bar is invalid student …
Browse files Browse the repository at this point in the history
…id (#253)
  • Loading branch information
hieungo89 authored Nov 16, 2023
1 parent 8118f2f commit 60c9ffa
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/pages/students/[student_id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,17 @@ const ViewStudentPage = () => {

const { data: student, isLoading } = trpc.student.getStudentById.useQuery(
{ student_id: student_id as string },
{ enabled: Boolean(student_id) }
{
enabled: Boolean(student_id),
retry: false,
onError: () => returnToStudentList(),
}
);

const returnToStudentList = async () => {
await router.push(`/students`);
};

const buttonSX = {
"&:hover": {
background: "#3023B8",
Expand Down Expand Up @@ -83,7 +91,7 @@ const ViewStudentPage = () => {
return;
}
await archiveMutation.mutateAsync({ student_id: student.student_id });
await router.push(`/students`);
await returnToStudentList();
};

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

if (!student) return;

return (
<Stack
spacing={2}
Expand Down

0 comments on commit 60c9ffa

Please sign in to comment.