fix: add logic for when the doc id does not exist and fix form per ticket id 674#1152
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis PR updates form submission wiring in EditResidentDialog to use react-hook-form's form-level handler, refactors confirmation flows in Deactivate/Delete/Transfer dialogs to derive confirmToken/confirmLabel from doc_id or username, and applies type/formatting refinements to BulkSessionFieldModal. ChangesResident Dialog Form and Confirmation Refinements
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
frontend/src/components/residents/ResidentDialogs.tsx (1)
406-414:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winInput placeholder still hardcodes "Resident ID" after the label was made conditional.
The prompt now uses
{confirmLabel}(which becomes "username" whendoc_idis absent), but the placeholder on Line 412 remains"Type Resident ID to confirm", which is misleading in the username-fallback case. Derive it fromconfirmLabelinstead.🩹 Proposed fix
<Input id="deactivate-confirm" {...confirm.inputProps} - placeholder="Type Resident ID to confirm" + placeholder={`Type ${confirmLabel} to confirm`} className="mt-2" />🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@frontend/src/components/residents/ResidentDialogs.tsx` around lines 406 - 414, The placeholder text is hardcoded to "Type Resident ID to confirm" while the label is dynamic via confirmLabel; update the Input with id "deactivate-confirm" (the one using confirm.inputProps) to derive its placeholder from confirmLabel (e.g., `Type ${confirmLabel} to confirm`, with appropriate capitalization) so the prompt matches the displayed {confirmLabel} and works when confirmLabel becomes "username".
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@frontend/src/components/residents/ResidentDialogs.tsx`:
- Around line 321-324: Extract the repeated confirm-token logic into a single
helper hook (e.g., function useConfirmToken(resident: User, open: boolean)) that
computes hasDocId, confirmToken (resident.doc_id || resident.username),
confirmLabel ('Resident ID' or 'username') and calls useTypeToConfirm({ open,
expected: confirmToken }) returning { confirmToken, confirmLabel, confirm };
then replace the four-line blocks inside DeactivateDialog, DeleteDialog, and
TransferDialog with a call to this hook and use the returned
confirmToken/confirmLabel/confirm variables instead of duplicating the logic.
- Around line 93-98: Remove the redundant e.preventDefault() call in the submit
handler inside ResidentDialogs.tsx: replace the current onSubmit that manually
calls e.preventDefault() and then form.handleSubmit(...) with a direct call to
form.handleSubmit(handleSave) (or equivalent wrapping used elsewhere) so that
react-hook-form handles the event prevention; ensure you still pass the same
handleSave callback used in the existing handler (reference form.handleSubmit
and handleSave to locate the code).
---
Outside diff comments:
In `@frontend/src/components/residents/ResidentDialogs.tsx`:
- Around line 406-414: The placeholder text is hardcoded to "Type Resident ID to
confirm" while the label is dynamic via confirmLabel; update the Input with id
"deactivate-confirm" (the one using confirm.inputProps) to derive its
placeholder from confirmLabel (e.g., `Type ${confirmLabel} to confirm`, with
appropriate capitalization) so the prompt matches the displayed {confirmLabel}
and works when confirmLabel becomes "username".
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: d241a4a1-f7d3-4dd7-b1e7-82dc73d84757
📒 Files selected for processing (2)
frontend/src/components/residents/ResidentDialogs.tsxfrontend/src/pages/class-detail/BulkSessionFieldModal.tsx
corypride
left a comment
There was a problem hiding this comment.
🐛 Bugs Caused by PR #1152
No PR-caused bugs identified during pre-test analysis. Code rabbit had a good suggestion that should be made, and this PR is good to go
🐛 Discovered Bugs — Unrelated to PR #1152
Bug: resident-verify returns 404 when resident has no doc_id
- Severity: Medium
- Blocker: No — this is a pre-existing bug unrelated to PR #1152. The PR can be merged as-is.
- Description:
GET /api/users/resident-verify?user_id=X&facility_id=Y&doc_id=returns 404 becauseGetUserByDocIDAndIDfails on an emptydoc_id. Surfaced when opening the Transfer dialog for a resident without a doc_id and selecting a destination facility. - Repro: Transfer dialog for any resident with
doc_id = NULL→ select destination facility → 404 in browser console. - Location:
backend/src/database/users.go—GetUserByDocIDAndIDalways queriesWHERE LOWER(doc_id) = ''even when doc_id is empty, which never matches a NULL column. - Recommendation: When
doc_idis an empty string, fall back to looking up byuser_idalone. The endpoint's purpose is to verify the resident exists and check program transfer conflicts —doc_idis just a lookup key, not a security boundary.// backend/src/database/users.go func (db *DB) GetUserByDocIDAndID(ctx context.Context, docID string, userID int) (*models.User, error) { user := models.User{} query := db.WithContext(ctx) if docID != "" { query = query.Where("LOWER(doc_id) = ? AND id = ?", strings.ToLower(docID), userID) } else { query = query.Where("id = ?", userID) } if err := query.First(&user).Error; err != nil { return nil, newNotFoundDBError(err, "users") } return &user, nil }
🗓️ Testing completed on:
- Date: 2026-06-04
📊 Overall Results
GTG!
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
frontend/src/components/residents/ResidentDialogs.tsx (1)
419-420:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winMake confirm input placeholders dynamic to match token fallback.
These placeholders still hardcode “Resident ID”, but the required token can now be
username. UseconfirmLabel/confirmTokenin the placeholder text so the instruction is consistent in fallback cases.💡 Suggested patch
- placeholder="Type Resident ID to confirm" + placeholder={`Type ${confirmLabel} to confirm`}- placeholder="Type Resident ID to confirm" + placeholder={`Type ${confirmLabel} to confirm`}- placeholder="Enter Resident ID" + placeholder={`Enter ${confirmLabel}`}Also applies to: 507-508, 722-723
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@frontend/src/components/residents/ResidentDialogs.tsx` around lines 419 - 420, Update the hardcoded placeholder "Type Resident ID to confirm" to use the dynamic confirmLabel/confirmToken values so the instruction matches the current token fallback; find the placeholder usages in ResidentDialogs.tsx (around the locations where the input element with className "mt-2" appears) and replace the static text with a placeholder that references confirmLabel (or confirmToken if that is the intended token name) so it reads dynamically (e.g., "Type {confirmLabel} to confirm") in all occurrences (also update the other two instances at the same pattern near the noted locations).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@frontend/src/components/residents/ResidentDialogs.tsx`:
- Around line 419-420: Update the hardcoded placeholder "Type Resident ID to
confirm" to use the dynamic confirmLabel/confirmToken values so the instruction
matches the current token fallback; find the placeholder usages in
ResidentDialogs.tsx (around the locations where the input element with className
"mt-2" appears) and replace the static text with a placeholder that references
confirmLabel (or confirmToken if that is the intended token name) so it reads
dynamically (e.g., "Type {confirmLabel} to confirm") in all occurrences (also
update the other two instances at the same pattern near the noted locations).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 2d616910-da00-4ede-9ddf-c1d981ac2285
📒 Files selected for processing (1)
frontend/src/components/residents/ResidentDialogs.tsx
Pre-Submission PR Checklist
Description of the change
Added custom conditional logic for when DOC ID does not exist the user name is used instead. Also fixed form to use onSubmit rather than button