fix: login logout button in mange doctor
Overview
This MR fixes the Doctor Login/Logout UI state synchronization issue and updates UI terminology from "Assign Doctor" to "Select Specialization".
The fix ensures that doctor availability and button states are derived directly from backend data (login_time, logout_time) and persist correctly after page refresh.
What does this MR do and why?
Previously, the frontend relied on manual cache updates (queryClient.setQueryData) to update login/logout state. This caused inconsistencies and incorrect UI behavior after refresh because the backend API did not reflect updated state immediately.
With backend now providing login_time and logout_time in /doctors API, this MR removes frontend cache hacks and makes the UI fully backend-driven.
Additionally, the UI label "Assign Doctor" was misleading and has been updated to "Select Specialization" to better match functionality.
Changes Made
-
Removed manual cache updates (
setQueryData) fromattendanceMutation -
Updated
attendanceMutationto use only:invalidateQueries(['doctors', 'list'])
-
Implemented derived state:
const isLoggedIn = !!doctor.login_time && !doctor.logout_time; -
Updated button logic:
- Login →
disabled={isLoggedIn} - Logout →
disabled={!isLoggedIn}
- Login →
-
Updated status display:
- Available / Not Available based on
isLoggedIn
- Available / Not Available based on
-
Replaced all occurrences of:
- "Assign Doctor" → "Select Specialization"
Technical Details
Root Cause:
- UI depended on frontend cache instead of backend state
- Cache updates were lost on refresh
Fix:
- Backend is now the single source of truth
- Frontend derives state using
login_timeandlogout_time - Removed conflicting cache mutation logic
Type of Change
-
🐛 Bug fix -
🎨 UI/UX improvement -
♻ ️ Refactor
Related Issues / References
- Closes #
- Related to backend MR for
/doctorsAPI enhancement
Screenshots or Screen Recordings
| Before | After |
|---|---|
| Login/Logout incorrect after refresh | Correct state persists |
| "Assign Doctor" label | "Select Specialization" |
How to Set Up and Validate Locally
-
Pull this branch:
git checkout <branch-name> -
Install dependencies:
bun install -
Set environment:
VITE_SERVER_URL=http://localhost:8000 -
Run project:
bun dev -
Test flow:
- Open Doctor Directory
- Click Login → check button/state
- Click Logout → check button/state
- Refresh page → verify persistence
- Check UI text updates
Testing Done
-
Manual testing completed -
Unit tests updated
Test Cases Covered:
| Scenario | Expected Result | Status |
|---|---|---|
| Login click | Login disabled, Logout enabled | |
| Logout click | Login enabled, Logout disabled | |
| Page refresh | State persists correctly | |
| UI rename | "Select Specialization" shown |
Code Quality Checklist
Code Standards
-
Code follows project conventions -
No console logs -
No unused variables -
No duplicate logic -
i18n maintained -
No anytypes -
ESLint passed
React Best Practices
-
Single responsibility components -
Hooks used correctly -
State derived from backend -
No unnecessary re-renders
Component Patterns
-
shadcn/ui used correctly -
Tailwind used properly -
Responsive UI maintained -
Accessibility preserved
API & Data Fetching
-
TanStack Query used properly -
Loading states handled -
API-driven UI logic
Error Handling
-
Errors handled via toast -
API failures handled
Documentation
-
README updated (not required) -
CHANGELOG updated (optional)
Known Limitations / Technical Debt
- No real-time updates (requires polling or WebSocket)
- Depends on backend accuracy of
login_timeandlogout_time
Additional Notes
- Frontend is now fully stateless regarding login/logout
- Backend is the single source of truth
- This improves reliability and consistency across sessions
MR Acceptance Checklist
-
All acceptance criteria met -
UI works after refresh -
No console errors -
Code reviewed ##locally pipeline testing screenshort
closes #319 (closed)
