feat: enriched edit request system with side-by-side snapshots, calendar preloading, and admin review UI

Backend:
- Add enriched response types (EditSnapshot, EnrichedEditRequest) with original vs proposed snapshots
- Add 4 new GET endpoints for viewing edit requests (user and admin scoped)
- Remove github.com/lib/pq dependency — use native PostgreSQL array scanning
- Clean up edit requests, time blockers, and notifications on booking cancellation
- Validate exceptional closed hours on admin approve (409 Conflict)
- Notification upsert on edit request replace (no duplicate admin notifications)

Frontend:
- New user EditRequestModal with time/services/both modes and lunch protection
- New admin EditRequestModal with side-by-side diff (date/time, services, notes)
- Integrate edit requests into PendingApprovals card and notifications page
- Preload 3 months of availability to prevent calendar snap-back
- Apply lunch protection to isDateUnavailable in BookingFlow and BookingCreateModal
- Fix accessibility: card list items use <button> instead of <div>

Dev & Docs:
- Seed edit requests in local-dev-2.sh
- Update all Obsidian manuals with enriched edit request documentation
- 42 new tests (438/441 passing)
This commit is contained in:
2026-05-26 11:59:07 +01:00
parent 3ccc017716
commit 8574bf2221
19 changed files with 5270 additions and 599 deletions
@@ -197,6 +197,7 @@
// =============== Effects ===============
let wasOpen = false;
let bookingCreateInitialLoadDone = $state(false);
$effect(() => {
if (open && !wasOpen) {
@@ -215,16 +216,21 @@
}
});
// Preload 3 months when entering step 4 to prevent snap-back
$effect(() => {
if (open && currentStep === 4) {
const dateToCheck = selectedDate || placeholder;
fetchHoursForMonth(dateToCheck);
if (open && currentStep === 4 && !bookingCreateInitialLoadDone) {
fetchHoursRange(placeholder, 3);
bookingCreateInitialLoadDone = true;
}
});
// Fetch additional months when navigating beyond preloaded range
$effect(() => {
if (open && currentStep === 4 && placeholder) {
fetchHoursForMonth(placeholder);
if (open && currentStep === 4 && bookingCreateInitialLoadDone && placeholder) {
const monthKey = `${placeholder.year}-${String(placeholder.month).padStart(2, '0')}`;
if (!workingHoursCache.has(monthKey)) {
fetchHoursForMonth(placeholder);
}
}
});
@@ -246,6 +252,7 @@
availableHoursCache.clear();
workingHours = null;
availableHours = null;
bookingCreateInitialLoadDone = false;
// Clear reservation state
reservationId = null;
reservationExpiresAt = null;
@@ -304,6 +311,68 @@
}
}
async function fetchHoursRange(startDate: CalendarDate, months: number) {
// Calculate end month manually (CalendarDate is immutable)
let endYear = startDate.year;
let endMonth = startDate.month + months - 1;
while (endMonth > 12) {
endMonth -= 12;
endYear++;
}
const endMonthDate = new CalendarDate(endYear, endMonth, 1);
const daysInEndMonth = endMonthDate.calendar.getDaysInMonth(endMonthDate);
const startStr = startDate.toString();
const endStr = `${endYear}-${String(endMonth).padStart(2, '0')}-${String(daysInEndMonth).padStart(2, '0')}`;
loadingWorkingHours = true;
loadingAvailableHours = true;
try {
const [whRes, ahRes] = await Promise.all([
fetch(`/api/scheduling/working-hours?start=${startStr}&end=${endStr}`, {
headers: { Authorization: `Bearer ${authStore.currentToken}` }
}),
fetch(`/api/scheduling/available-hours?start=${startStr}&end=${endStr}`, {
headers: { Authorization: `Bearer ${authStore.currentToken}` }
})
]);
if (whRes.ok && ahRes.ok) {
const whData: WorkingHoursDay[] = await whRes.json();
const ahData: AvailableHoursDay[] = await ahRes.json();
const whMap: Record<string, any> = {};
const ahMap: Record<string, any> = {};
whData.forEach((d) => (whMap[d.date] = { isOpen: d.isOpen, startTime: d.startTime, endTime: d.endTime }));
ahData.forEach((d) => (ahMap[d.date] = { isOpen: d.isOpen, slots: d.slots }));
// Cache by month key
for (let i = 0; i < months; i++) {
let mYear = startDate.year;
let mMonth = startDate.month + i;
while (mMonth > 12) {
mMonth -= 12;
mYear++;
}
const key = `${mYear}-${String(mMonth).padStart(2, '0')}`;
workingHoursCache.set(key, whMap);
availableHoursCache.set(key, ahMap);
}
workingHours = whMap;
availableHours = ahMap;
}
} catch (err) {
console.error('Failed to fetch hours', err);
toast.error('Failed to load availability');
} finally {
loadingWorkingHours = false;
loadingAvailableHours = false;
}
}
async function fetchHoursForMonth(date: CalendarDate) {
const monthKey = `${date.year}-${String(date.month).padStart(2, '0')}`;
@@ -712,12 +781,32 @@
if (!workingHours) return true;
const dateStr = date.toString();
if (!workingHours[dateStr]?.isOpen) return true;
const dayHours = workingHours[dateStr];
if (!dayHours?.isOpen) return true;
if (selectedServices.length > 0) {
const duration = getTotalDuration();
const slots = generateAvailableTimeSlots(duration, date);
return slots.length === 0;
if (slots.length === 0) return true;
const dayAvailableHours = availableHours?.[dateStr];
if (dayAvailableHours?.slots) {
const existingBookings = extractBookedSlots(
dayHours.startTime,
dayHours.endTime,
dayAvailableHours.slots
);
const lunchProtection = getLunchProtectionForSlots(
dayHours.startTime,
dayHours.endTime,
existingBookings,
duration,
15,
true
);
const validSlots = slots.filter((t) => !lunchProtection.get(t)?.isBlocked);
if (validSlots.length === 0) return true;
}
}
return false;
@@ -1244,9 +1333,10 @@
selectedDate = newDate;
selectedTime = null;
}}
onPlaceholderChange={(newPlaceholder) => {
placeholder = newPlaceholder;
}}
onPlaceholderChange={(newPlaceholder) => {
placeholder = newPlaceholder;
fetchHoursForMonth(newPlaceholder);
}}
/>
</div>
{/if}