mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 09:38:54 +00:00
@
fix(dashboard): fix the upcoming widget dropping bookings, and give it the stays back Three things, all in the same widget. reservation_time holds two shapes. The booking form writes the datetime-local YYYY-MM-DDTHH:MM; day-anchored rows, the demo seed among them, hold a bare HH:MM. The query compared the column against an ISO timestamp as a string, where ":" sorts above "2": every booking from 20:00 on passed the filter and everything before it silently vanished, and the order ran off the same column. On the demo that is why the Broadway show shows and the ferry does not. The query now separates the date from the time before it filters, so a value with no date falls back to the day it hangs off instead of being read as one, and the order is by day and clock. The demo seed writes full timestamps, which is the shape every real write path already produces. Hotels came out of this list because a stay covers a range and a week in one would hold a slot for the whole week. Arriving and leaving do not: they are moments, and they are the two worth reminding someone of. Check-in and check-out now appear as their own entries, named after the stay place and falling back to the linked booking. The stay itself stays out. The two carry the accommodation id, so the list key had to take the type with it. An unconfirmed booking looked exactly like a confirmed one. The status was already in the payload and is now a badge, on both the desktop tool and the phone widget. @
This commit is contained in:
@@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import { useNavigate } from 'react-router'
|
||||
import {
|
||||
ArrowRight, ArrowRightLeft, Bookmark, Calendar, ChevronDown, ChevronRight,
|
||||
Clock, Hotel, MapPin, Plane, Plus, RefreshCw, Ticket, Utensils, X,
|
||||
Clock, Hotel, LogIn, LogOut, MapPin, Plane, Plus, RefreshCw, Ticket, Utensils, X,
|
||||
} from 'lucide-react'
|
||||
import { useTranslation } from '../../../i18n'
|
||||
import { useSettingsStore } from '../../../store/settingsStore'
|
||||
@@ -12,14 +12,21 @@ import { entityGradient } from '../../../utils/gradients'
|
||||
import { CURRENCIES } from '../../../components/Budget/BudgetPanel.constants'
|
||||
import { formatTime, splitReservationDateTime } from '../../../utils/formatters'
|
||||
import { normalizeAppearance, MOBILE_DASH_TOKENS, type MobileDashToken, type Collection } from '@trek/shared'
|
||||
import type { UpcomingReservation } from '../../../pages/dashboard/dashboardModel'
|
||||
import { upcomingKey, type UpcomingReservation } from '../../../pages/dashboard/dashboardModel'
|
||||
|
||||
const RES_ICON: Record<string, React.ReactElement> = {
|
||||
flight: <Plane size={14} strokeWidth={2} />,
|
||||
hotel: <Hotel size={14} strokeWidth={2} />,
|
||||
restaurant: <Utensils size={14} strokeWidth={2} />,
|
||||
// A stay's two moments (#1934) — the stay itself covers a range and stays out
|
||||
// of a list of what happens next; arriving and leaving are points in time.
|
||||
checkin: <LogIn size={14} strokeWidth={2} />,
|
||||
checkout: <LogOut size={14} strokeWidth={2} />,
|
||||
}
|
||||
|
||||
/** The label a stay's moment carries in place of a location. */
|
||||
const MOMENT_LABEL: Record<string, string> = { checkin: 'day.checkIn', checkout: 'day.checkOut' }
|
||||
|
||||
/**
|
||||
* Inline dashboard widget panels (currency, collections, timezones, upcoming
|
||||
* reservations) for the mobile dashboard. The blocks are rendered individually
|
||||
@@ -409,8 +416,8 @@ function MUpcomingWidget({ items }: { items: UpcomingReservation[] }): React.Rea
|
||||
? date.toLocaleDateString(locale, { day: 'numeric', month: 'short', timeZone: 'UTC' })
|
||||
: null
|
||||
const timeStr = parsed.time ? formatTime(parsed.time, locale, timeFormat) : null
|
||||
const place = r.location || r.place_name || r.trip_title || null
|
||||
return [dateStr, timeStr, place].filter(Boolean).join(' · ')
|
||||
const tail = MOMENT_LABEL[r.type] ? t(MOMENT_LABEL[r.type]) : (r.location || r.place_name || r.trip_title || null)
|
||||
return [dateStr, timeStr, tail].filter(Boolean).join(' · ')
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -420,7 +427,7 @@ function MUpcomingWidget({ items }: { items: UpcomingReservation[] }): React.Rea
|
||||
) : (
|
||||
items.map(r => (
|
||||
<button
|
||||
key={r.id}
|
||||
key={upcomingKey(r)}
|
||||
type="button"
|
||||
onClick={() => openReservation(r.trip_id)}
|
||||
className="flex w-full items-center gap-[11px] border-b border-[color:var(--m-rowbr)] py-[9px] text-left"
|
||||
@@ -429,7 +436,14 @@ function MUpcomingWidget({ items }: { items: UpcomingReservation[] }): React.Rea
|
||||
{RES_ICON[r.type] || <Ticket size={14} strokeWidth={2} />}
|
||||
</span>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="truncate text-[0.8125rem] font-semibold">{r.title}</div>
|
||||
<div className="flex min-w-0 items-center gap-1.5">
|
||||
<span className="truncate text-[0.8125rem] font-semibold">{r.title}</span>
|
||||
{r.status === 'pending' && (
|
||||
<span className="flex-none rounded-full bg-[color:var(--m-ic)] px-[6px] py-px font-geist text-[0.5625rem] font-bold uppercase tracking-[.08em] text-m-muted">
|
||||
{t('reservations.pending')}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="truncate font-geist text-[0.625rem] text-m-muted">{subFor(r)}</div>
|
||||
</div>
|
||||
<ChevronRight size={14} strokeWidth={2} className="flex-none text-m-faint" />
|
||||
|
||||
@@ -180,6 +180,32 @@ describe('DashboardPage (desktop)', () => {
|
||||
expect(screen.getByText('Hotel Ibis')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
// #1934 — a stay covers a range and stays out of a list of what happens next,
|
||||
// but arriving and leaving are moments, and they carry the same id.
|
||||
it('FE-PAGE-DESKDASH-027: a stay renders as two moments and an unconfirmed booking says so', async () => {
|
||||
seedStore(useSettingsStore, { settings: buildSettings({ time_format: '24h' }) });
|
||||
server.use(http.get('/api/reservations/upcoming', () => HttpResponse.json({
|
||||
reservations: [
|
||||
{ id: 7, trip_id: 101, title: 'The Plaza', type: 'checkin', status: 'confirmed', reservation_time: '2026-09-18T15:00', day_date: '2026-09-18' },
|
||||
{ id: 3, trip_id: 101, title: 'Broadway Show', type: 'activity', status: 'pending', reservation_time: '2026-09-18T20:00', location: 'Richard Rodgers' },
|
||||
{ id: 7, trip_id: 101, title: 'The Plaza', type: 'checkout', status: 'confirmed', reservation_time: '2026-09-22T11:00', day_date: '2026-09-22' },
|
||||
],
|
||||
})));
|
||||
const { container } = render(<DashboardPage />);
|
||||
|
||||
// Both moments render despite sharing id 7 — the list key carries the type.
|
||||
expect(await screen.findAllByText('The Plaza')).toHaveLength(2);
|
||||
// The label shares its line with the time, so match the row, not a bare node.
|
||||
expect(screen.getByText(/Check-in/)).toBeInTheDocument();
|
||||
expect(screen.getByText(/Check-out/)).toBeInTheDocument();
|
||||
expect(container.querySelectorAll('.upc-item')).toHaveLength(3);
|
||||
|
||||
// Only the unconfirmed one is marked.
|
||||
const pending = container.querySelectorAll('.upc-pending');
|
||||
expect(pending).toHaveLength(1);
|
||||
expect(pending[0]).toHaveTextContent('Pending');
|
||||
});
|
||||
|
||||
it('FE-PAGE-DESKDASH-009: the currency tool converts and swaps the pair', async () => {
|
||||
seedStore(useSettingsStore, { settings: buildSettings({ dashboard_fx_from: 'EUR', dashboard_fx_to: 'USD' }) });
|
||||
const { container } = render(<DashboardPage />);
|
||||
|
||||
@@ -12,12 +12,12 @@ import MobileTopBar from '../components/Layout/MobileTopBar'
|
||||
import { useDashboard } from './dashboard/useDashboard'
|
||||
import {
|
||||
type DashboardTrip, type HeroBundle, type TravelStats, type UpcomingReservation,
|
||||
MS_PER_DAY, daysUntil, getTripStatus,
|
||||
MS_PER_DAY, daysUntil, getTripStatus, upcomingKey,
|
||||
} from './dashboard/dashboardModel'
|
||||
import {
|
||||
Plus, Edit2, Trash2, Archive, ArchiveRestore, Copy, ArrowRight, MapPin,
|
||||
Plane, Hotel, Utensils, Clock, RefreshCw, ArrowRightLeft, Calendar,
|
||||
LayoutGrid, List, Ticket, X, CalendarPlus, ParkingSquare,
|
||||
LayoutGrid, List, Ticket, X, CalendarPlus, ParkingSquare, LogIn, LogOut,
|
||||
} from 'lucide-react'
|
||||
import { IcsSubscribeModal } from '../components/Planner/IcsSubscribeModal'
|
||||
import CollectionsWidget from '../components/Dashboard/CollectionsWidget'
|
||||
@@ -91,8 +91,15 @@ function initials(name: string | null | undefined): string {
|
||||
|
||||
const RES_ICON: Record<string, React.ReactElement> = {
|
||||
flight: <Plane size={16} />, hotel: <Hotel size={16} />, restaurant: <Utensils size={16} />, parking: <ParkingSquare size={16} />,
|
||||
// A stay's two moments (#1934) — the arrow says which way you are going, on
|
||||
// the same green the hotel tile already uses.
|
||||
checkin: <LogIn size={16} />, checkout: <LogOut size={16} />,
|
||||
}
|
||||
const RES_TYPE_CLASS: Record<string, string> = { flight: 'flight', hotel: 'hotel', restaurant: 'food' }
|
||||
const RES_TYPE_CLASS: Record<string, string> = {
|
||||
flight: 'flight', hotel: 'hotel', restaurant: 'food', checkin: 'hotel', checkout: 'hotel',
|
||||
}
|
||||
/** The label a stay's moment carries in place of a location. */
|
||||
const MOMENT_LABEL: Record<string, string> = { checkin: 'day.checkIn', checkout: 'day.checkOut' }
|
||||
|
||||
export default function DashboardPage(): React.ReactElement {
|
||||
// ViewportRoute in App.tsx picks the branch now, so the phone screen is a
|
||||
@@ -804,16 +811,20 @@ function UpcomingTool({ items, locale, onOpen }: {
|
||||
const dateStr = datePart ? splitDate(datePart, locale) : null
|
||||
const timeStr = parsed.time ? formatTime(parsed.time, locale, timeFormat) : null
|
||||
const typeClass = RES_TYPE_CLASS[r.type] || 'other'
|
||||
const moment = MOMENT_LABEL[r.type]
|
||||
return (
|
||||
<div className="upc-item" key={r.id} onClick={() => onOpen(r.trip_id)}
|
||||
<div className="upc-item" key={upcomingKey(r)} onClick={() => onOpen(r.trip_id)}
|
||||
role="button" tabIndex={0}
|
||||
onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); onOpen(r.trip_id) } }}>
|
||||
<div className="upc-date"><div className="d mono">{dateStr?.d ?? '–'}</div><div className="m">{dateStr?.m ?? ''}</div></div>
|
||||
<div className="upc-info">
|
||||
<div className="t">{r.title}</div>
|
||||
<div className="t">
|
||||
{r.title}
|
||||
{r.status === 'pending' && <span className="upc-pending">{t('reservations.pending')}</span>}
|
||||
</div>
|
||||
<div className="s">
|
||||
{timeStr && <><Clock size={11} /> {timeStr} · </>}
|
||||
{r.location || r.place_name || r.trip_title}
|
||||
{moment ? t(moment) : (r.location || r.place_name || r.trip_title)}
|
||||
</div>
|
||||
</div>
|
||||
<div className={`upc-type ${typeClass}`}>{RES_ICON[r.type] || <Ticket size={16} />}</div>
|
||||
|
||||
@@ -23,11 +23,21 @@ export interface Place {
|
||||
export interface HeroBundle { members: Member[]; places: Place[] }
|
||||
export interface TravelStats { totalTrips?: number; totalDays?: number; totalPlaces?: number; totalDistanceKm?: number; countries?: string[] }
|
||||
export interface UpcomingReservation {
|
||||
id: number; trip_id: number; title: string; type: string
|
||||
/** Unique per `type`, not on its own: a stay's two moments carry the
|
||||
* accommodation id, which can collide with a reservation id. */
|
||||
id: number; trip_id: number; title: string
|
||||
/** A reservation type, or 'checkin' / 'checkout' for a stay's two moments. */
|
||||
type: string
|
||||
status?: string | null
|
||||
reservation_time?: string | null; day_date?: string | null
|
||||
location?: string | null; place_name?: string | null; trip_title?: string | null
|
||||
}
|
||||
|
||||
/** Stable list key — see the note on `id`. */
|
||||
export function upcomingKey(r: UpcomingReservation): string {
|
||||
return `${r.type}:${r.id}`
|
||||
}
|
||||
|
||||
export const MS_PER_DAY = 86400000
|
||||
|
||||
/**
|
||||
|
||||
@@ -593,6 +593,9 @@
|
||||
.trek-dash .upc-date .d { font-size: 18px; font-weight: 600; letter-spacing: -0.02em; line-height: 1; }
|
||||
.trek-dash .upc-date .m { font-size: 10px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--ink-3); margin-top: 4px; font-weight: 500; }
|
||||
.trek-dash .upc-info .t { font-size: 14px; font-weight: 500; margin-bottom: 2px; }
|
||||
.trek-dash .upc-info .t { display: flex; align-items: center; gap: 7px; }
|
||||
/* An unconfirmed booking looked exactly like a confirmed one here (#1934). */
|
||||
.trek-dash .upc-pending { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; padding: 2px 6px; border-radius: 999px; background: var(--bg-2); color: var(--ink-3); }
|
||||
.trek-dash .upc-info .s { font-size: 12px; color: var(--ink-3); display: flex; align-items: center; gap: 6px; }
|
||||
.trek-dash .upc-info .s svg { width: 11px; height: 11px; }
|
||||
.trek-dash .upc-type { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; }
|
||||
|
||||
Reference in New Issue
Block a user