Room planner: rewrite card layout to match original Gantt design
Replace CSS grid with the original plugin's vertical list + 23px margin bracket system. Each card has a 2px border coloured by booking status; data-previous-status / data-next-status drive C-bracket pseudo-elements in the 23px gutter; data-spans-previous/next remove the corresponding border and collapse the margin to extend the card across days. Card interior is restructured: header row (room number, flow badge, lock, nights counter, site-status pill), guest info row, and stats row (time pill, bed-type pill, task-status bordered pill). Category headers now match the original's sticky bordered style with edge-extending pseudo-elements. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
3c0eb5ae73
commit
00e5e684fa
2 changed files with 439 additions and 209 deletions
|
|
@ -1,9 +1,10 @@
|
|||
import { memo } from 'react'
|
||||
import type { RoomData, AppConfig } from '../types'
|
||||
import {
|
||||
roomCardColor, bookingStatusColor, FLOW_TYPE_LABEL, sliverColor, spanDataAttrs,
|
||||
hasOutstandingTasks, isDirty,
|
||||
} from '../lib/booking-flow'
|
||||
Lock, Moon, Clock, BedDouble, BedSingle,
|
||||
ClipboardX, ClipboardCheck, Clipboard,
|
||||
ArrowDown, ArrowUp, ArrowUpDown, Package,
|
||||
} from 'lucide-react'
|
||||
import type { RoomData, AppConfig } from '../types'
|
||||
import { detectTwin } from '../lib/twin-detect'
|
||||
|
||||
interface Props {
|
||||
|
|
@ -13,113 +14,225 @@ interface Props {
|
|||
onClick: (room: RoomData) => void
|
||||
}
|
||||
|
||||
const I = { strokeWidth: 1.75 }
|
||||
|
||||
function nightsInfo(arrival: string, departure: string, viewDate: string) {
|
||||
const msDay = 86400000
|
||||
const total = Math.round((Date.parse(departure) - Date.parse(arrival)) / msDay)
|
||||
const current = Math.round((Date.parse(viewDate) - Date.parse(arrival)) / msDay) + 1
|
||||
return { current: Math.max(1, Math.min(current, total)), total: Math.max(1, total) }
|
||||
}
|
||||
|
||||
function etaTime(eta: string | null | undefined): string | null {
|
||||
if (!eta) return null
|
||||
const t = eta.slice(11, 16)
|
||||
return t && t !== '00:00' ? t : null
|
||||
}
|
||||
|
||||
function statusCls(status: string): string {
|
||||
const s = (status || '').toLowerCase()
|
||||
if (s === 'clean') return 'site-clean'
|
||||
if (s === 'inspected') return 'site-inspected'
|
||||
if (s === 'dirty') return 'site-dirty'
|
||||
return 'site-unknown'
|
||||
}
|
||||
|
||||
const FLOW: Record<string, { label: string; cls: string }> = {
|
||||
arrive: { label: 'Arrive', cls: 'flow-arrive' },
|
||||
depart: { label: 'Depart', cls: 'flow-depart' },
|
||||
stopover: { label: 'Stay', cls: 'flow-stopover' },
|
||||
'back-to-back': { label: 'B2B', cls: 'flow-b2b' },
|
||||
vacant: { label: 'Vacant', cls: 'flow-vacant' },
|
||||
blocked: { label: 'Blocked', cls: '' },
|
||||
}
|
||||
|
||||
function FlowIcon({ type }: { type: string }) {
|
||||
if (type === 'arrive') return <ArrowDown size={10} {...I} />
|
||||
if (type === 'depart') return <ArrowUp size={10} {...I} />
|
||||
if (type === 'back-to-back') return <ArrowUpDown size={10} {...I} />
|
||||
return null
|
||||
}
|
||||
|
||||
function RoomCard({ room, viewDate, config, onClick }: Props) {
|
||||
const booking = room.booking
|
||||
const twinType = detectTwin(booking, config)
|
||||
const taskDisplay = config?.task_display ?? {}
|
||||
const booking = room.booking
|
||||
const twinType = detectTwin(booking, config)
|
||||
const taskDisp = config?.task_display ?? {}
|
||||
const isBlocked = room.flow_type === 'blocked'
|
||||
const isVacant = room.flow_type === 'vacant'
|
||||
|
||||
const stripColor = booking ? bookingStatusColor(booking.booking_status) : 'transparent'
|
||||
const prevColor = sliverColor(room.previous_status)
|
||||
const nextColor = sliverColor(room.next_status)
|
||||
// Booking status (lowercased) drives the card border via CSS attribute selector
|
||||
const bookingStatus = booking?.booking_status?.toLowerCase() ?? null
|
||||
|
||||
// Tasks relevant for today
|
||||
// Tasks in scope for today
|
||||
const todayTasks = room.tasks.filter(t => {
|
||||
const d = t.task_when_date || t.task_period_from
|
||||
return !d || d <= viewDate && (t.task_period_to ? t.task_period_to >= viewDate : d === viewDate)
|
||||
return !d || (d <= viewDate && (!t.task_period_to || t.task_period_to >= viewDate))
|
||||
})
|
||||
const outstanding = todayTasks.filter(t => !t.completed_on)
|
||||
const hasRollover = outstanding.some(t => {
|
||||
const d = t.task_when_date || t.task_period_from
|
||||
return !!d && d < viewDate
|
||||
})
|
||||
|
||||
const outstanding = todayTasks.filter(t => !t.completed_on)
|
||||
const dirty = isDirty(room)
|
||||
// Night counter (current night / total nights)
|
||||
const nights = booking?.booking_arrival && booking?.booking_departure
|
||||
? nightsInfo(booking.booking_arrival, booking.booking_departure, viewDate)
|
||||
: null
|
||||
|
||||
const spanAttrs = spanDataAttrs(room)
|
||||
const cssVars: Record<string, string> = {}
|
||||
if (room.spans_previous) cssVars['--prev-color'] = prevColor
|
||||
if (room.spans_next) cssVars['--next-color'] = nextColor
|
||||
// Time pills
|
||||
const arriveTime = (room.flow_type === 'arrive' || room.flow_type === 'back-to-back')
|
||||
? etaTime(booking?.booking_eta)
|
||||
: null
|
||||
const departTime = (room.flow_type === 'depart' || room.flow_type === 'back-to-back')
|
||||
? (room.departing_time?.slice(0, 5) ?? null)
|
||||
: null
|
||||
|
||||
// CSS data attributes for the Gantt bracket system
|
||||
const dataAttrs: Record<string, string> = {}
|
||||
if (bookingStatus) dataAttrs['data-booking-status'] = bookingStatus
|
||||
if (room.spans_previous) {
|
||||
dataAttrs['data-spans-previous'] = 'true'
|
||||
} else if (room.previous_status) {
|
||||
dataAttrs['data-previous-status'] = room.previous_status.toLowerCase()
|
||||
}
|
||||
if (room.spans_next) {
|
||||
dataAttrs['data-spans-next'] = 'true'
|
||||
} else if (room.next_status) {
|
||||
dataAttrs['data-next-status'] = room.next_status.toLowerCase()
|
||||
}
|
||||
|
||||
// Task status pill
|
||||
let taskCls: string
|
||||
let TaskIcon: typeof Clipboard
|
||||
if (todayTasks.length === 0) {
|
||||
taskCls = 'no-tasks'; TaskIcon = Clipboard
|
||||
} else if (outstanding.length === 0) {
|
||||
taskCls = 'all-done'; TaskIcon = ClipboardCheck
|
||||
} else if (hasRollover) {
|
||||
taskCls = 'rollover'; TaskIcon = ClipboardX
|
||||
} else {
|
||||
taskCls = 'outstanding'; TaskIcon = ClipboardX
|
||||
}
|
||||
|
||||
const flow = FLOW[room.flow_type] ?? FLOW.vacant
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`room-card${isBlocked ? ' blocked-room' : ''}`}
|
||||
style={cssVars as React.CSSProperties}
|
||||
{...(spanAttrs as React.HTMLAttributes<HTMLDivElement>)}
|
||||
className={`room-card${isBlocked ? ' room-blocked' : ''}`}
|
||||
{...(dataAttrs as React.HTMLAttributes<HTMLDivElement>)}
|
||||
onClick={() => onClick(room)}
|
||||
>
|
||||
{!isBlocked && (
|
||||
<div className="card-status-strip" style={{ background: stripColor }} />
|
||||
)}
|
||||
|
||||
<div className="card-inner">
|
||||
<div className="card-top">
|
||||
<span className="card-room-name">{room.site_name}</span>
|
||||
<div className="card-badges">
|
||||
{twinType === 'twin' && <span className="card-badge badge-twin">Twin</span>}
|
||||
{twinType === 'extra-bed' && <span className="card-badge badge-extra">+Bed</span>}
|
||||
{booking?.pax != null && booking.pax > 0 && (
|
||||
<span className="card-badge badge-pax">{booking.pax}p</span>
|
||||
)}
|
||||
{room.departing_time && (
|
||||
<span className="card-badge badge-depart-time">{room.departing_time.slice(0,5)}</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{/* ── Header row ─────────────────────────────── */}
|
||||
<div className="card-header">
|
||||
<span className="card-room-number">{room.site_name}</span>
|
||||
|
||||
{!isBlocked && (
|
||||
<div className="card-mid">
|
||||
{booking?.guest_name ? (
|
||||
<span className="card-guest-name">{booking.guest_name}</span>
|
||||
) : (
|
||||
<span className="card-guest-name" style={{ opacity: .4 }}>
|
||||
{room.flow_type === 'vacant' ? 'Vacant' : '—'}
|
||||
</span>
|
||||
)}
|
||||
{booking?.rate_plan_name && (
|
||||
<span className="card-rate">{booking.rate_plan_name}</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="card-bottom">
|
||||
{!isBlocked && (
|
||||
<span
|
||||
className="card-flow-label"
|
||||
style={{
|
||||
background: stripColor + '22',
|
||||
color: stripColor === 'transparent' ? 'var(--text-muted)' : stripColor,
|
||||
}}
|
||||
>
|
||||
{FLOW_TYPE_LABEL[room.flow_type]}
|
||||
</span>
|
||||
)}
|
||||
|
||||
<span className={`card-clean-status ${dirty ? 'dirty-dot' : 'clean-dot'}`}>
|
||||
{dirty ? 'Dirty' : room.site_status}
|
||||
<span className={`card-flow-badge ${flow.cls}`}>
|
||||
<FlowIcon type={room.flow_type} />
|
||||
{flow.label}
|
||||
</span>
|
||||
)}
|
||||
|
||||
{outstanding.length > 0 && (
|
||||
<span className="card-badge badge-tasks" style={{ background: '#fef3c7', color: '#92400e' }}>
|
||||
{outstanding.length} task{outstanding.length > 1 ? 's' : ''}
|
||||
{isBlocked && (
|
||||
<span style={{ marginLeft: 4, color: 'rgba(255,255,255,.7)', display: 'flex' }}>
|
||||
<Package size={13} {...I} />
|
||||
</span>
|
||||
)}
|
||||
|
||||
{booking?.booking_locked && (
|
||||
<span className="card-locked-icon"><Lock size={11} {...I} /></span>
|
||||
)}
|
||||
|
||||
<div className="card-header-right">
|
||||
{nights && !isVacant && (
|
||||
<span className="card-nights">
|
||||
<Moon size={11} {...I} />
|
||||
{nights.current}/{nights.total}
|
||||
</span>
|
||||
)}
|
||||
<span className={`card-site-status ${statusCls(room.site_status)}`}>
|
||||
{room.site_status || 'Unknown'}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Task dots for show_on_card tasks */}
|
||||
{todayTasks.length > 0 && (
|
||||
<div className="card-task-dots">
|
||||
{todayTasks.map(t => {
|
||||
const display = taskDisplay[t.task_type_id]
|
||||
if (!display?.show_on_card) return null
|
||||
return (
|
||||
<div
|
||||
key={t.task_id}
|
||||
className={`task-dot${t.completed_on ? ' complete' : ''}`}
|
||||
style={{ background: display.color || '#94a3b8' }}
|
||||
title={display.label || t.task_description}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* ── Guest info row ──────────────────────────── */}
|
||||
{!isBlocked && (
|
||||
<div className="card-guest-row">
|
||||
{isVacant ? (
|
||||
<span className="card-vacant-label">Vacant</span>
|
||||
) : booking?.guest_name ? (
|
||||
<span className="card-guest-name">{booking.guest_name}</span>
|
||||
) : (
|
||||
<span className="card-guest-name" style={{ opacity: .4 }}>—</span>
|
||||
)}
|
||||
|
||||
{!isVacant && booking?.pax != null && booking.pax > 0 && (
|
||||
<span className="card-pax-badge">{booking.pax}p</span>
|
||||
)}
|
||||
{twinType === 'twin' && <span className="card-type-badge type-twin">Twin</span>}
|
||||
{twinType === 'extra-bed' && <span className="card-type-badge type-extra">+Bed</span>}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ── Stats row ───────────────────────────────── */}
|
||||
{!isBlocked && !isVacant && (
|
||||
<div className="card-stats-row">
|
||||
|
||||
{/* Arrival ETA */}
|
||||
{arriveTime && (
|
||||
<span className="card-stat-pill time-arrive">
|
||||
<Clock size={11} {...I} /> {arriveTime}
|
||||
</span>
|
||||
)}
|
||||
|
||||
{/* Departure time */}
|
||||
{departTime && (
|
||||
<span className="card-stat-pill time-depart">
|
||||
<Clock size={11} {...I} /> {departTime}
|
||||
</span>
|
||||
)}
|
||||
|
||||
{/* Bed type */}
|
||||
{twinType === 'twin' ? (
|
||||
<span className="card-stat-pill bed-twin">
|
||||
<BedSingle size={11} {...I} /><BedSingle size={11} {...I} />
|
||||
</span>
|
||||
) : twinType === 'extra-bed' ? (
|
||||
<span className="card-stat-pill bed-extra">
|
||||
<BedDouble size={11} {...I} /><BedSingle size={11} {...I} />
|
||||
</span>
|
||||
) : (
|
||||
<span className="card-stat-pill bed-double">
|
||||
<BedDouble size={11} {...I} />
|
||||
</span>
|
||||
)}
|
||||
|
||||
{/* Task status */}
|
||||
<span className={`card-task-pill ${taskCls}`}>
|
||||
<TaskIcon size={12} {...I} />
|
||||
{outstanding.length > 0 && <span>{outstanding.length}</span>}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ── show_on_card task dots ──────────────────── */}
|
||||
{todayTasks.some(t => taskDisp[t.task_type_id]?.show_on_card) && (
|
||||
<div className="card-task-dots">
|
||||
{todayTasks.map(t => {
|
||||
const d = taskDisp[t.task_type_id]
|
||||
if (!d?.show_on_card) return null
|
||||
return (
|
||||
<div
|
||||
key={t.task_id}
|
||||
className={`task-dot${t.completed_on ? ' complete' : ''}`}
|
||||
style={{ background: d.color || '#94a3b8' }}
|
||||
title={d.label || t.task_description}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue