Files
NextChair/src/features/booking/error-messages.ts
T
Stefan Lazic 9f981173f4
CI / ci (push) Canceled after 0s
holidays feature
The owner page

Where: Manage → Business → Holidays, at /owner/settings/holidays. It needs the same permission as Business Details.
Adding: you enter a name, a start date and an optional end date. Leaving the end empty gives a single day.
Upcoming and past: upcoming holidays are listed by date, with a trash icon to remove each one. Past ones sit in a collapsed “Past” list.
Existing bookings: if appointments are already booked on those dates, you see them and confirm with “Add Anyway”, the same pattern as Opening Hours. Nothing is cancelled automatically.

What it does to booking

Customer calendar: holiday dates are greyed out, for every staff member and every service.
Time slots: no slots are offered on those dates.
Direct bookings: staff and owner bookings and reschedules onto a holiday are refused, with a message naming the holiday. This is deliberate, but if you want owners to be able to override it, that’s a small change.
2026-10-17 12:23:53 +01:00

48 lines
2.8 KiB
TypeScript

import type { BookingValidationErrorCode, ValidationResult } from "@/services/scheduling/types";
/**
* Maps the typed error codes the Phase 3 services already return into
* customer-friendly copy. The only place raw codes get translated —
* every booking-flow page imports from here rather than inlining its own
* message strings, so the wording only needs to change in one place.
*/
const FRIENDLY_MESSAGES: Record<BookingValidationErrorCode, string> = {
INVALID_INPUT: "Something about that wasn't quite right. Please try again.",
NO_SERVICES_SELECTED: "Please select at least one service.",
SERVICES_SPAN_MULTIPLE_BUSINESSES: "One or more selected services aren't available here.",
STAFF_CANNOT_PERFORM_SERVICE: "This barber doesn't offer one of the selected services.",
BUSINESS_CLOSED: "The business is closed at this time — please choose another slot.",
BUSINESS_HOLIDAY: "The business is closed on that date — please choose another day.",
STAFF_NOT_WORKING: "This barber isn't working at that time — please choose another slot or barber.",
STAFF_ON_BREAK: "This barber is on a break at that time — please choose another slot.",
STAFF_ON_LEAVE: "This barber is away on that date — please choose another barber or date.",
SLOT_UNAVAILABLE: "That time was just booked by someone else — please choose another.",
INSUFFICIENT_DURATION:
"There isn't enough time left that day for the selected services — try an earlier time or fewer services.",
BELOW_MIN_NOTICE: "This time is too soon — please choose a later time.",
BEYOND_MAX_ADVANCE: "This date is too far ahead to book yet — please choose a nearer date.",
BUSINESS_DAILY_LIMIT_REACHED: "This business is fully booked that day — please choose another date.",
STAFF_DAILY_LIMIT_REACHED: "This barber is fully booked that day — please choose another barber or date.",
APPOINTMENT_NOT_FOUND: "We couldn't find that appointment.",
INVALID_STATUS_TRANSITION: "This appointment can no longer be changed.",
STAFF_NOT_FOUND: "We couldn't find that barber.",
CUSTOMER_NOT_FOUND: "We couldn't find your customer details.",
BUSINESS_NOT_FOUND: "We couldn't find this business.",
};
const FALLBACK_MESSAGE = "Something went wrong with this booking. Please try again.";
export function getFriendlyMessage(code: BookingValidationErrorCode): string {
return FRIENDLY_MESSAGES[code] ?? FALLBACK_MESSAGE;
}
export function getFriendlyValidationMessages(validation: ValidationResult): string[] {
if (validation.issues.length === 0) return [];
return validation.issues.map((issue) => getFriendlyMessage(issue.code));
}
export function getFirstFriendlyMessage(validation: ValidationResult): string {
const [first] = validation.issues;
return first ? getFriendlyMessage(first.code) : FALLBACK_MESSAGE;
}