From 285b5c76935af71e7c7d378639fd7c6e9fce3d80 Mon Sep 17 00:00:00 2001 From: Katrina Connors <32425204+katconnors@users.noreply.github.com> Date: Sat, 11 May 2024 22:46:01 -0700 Subject: [PATCH] Resolution to Issue #313: Error alert for invalid email entry (#320) * Added ability to access error message/ conditional for invalid email * added try catch * renaming variables, adding conditional --- src/pages/students/index.tsx | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/pages/students/index.tsx b/src/pages/students/index.tsx index ea698917..9fc12107 100644 --- a/src/pages/students/index.tsx +++ b/src/pages/students/index.tsx @@ -13,10 +13,30 @@ const Students = () => { const createStudent = trpc.case_manager.addStudent.useMutation({ onSuccess: () => utils.case_manager.getMyStudentsAndIepInfo.invalidate(), // TODO(tessa): In a future PR, we could change this to notification instead of browser alert - onError: () => - alert( - `This student is already assigned to a case manager. Please check your roster if the student is already there. Otherwise, this student is with another case manager.` - ), + onError: (err) => { + // err allows one to access validation, code, message, and path + // JSON.parse is utilized because err.message is a string + try { + const formattedErr = JSON.parse(err.message) as { + validation: string; + code: string; + message: string; + path: string[]; + }[]; + + if (formattedErr[0].message == "Invalid email") { + alert("The provided email is in the incorrect format- please edit."); + } + // can later insert other error messages here, as needed + else { + alert("An error has occurred."); + } + } catch { + alert( + `This student is already assigned to a case manager. Please check your roster if the student is already there. Otherwise, this student is with another case manager.` + ); + } + }, }); // create editStudent