Fix calendar auto-advance and add fault injection for availability

- Remove client-side serviceEarliestDate; instead auto-advance month by
  month until the server returns events (capped at 12 months)
- Only mark initialized when a date is actually found, so empty months
  don't block auto-select on subsequent fetches
- Add per-service fault injection flags in ScheduleController::events
  to force zero availability for testing the no-slots UI path

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Philip Peterson 2026-06-03 19:52:14 -07:00
parent b000b824ed
commit 58988a4fe8
2 changed files with 19 additions and 4 deletions

View file

@ -45,6 +45,7 @@ function Booking({ settings }) {
const calRef = useRef(null);
const initializedRef = useRef(false);
const prevServiceRef = useRef(null);
const autoAdvanceRef = useRef(0);
const initDate = useMemo(nextBusinessDay, []);
function buildEventsUrl(svc) {
@ -93,12 +94,11 @@ function Booking({ settings }) {
eventsSet: function (events) {
markDays(events);
if (!initializedRef.current) {
initializedRef.current = true;
var dates = [...new Set(events.map(function (e) { return e.startStr.substring(0, 10); }))]
.filter(function (d) { return d >= initDate; })
.sort();
var dates = [...new Set(events.map(function (e) { return e.startStr.substring(0, 10); }))].sort();
var firstDate = dates[0];
if (firstDate) {
initializedRef.current = true;
autoAdvanceRef.current = 0;
var targetEl = calEl.current.querySelector(".fc-daygrid-day[data-date=\"" + firstDate + "\"]");
if (targetEl) {
targetEl.classList.add("is-selected");
@ -108,6 +108,9 @@ function Booking({ settings }) {
.sort(function (a, b) { return a.start - b.start; })
);
}
} else if (autoAdvanceRef.current < 12) {
autoAdvanceRef.current++;
cal.next();
}
}
},
@ -144,9 +147,11 @@ function Booking({ settings }) {
var isInitial = prevServiceRef.current === null;
prevServiceRef.current = service;
serviceRef.current = service;
if (!isInitial) {
initializedRef.current = false;
autoAdvanceRef.current = 0;
setSlots([]);
setSelectedSlotId(null);
setFormData(EMPTY_FORM);

View file

@ -101,6 +101,16 @@ class ScheduleController extends ControllerBase {
$end = $request->query->get('end');
$service = $request->query->get('service', 'diagnostic');
$faultZeroAvailability = [
'diagnostic' => false,
'sports' => false,
'surgical' => false,
'neuro' => false,
];
if ($faultZeroAvailability[$service] ?? false) {
return new JsonResponse([]);
}
// Each service gets different slot density and start hours so calendars
// look meaningfully distinct when switching types.
$serviceConfig = [