feat: integrated the auto generate book no in the frontend create new patient page
What does this MR do and why?
This MR updates the Volunteer → Patient Registration → New Patient flow to use the new backend endpoint for book number generation.
Changes included:
- Calls
GET /api/v1/users/new-book-nowhen opening the Create New Patient form. - Auto-fills the
book_nofield from backend response. - Makes
book_nonon-editable in the new-patient form. - Shows loading state while generating and a retry button if generation fails.
- Adds API helper
getNewBookNo()insrc/lib/api.ts. - Updates unit tests to mock
getNewBookNoand validate auto-filled behavior.
Why:
- Ensures book numbers are generated from a single backend source of truth.
- Prevents manual edits and accidental duplicate/invalid book numbers.
- Aligns frontend with the newly added backend route and expected registration workflow.
References
- Backend endpoint:
GET /api/v1/users/new-book-no - Frontend files:
src/lib/api.tssrc/pages/volunteer/PatientRegistrationPage.tsxtests/unit/components/PatientRegistrationPage.test.tsx
| Before | After |
|---|---|
New patient form had editable Book Number input. |
New patient form auto-generates Book Number and keeps it read-only (with loading/retry states). |
Please attach:
- Before: editable book number field
- After: auto-filled read-only field + retry state (if endpoint fails)
| Viewport size | Before | After |
|---|---|---|
xs (<576px) |
Attach | Attach |
sm (>=576px) |
Attach | Attach |
md (>=768px) |
Attach | Attach |
lg (>=992px) |
Attach | Attach |
xl (>=1200px) |
Attach | Attach |
How to set up and validate locally
-
Ensure backend is running with the new route
GET /api/v1/users/new-book-no. -
In frontend
.env, set:VITE_SERVER_URL=http://localhost:8000 VITE_SOCKET_URL=http://localhost:8000 -
Install dependencies and run frontend:
npm install npm run dev -
Login as a volunteer user.
-
Go to Volunteer Dashboard → Register Patient → Create New Patient.
-
Verify:
- Book number is fetched automatically.
- Book number input is not editable.
- If generation fails, retry option appears.
-
Run checks:
npm run lint npm run build npm run test:run
MR acceptance checklist
-
Quality: New patient registration uses backend-generated book number. -
Performance: Adds one lightweight GET call only when opening new-patient form. -
Reliability: Handles loading, success, and error/retry states for book number generation. -
Security: Uses existing authenticated apiClient+ interceptors; no new auth bypass. -
Maintainability: Added typed API helper and updated relevant unit tests. -
Regression checks: npm run test:runpasses (396/396).