Appointment data in AMS is managed entirely through three async thunks defined inDocumentation 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.
src/redux/thunk/appointmentThunk.js. Each thunk calls the corresponding function in src/services/appointmentApi.js, which wraps an Axios instance pointed at the REST backend. The appointmentSlice in src/redux/slices/appointmentSlice.js handles all lifecycle cases — pending, fulfilled, and rejected — updating state.list in place so the UI always reflects the latest server data.
Redux State Shape
| Field | Type | Description |
|---|---|---|
list | Appointment[] | All appointments loaded from the API |
loading | boolean | true during any in-flight async operation |
error | string | null | Last error message from a failed operation |
Thunks
fetchAppointments
Fetches all appointments from the backend and replaces the entire local list. This is the primary way to hydrate or refresh appointment data.
| Action type | appointments/fetchAppointments |
| Parameters | None |
| API call | GET /Appointments via fetchAppointmentsFromApi() |
| Returns (fulfilled) | Appointment[] — the full array from response.data |
| Returns (rejected) | rejectWithValue(error.response?.data | error.message) |
| Case | loading | list | error |
|---|---|---|---|
pending | true | — | null |
fulfilled | false | replaced with API payload | — |
rejected | false | — | error string |
Because
fetchAppointments replaces state.list on every call rather
than merging, it is safe to dispatch it repeatedly — the list will always
match what the server returns. Use useFocusEffect to trigger a refresh
whenever a screen comes back into focus after a booking or cancellation.addAppointment
Creates a new appointment on the server and appends the server response (with its assigned id) to the local list.
| Action type | appointments/addAppointment |
| API call | POST /Appointments via createAppointmentOnApi(newAppointment) |
| Returns (fulfilled) | The created Appointment object with a server-assigned id |
| Returns (rejected) | rejectWithValue(error.response?.data | error.message) |
The appointment payload to send to the server. The object typically
includes the fields below, though the exact schema is determined by the
backend.
ID of the doctor being booked.
Display name of the doctor (denormalized for quick rendering).
Appointment date in
YYYY-MM-DD format.Appointment time slot, e.g.
"10:00 AM".Name of the patient.
Initial status — typically
"Upcoming" when first created.| Case | loading | list | error |
|---|---|---|---|
pending | true | — | — |
fulfilled | false | new appointment pushed | — |
rejected | false | — | error string |
cancelAppointment
Marks an existing appointment as 'Cancelled' by sending a PUT request to the server with the updated status, then replacing the matching entry in state.list in-place.
| Action type | appointments/cancelAppointment |
| API call | PUT /Appointments/:id via updateAppointmentOnApi({ ...appointment, status: 'Cancelled' }) |
| Returns (fulfilled) | The updated Appointment object returned by the server |
| Returns (rejected) | rejectWithValue(error.response?.data | error.message) |
The full existing appointment object from
state.list. The thunk
spreads it and overrides status: 'Cancelled' before sending the PUT
request — all original fields (including id) are preserved.| Case | loading | list | error |
|---|---|---|---|
pending | true | — | — |
fulfilled | false | matched item updated in-place | — |
rejected | false | — | error string |
The
cancelAppointment.fulfilled reducer finds the appointment by id
(state.list.findIndex(item => item.id === action.payload.id)) and
replaces it with the server response. The appointment stays in the list
with status: 'Cancelled' rather than being removed, so the user can see
their full booking history.Keeping Data Fresh with useFocusEffect
Because React Navigation does not unmount screens when you navigate away, a
plain useEffect will only fire once. Use useFocusEffect to re-fetch
appointments every time the screen comes into focus — for example, after the
user books a new appointment and navigates back to the appointments list.