Skip to content

Commit

Permalink
Resolution to Issue #313: Error alert for invalid email entry (#320)
Browse files Browse the repository at this point in the history
* Added ability to access error message/ conditional for invalid email

* added try catch

* renaming variables, adding conditional
  • Loading branch information
katconnors authored May 12, 2024
1 parent fe6e1f1 commit 285b5c7
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/pages/students/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 285b5c7

Please sign in to comment.