Bookability: show last-updated timestamp per date column
Backend adds valid_from to DateRateInfo and computes date_last_updated dict (max valid_from across categories per date). Frontend renders it as a small timestamp below the date in each column header — time only if today, date+time if older. Full ISO string in title tooltip. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
9e6801482f
commit
7223ae9c30
2 changed files with 40 additions and 2 deletions
|
|
@ -37,12 +37,14 @@ interface DateRateInfo {
|
|||
tariffs: TariffInfo[]
|
||||
tariff_count: number
|
||||
occupancy?: OccupancyInfo
|
||||
valid_from?: string | null
|
||||
}
|
||||
|
||||
interface RateMatrixData {
|
||||
categories: CategoryInfo[]
|
||||
dates: string[]
|
||||
matrix: Record<string, Record<string, DateRateInfo>>
|
||||
date_last_updated?: Record<string, string | null>
|
||||
}
|
||||
|
||||
// Helper functions
|
||||
|
|
@ -56,6 +58,16 @@ const formatDayOfWeek = (dateStr: string): string => {
|
|||
return date.toLocaleDateString('en-GB', { weekday: 'short' })
|
||||
}
|
||||
|
||||
const formatLastUpdated = (isoStr: string | null | undefined): string => {
|
||||
if (!isoStr) return ''
|
||||
const d = new Date(isoStr)
|
||||
const now = new Date()
|
||||
const isToday = d.toDateString() === now.toDateString()
|
||||
return isToday
|
||||
? d.toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit' })
|
||||
: d.toLocaleDateString('en-GB', { day: '2-digit', month: 'short' }) + ' ' + d.toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit' })
|
||||
}
|
||||
|
||||
const isWeekend = (dateStr: string): boolean => {
|
||||
const date = new Date(dateStr + 'T00:00:00')
|
||||
const day = date.getDay()
|
||||
|
|
@ -422,6 +434,11 @@ const Bookability: React.FC = () => {
|
|||
>
|
||||
{refreshingDate === dateStr ? '...' : '↻'}
|
||||
</button>
|
||||
{data.date_last_updated?.[dateStr] && (
|
||||
<span style={styles.lastUpdated} title={`Rates last fetched: ${data.date_last_updated[dateStr]}`}>
|
||||
{formatLastUpdated(data.date_last_updated[dateStr])}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</th>
|
||||
))}
|
||||
|
|
@ -853,6 +870,12 @@ const styles: Record<string, React.CSSProperties> = {
|
|||
fontSize: '13px',
|
||||
fontWeight: 600,
|
||||
},
|
||||
lastUpdated: {
|
||||
fontSize: '9px',
|
||||
color: 'var(--text-mid)',
|
||||
opacity: 0.7,
|
||||
lineHeight: 1,
|
||||
},
|
||||
weekendHeader: {
|
||||
background: 'var(--body-bg)',
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue