Skip to content

Commit 31f529b

Browse files
authored
Merge pull request #15 from clawnify/client-visit-history
Show services and notes in client visit history
2 parents 2dcac6c + 75231b9 commit 31f529b

6 files changed

Lines changed: 76 additions & 10 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ OpenSalon is **vertical-agnostic** — configure services, pricing, and staff fo
3939
- **Appointment booking** — create bookings with client, staff, date/time, and multiple services; auto-calculates duration and total price
4040
- **Rescheduling** — move an existing booking to a new date or time from its details, keeping its duration, services and history; staff conflicts require an explicit override
4141
- **Blocked time slots** — mark breaks, lunch hours, or days off per staff member directly on the calendar
42-
- **Client management** — full database with contact info, notes, preferences, and appointment history
42+
- **Client management** — full database with contact info, notes, preferences, and appointment history with services and latest visit notes at a glance
4343
- **Staff management** — team directory with color coding, titles/roles, activate/deactivate, and appointment counts
4444
- **Service catalog** — configurable services with duration, price, color, and category grouping
4545
- **Product inventory** — track retail products with cost/price, stock levels, low stock alerts, brand, and SKU

‎src/client/components/client-detail.tsx‎

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,54 @@ export function ClientDetail() {
8080
<CardTitle>Appointment History</CardTitle>
8181
</CardHeader>
8282
<CardContent className="p-0">
83-
<Table>
83+
<div className="divide-y lg:hidden">
84+
{appointments.length === 0 && <p className="py-8 text-center text-sm text-muted-foreground">No appointments yet</p>}
85+
{appointments.map((apt) => (
86+
<button
87+
key={apt.id}
88+
type="button"
89+
className="w-full p-4 text-left transition-colors hover:bg-muted/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
90+
onClick={() => navigate(`/appointments/${apt.id}`)}
91+
>
92+
<div className="flex items-start justify-between gap-3">
93+
<div className="min-w-0">
94+
<p className="text-xs text-muted-foreground">{apt.scheduled_date} at {apt.start_time}</p>
95+
<p className="font-medium">{apt.service_names || "—"}</p>
96+
{apt.latest_note && <p className="mt-1 line-clamp-2 text-xs text-muted-foreground">{apt.latest_note}</p>}
97+
</div>
98+
<StatusBadge status={apt.status} />
99+
</div>
100+
<div className="mt-3 flex items-center justify-between text-sm">
101+
<span className="flex items-center gap-1.5">
102+
{apt.staff_name && <span className="inline-block h-2 w-2 rounded-full" style={{ backgroundColor: apt.staff_color || "#7c3aed" }} />}
103+
<span>{apt.staff_name || "—"}</span>
104+
</span>
105+
<span className="font-medium">${apt.total_price.toFixed(2)}</span>
106+
</div>
107+
</button>
108+
))}
109+
</div>
110+
<div className="hidden lg:block">
111+
<Table>
84112
<TableHeader>
85113
<TableRow>
86-
<TableHead className="w-24">Date</TableHead>
87-
<TableHead className="w-16">Time</TableHead>
114+
<TableHead>Visit</TableHead>
88115
<TableHead>Staff</TableHead>
89116
<TableHead className="w-24">Status</TableHead>
90117
<TableHead className="w-20 text-right">Price</TableHead>
91118
</TableRow>
92119
</TableHeader>
93120
<TableBody>
94121
{appointments.length === 0 && (
95-
<TableRow><TableCell colSpan={5} className="py-8 text-center text-muted-foreground">No appointments yet</TableCell></TableRow>
122+
<TableRow><TableCell colSpan={4} className="py-8 text-center text-muted-foreground">No appointments yet</TableCell></TableRow>
96123
)}
97124
{appointments.map((apt) => (
98125
<TableRow key={apt.id} className="cursor-pointer" onClick={() => navigate(`/appointments/${apt.id}`)}>
99-
<TableCell className="text-xs">{apt.scheduled_date}</TableCell>
100-
<TableCell className="text-xs">{apt.start_time}</TableCell>
126+
<TableCell className="min-w-52">
127+
<p className="text-xs text-muted-foreground">{apt.scheduled_date} at {apt.start_time}</p>
128+
<p className="font-medium">{apt.service_names || "—"}</p>
129+
{apt.latest_note && <p className="mt-1 line-clamp-2 max-w-md text-xs text-muted-foreground">{apt.latest_note}</p>}
130+
</TableCell>
101131
<TableCell>
102132
<span className="flex items-center gap-1.5">
103133
{apt.staff_name && <span className="inline-block h-2 w-2 rounded-full" style={{ backgroundColor: apt.staff_color || "#7c3aed" }} />}
@@ -109,7 +139,8 @@ export function ClientDetail() {
109139
</TableRow>
110140
))}
111141
</TableBody>
112-
</Table>
142+
</Table>
143+
</div>
113144
</CardContent>
114145
</Card>
115146
</div>

‎src/client/styles.css‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
--accent: oklch(0.965 0 0);
5858
--accent-foreground: oklch(0.205 0 0);
5959
--destructive: oklch(0.577 0.245 27.325);
60-
--destructive-foreground: oklch(0.577 0.245 27.325);
60+
--destructive-foreground: oklch(0.985 0 0);
6161
--border: oklch(0.922 0 0);
6262
--input: oklch(0.922 0 0);
6363
--ring: oklch(0.45 0.18 277);

‎src/client/types.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export interface Appointment {
1919
client_phone?: string;
2020
staff_name?: string | null;
2121
staff_color?: string | null;
22+
service_names?: string | null;
23+
latest_note?: string | null;
2224
appointment_services?: AppointmentService[];
2325
appointment_notes?: AppointmentNote[];
2426
created_at: string;

‎src/server/appointments.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,24 @@ test("rescheduling across dates keeps booking history and moves the calendar ent
133133
assert.equal(newDay.body.appointments.find((a: { id: number }) => a.id === id).end_time, "15:30");
134134
});
135135

136+
test("client history summarizes services and the latest service note", async (t) => {
137+
const { create, call } = await setup(t);
138+
const created = await create({ service_ids: [1, 2] });
139+
const id = created.body.appointment.id;
140+
assert.equal((await call("POST", `/api/appointments/${id}/notes`, { content: "First formula" })).status, 201);
141+
assert.equal((await call("POST", `/api/appointments/${id}/notes`, { content: "Latest formula" })).status, 201);
142+
const blank = await create({ service_ids: [], start_time: "12:00" });
143+
144+
const history = await call("GET", "/api/clients/1");
145+
assert.equal(history.status, 200);
146+
const visit = history.body.appointments.find((appointment: { id: number }) => appointment.id === id);
147+
assert.equal(visit.service_names, "Standard Session, Quick Service");
148+
assert.equal(visit.latest_note, "Latest formula");
149+
const blankVisit = history.body.appointments.find((appointment: { id: number }) => appointment.id === blank.body.appointment.id);
150+
assert.equal(blankVisit.service_names, null);
151+
assert.equal(blankVisit.latest_note, null);
152+
});
153+
136154
test("invalid times and midnight overflow cannot bypass the guard, even with an override", async (t) => {
137155
const { create, update, db } = await setup(t);
138156
for (const start_time of ["", "noon", "09:30garbage", "24:00", "23:30"]) {

‎src/server/index.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ const AppointmentSchema = z.object({
102102
client_phone: z.string().optional(),
103103
staff_name: z.string().nullable().optional(),
104104
staff_color: z.string().nullable().optional(),
105+
service_names: z.string().nullable().optional(),
106+
latest_note: z.string().nullable().optional(),
105107
appointment_services: z.array(AppointmentServiceSchema).optional(),
106108
appointment_notes: z.array(AppointmentNoteSchema).optional(),
107109
created_at: z.string(),
@@ -707,7 +709,20 @@ app.openapi(getClient, async (c) => {
707709
const client = await get<Record<string, unknown>>("SELECT * FROM clients WHERE id = ?", [id]);
708710
if (!client) return c.json({ error: "Not found" }, 404);
709711
const appointments = await query<Record<string, unknown>>(
710-
`SELECT a.*, s.name as staff_name, s.color as staff_color
712+
`SELECT a.*, s.name as staff_name, s.color as staff_color,
713+
(SELECT GROUP_CONCAT(name, ', ')
714+
FROM (
715+
SELECT sv.name
716+
FROM appointment_services aps
717+
JOIN services sv ON sv.id = aps.service_id
718+
WHERE aps.appointment_id = a.id
719+
ORDER BY aps.id
720+
)) as service_names,
721+
(SELECT an.content
722+
FROM appointment_notes an
723+
WHERE an.appointment_id = a.id
724+
ORDER BY an.created_at DESC, an.id DESC
725+
LIMIT 1) as latest_note
711726
FROM appointments a LEFT JOIN staff s ON s.id = a.staff_id
712727
WHERE a.client_id = ? ORDER BY a.scheduled_date DESC LIMIT 50`,
713728
[id],

0 commit comments

Comments
 (0)