From 60c9ffafe83aa8e0df6de5da736b61c4167eaf92 Mon Sep 17 00:00:00 2001 From: Hieu Ngo Date: Wed, 15 Nov 2023 19:38:54 -0800 Subject: [PATCH] Redirect user back to student list if address bar is invalid student id (#253) --- src/pages/students/[student_id].tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/pages/students/[student_id].tsx b/src/pages/students/[student_id].tsx index c9a9f20b..498c6273 100644 --- a/src/pages/students/[student_id].tsx +++ b/src/pages/students/[student_id].tsx @@ -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", @@ -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({ @@ -120,6 +128,8 @@ const ViewStudentPage = () => { return
Loading...
; } + if (!student) return; + return (