The doctor feature in AMS uses a single async thunk —Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Jay-byte389/AMS/llms.txt
Use this file to discover all available pages before exploring further.
fetchDoctors — to load the full doctor catalogue from the REST API, combined with four synchronous slice actions that manage selection and favourites entirely in memory. All doctor state lives in src/redux/slices/doctorSlice.js, with the thunk defined in src/redux/thunk/doctorThunk.js and the API call handled by src/services/doctorServices.js.
Redux State Shape
| Field | Type | Description |
|---|---|---|
doctorsList | Doctor[] | Full list of doctors loaded from the API |
selectedDoctor | Doctor | null | The doctor currently being viewed or booked |
favouriteIds | string[] | Array of doctor IDs the user has favourited |
loading | boolean | true while a fetch is in progress |
error | string | null | Last error message from a failed fetch |
Async Thunk
fetchDoctors
Fetches the full list of doctors from the backend API and stores them in state.doctorsList. This thunk is typically dispatched once on the home or doctors-list screen mount.
| Action type | doctors/fetchDoctors |
| Parameters | None |
| API call | GET /Doctors via fetchDoctorsAPI() |
| Returns (fulfilled) | Doctor[] — the full array from response.data |
| Returns (rejected) | rejectWithValue(error.response?.data | error.message | 'Failed to fetch doctors') |
| Case | loading | doctorsList | error |
|---|---|---|---|
pending | true | — | null |
fulfilled | false | replaced with API payload | — |
rejected | false | — | error string |
Synchronous Actions
All four actions below are exported fromdoctorSlice.actions and can be imported directly from the slice:
setSelectedDoctor
Sets state.selectedDoctor to the provided doctor object. Dispatch this when the user taps a doctor card to navigate to the detail or booking screen.
The full doctor object to mark as selected. This is typically an item
directly from
state.doctorsList.clearSelectedDoctor
Sets state.selectedDoctor to null. Dispatch this when navigating away from a doctor detail screen to avoid stale data if the user returns later.
toggleFavourtie
The exported action name is
toggleFavourtie (note the transposed u and
r in Favourite) — this matches the source code spelling exactly. Use
this exact name when importing.state.favouriteIds if it is not already present, or removes it if it is. This provides a toggle-on-tap interaction directly from any list or detail screen.
The
id field of the doctor to toggle. The reducer checks
favouriteIds.includes(doctorId) to decide whether to add or remove.setFavourite
Replaces the entire state.favouriteIds array with the provided list. This is used on app launch to rehydrate persisted favourites from loadFavourites() in storage, ensuring the heart icons render correctly before the user interacts.
An array of doctor ID strings to set as the complete favourites list.
Passing an empty array
[] clears all favourites.Reading Doctors in a Component
- Full List
- Selected Doctor
- Favourites
- Filtered by Specialty