Phase 5
Phase 5 is complete. All 53 tasks are done, verified on a fresh database in a single clean run: **121 unit tests**, **55 integration tests**, and **15 E2E journeys** (6 Phase 4 + 9 new Phase 5) all passing, plus a clean `tsc`/`eslint`/`build`. Summary of this final stretch: - **Fixed a real bug**: `StaffService`'s break/time-off update/delete functions threw uncaught instead of failing gracefully on a permission mismatch — fixed with proper `PERMISSION_DENIED` handling, covered by new integration tests. - **Built the remaining Phase 5 UI**: Breaks editor, Time Off editor, Barber Profile, and Notification Preferences — all wired to real services, no placeholders. - **Extended seed data**: more customers, loyalty accounts/transactions/rewards, and appointments spanning every status today (anchored to real time so the "Current Appointment" priority logic is reliably exercised). - **Found and fixed a second real bug live in the browser**: the Break/Time-Off edit sheets showed stale default values instead of the item being edited (a classic `useState`-doesn't-reinitialize-on-prop-change bug) — fixed with a `key` prop to force remount. - **Wrote the full Phase 5 test suite**: unit tests for `selectCurrentAppointment` and all `StaffService` validators, integration tests for `LoyaltyService` and `StaffService` (including the permission-fix regression tests), and 9 new Playwright E2E journeys covering the brief's exact required list. - **Did the desktop-responsive pass**: a persistent sidebar nav replacing the bottom bar at `lg:`, a genuine calendar+"Right Now" side-by-side split, and 2-column layouts for the clients list and customer details — addressing the brief's explicit "more than simple centering" requirement. - **Wrote [docs/phase-5-summary.md](docs/phase-5-summary.md)** documenting everything above in full. Nothing is committed — the whole session (Phases 2–5) sits uncommitted on top of the initial template commit, same as you left it. Let me know if you'd like me to commit, or if you want to move on to Phase 6.
This commit is contained in:
81 files changed
+8024
-113
No files matched your search
@@ -27,7 +27,10 @@ export function canTransition(from: AppointmentStatus, to: AppointmentStatus): b
|
||||
return TRANSITIONS[from].includes(to);
|
||||
}
|
||||
|
||||
export function validateTransition(from: AppointmentStatus, to: AppointmentStatus): ValidationResult {
|
||||
export function validateTransition(
|
||||
from: AppointmentStatus,
|
||||
to: AppointmentStatus,
|
||||
): ValidationResult {
|
||||
if (!canTransition(from, to)) {
|
||||
return fail({
|
||||
code: "INVALID_STATUS_TRANSITION",
|
||||
@@ -85,11 +88,18 @@ export type TransitionResult =
|
||||
| { success: true; appointment: NonNullable<Awaited<ReturnType<typeof getAppointmentById>>> }
|
||||
| { success: false; validation: ValidationResult };
|
||||
|
||||
async function transitionStatus(prisma: PrismaClient, appointmentId: string, to: AppointmentStatus): Promise<TransitionResult> {
|
||||
async function transitionStatus(
|
||||
prisma: PrismaClient,
|
||||
appointmentId: string,
|
||||
to: AppointmentStatus,
|
||||
): Promise<TransitionResult> {
|
||||
return prisma.$transaction(async (tx) => {
|
||||
const appointment = await tx.appointment.findUnique({ where: { id: appointmentId } });
|
||||
if (!appointment) {
|
||||
return { success: false, validation: fail({ code: "APPOINTMENT_NOT_FOUND", message: "Appointment not found." }) };
|
||||
return {
|
||||
success: false,
|
||||
validation: fail({ code: "APPOINTMENT_NOT_FOUND", message: "Appointment not found." }),
|
||||
};
|
||||
}
|
||||
|
||||
const check = validateTransition(appointment.status, to);
|
||||
@@ -123,3 +133,43 @@ export function markNoShow(prisma: PrismaClient, appointmentId: string) {
|
||||
export function confirm(prisma: PrismaClient, appointmentId: string) {
|
||||
return transitionStatus(prisma, appointmentId, AppointmentStatus.CONFIRMED);
|
||||
}
|
||||
|
||||
const CURRENT_APPOINTMENT_ACTIVE_STATUSES: AppointmentStatus[] = [
|
||||
AppointmentStatus.PENDING,
|
||||
AppointmentStatus.CONFIRMED,
|
||||
AppointmentStatus.CHECKED_IN,
|
||||
AppointmentStatus.IN_PROGRESS,
|
||||
];
|
||||
|
||||
/**
|
||||
* Which of a staff member's appointments is "the current one" for the
|
||||
* Current Appointment screen — a pure function over already-fetched
|
||||
* appointments (the page fetches today's list via listAppointments; this
|
||||
* just picks the most relevant one), so it's cheap to unit test every edge
|
||||
* case without a database. Priority, per the Phase 5 brief:
|
||||
* 1. IN_PROGRESS
|
||||
* 2. CHECKED_IN
|
||||
* 3. Scheduled right now (startAt <= now < endAt) and not yet terminal
|
||||
* 4. The next upcoming one today
|
||||
* 5. null — the page shows its own empty state
|
||||
*/
|
||||
export function selectCurrentAppointment<
|
||||
T extends { status: AppointmentStatus; startAt: Date; endAt: Date },
|
||||
>(appointments: T[], now: Date): T | null {
|
||||
const inProgress = appointments.find((a) => a.status === AppointmentStatus.IN_PROGRESS);
|
||||
if (inProgress) return inProgress;
|
||||
|
||||
const checkedIn = appointments.find((a) => a.status === AppointmentStatus.CHECKED_IN);
|
||||
if (checkedIn) return checkedIn;
|
||||
|
||||
const scheduledNow = appointments.find(
|
||||
(a) =>
|
||||
CURRENT_APPOINTMENT_ACTIVE_STATUSES.includes(a.status) && a.startAt <= now && a.endAt > now,
|
||||
);
|
||||
if (scheduledNow) return scheduledNow;
|
||||
|
||||
const upcoming = appointments
|
||||
.filter((a) => CURRENT_APPOINTMENT_ACTIVE_STATUSES.includes(a.status) && a.startAt > now)
|
||||
.sort((a, b) => a.startAt.getTime() - b.startAt.getTime());
|
||||
return upcoming[0] ?? null;
|
||||
}
|
||||
Reference in new issue
Block a user