Show own hotel's direct rate (Newbook best available) in the matrix direct sub-row

New GET /competitors/own-direct-rates: cheapest bookable non-dinner
Newbook tariff per date (same selection rules as the parity check).
'Show direct rates' now renders a 'Direct (Newbook)' sub-row under the
own-hotel row alongside the competitors' scraped direct rows; cell
tooltip names the tariff.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-06 08:25:46 +00:00
parent ad0e82465c
commit 2abc2b0297
2 changed files with 91 additions and 0 deletions

View file

@ -1312,6 +1312,18 @@ const RateMatrixTab: React.FC = () => {
enabled: showDirect && hotels.length > 0,
})
// Our own direct rate comes from Newbook (best available), not the direct scraper
const { data: ownDirectRates } = useQuery<Record<string, { rate: number; tariff: string }>>({
queryKey: ['own-direct-rates', fromDate, toDate],
queryFn: async () => {
const res = await api.get('/competitors/own-direct-rates', {
params: { from_date: fromDate, to_date: toDate }
})
return res.data.rates
},
enabled: showDirect,
})
if (isLoading) {
return (
<div style={styles.loading}>
@ -1600,6 +1612,25 @@ const RateMatrixTab: React.FC = () => {
)
})}
</tr>
{/* Own hotel direct sub-row — Newbook best available */}
{showDirect && hotel.tier === 'own' && ownDirectRates &&
Object.keys(ownDirectRates).length > 0 && (
<tr style={{ background: '#fafbfc' }}>
<td style={{ ...styles.matrixTd, ...styles.stickyCol, paddingLeft: 28, fontSize: 11, color: 'var(--text-mid)', fontStyle: 'italic' }}>
Direct (Newbook)
</td>
{dates.map(d => {
const own = ownDirectRates[d]
return (
<td key={d} title={own?.tariff}
style={{ ...styles.matrixTd, fontSize: 11, color: own ? 'var(--text-dark)' : 'var(--text-mid)',
background: isWeekend(d) ? '#fdf8f0' : undefined }}>
{own ? `£${Number(own.rate).toFixed(0)}` : '—'}
</td>
)
})}
</tr>
)}
{/* Direct rates sub-row — only when this hotel actually has direct rates */}
{showDirect && hotel.tier === 'competitor' &&
Object.values(directRatesMap?.[hotel.id] || {}).some(v => v != null) && (