-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unique Resident IDs #200
Unique Resident IDs #200
Conversation
Visit the preview URL for this PR (updated for commit 63eaf16): https://blueprintsupportivehousing--pr200-kevin-unique-residen-dk93zcfe.web.app (expires Sun, 10 Dec 2023 17:47:08 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: f6bcdba7452bf82a6ec1a299c37d1bdff7870d09 |
fmt_resident_id = resident.get("initial") + str(resident.get("room_num")) | ||
try: | ||
res = residents_service.get_residents(False, 1, 10, fmt_resident_id) | ||
if len(res["residents"]) > 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When adding a new resident, we simply want to check for a result length greater than 0 (if there's even one other resident that has the same ID, then this is a duplicate resident => reject)
fmt_resident_id = updated_resident.get("initial") + str(updated_resident.get("room_num")) | ||
try: | ||
res = residents_service.get_residents(False, 1, 10, fmt_resident_id) | ||
if len(res["residents"]) == 1 and res["residents"][0]["id"] != resident_id: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When editing a resident, there are two cases for which the result of get_residents could be >=1
in size:
-
There was no change to the resident ID (i.e. a resident with ID AA123 has their building num changed ; ID remains AA123 and so when we get residents with the ID
fmt_resident_id = AA123
, then we get 1) -
We changed another resident to have a pre-existing resident ID (there are residents AA123 and AA321 ; resident AA123 has their room number changed to 321, resulting in two duplicate entries ; thus when we fetch the residents with the ID AA321, we end up with a result of 1)
We want case #2 to be marked as INVALID but case #1 to be VALID. As such, our checking logic must check for:
- If there's already a result being returned
- If the result has the same database ID as us (if it's the same, then we're editing the same record, meaning this change is valid ; if the database IDs are different, then this means that there is a different resident with the same formatted ID as us)
|
||
if (axiosErr.response && axiosErr.response.status === 409) { | ||
return { | ||
errMessage: "Resident with the specified user ID already exists." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, we're propagating the error message displayed in the toast through the API client
getRecords(1); | ||
countResidents(); | ||
setUserPageNum(1); | ||
setShowAlert(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We move the call to here since the showAlert state controls the visibility of a success
alert ; we only want the success state to be displayed if we get back a boolean result with value true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I tested creating and editing residents on the frontend and everything works as expected, and I didn't find any real problems related to the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
THE EXPLANATIONS ARE 💯 , one thing I think is worth changing is keeping the modal open (and not clearing whatever was entered) when a duplicate resident is entered
Also I'm thinking since we have a few more error types/messages now it might be worth having them in their own shared files:
- Can have a file
ErrorTypes.ts
(under/types
) which can hold theErrorResponse
here and the one defined inhttps://github.com/uwblueprint/supportive-housing/pull/202/files
- Under
helpers
we have a file callederrors.ts
which can hold everything inresidentError.ts
andauthError.ts
Just so it makes things more reusable if we ever need to use the functionality in the future.
… closes on duplicate resident
Notion task link
Unique Resident ID
Implementation description
Steps to test
Create Resident
Edit Resident
What should reviewers focus on?
Checklist