fix: ReviewsPage use useAuth for slug; reviews redirect by booking source

- Replace useParams with useAuth().user.hotelSlug in ReviewsPage
- Backend: filter platforms by booking source when review_redirect_source=true
  (booking_com→Booking.com, yandex_travel→Яндекс, airbnb, expedia, vrbo)
- If source has matching platform — show only that one; otherwise all platforms

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-21 00:21:26 +03:00
parent 6ba591928a
commit 2de9b9e27d
2 changed files with 33 additions and 9 deletions

View File

@@ -119,13 +119,40 @@ const reviewsRoutes: FastifyPluginAsync = async (fastify) => {
AND key IN (
'review_redirect_threshold','review_platforms',
'review_show_text_field','review_welcome_text',
'review_brand_color'
'review_brand_color','review_redirect_source'
)`,
[row.hotel_id],
)
const s: Record<string, unknown> = {}
for (const r of settings) s[r.key] = r.value
// Mapping booking source → keyword to match in platform name
const SOURCE_KEYWORD: Record<string, string> = {
booking_com: 'booking',
airbnb: 'airbnb',
expedia: 'expedia',
vrbo: 'vrbo',
yandex_travel: 'яндекс',
}
const allPlatforms = Array.isArray(s.review_platforms)
? (s.review_platforms as { name: string; url: string; enabled: boolean }[])
.filter(p => p.enabled)
: []
const useSourceRedirect = s.review_redirect_source !== false
const bookingSrc = row.booking_source ?? 'direct'
const keyword = SOURCE_KEYWORD[bookingSrc]
// If source redirect is on and we have a matching platform — show only that one
let platforms = allPlatforms.map(p => ({ name: p.name, url: p.url }))
if (useSourceRedirect && keyword) {
const match = allPlatforms.find(p =>
p.name.toLowerCase().includes(keyword),
)
if (match) platforms = [{ name: match.name, url: match.url }]
}
return {
hotelName: row.hotel_name,
logoLetter: (row.hotel_name as string)[0] ?? 'О',
@@ -133,13 +160,9 @@ const reviewsRoutes: FastifyPluginAsync = async (fastify) => {
color: (s.review_brand_color as string | undefined) ?? '#2563eb',
redirectThreshold: Number(s.review_redirect_threshold ?? 4),
showTextField: s.review_show_text_field !== false,
platforms: Array.isArray(s.review_platforms)
? (s.review_platforms as { name: string; url: string; enabled: boolean }[])
.filter(p => p.enabled)
.map(p => ({ name: p.name, url: p.url }))
: [],
platforms,
guestName: row.guest_name ?? '',
bookingSource: row.booking_source ?? 'direct',
bookingSource: bookingSrc,
}
},
)

View File

@@ -1,5 +1,5 @@
import { useState, useEffect, useCallback } from 'react'
import { useParams } from 'react-router-dom'
import { useAuth } from '../contexts/AuthContext'
import {
Star, ThumbsDown, Copy, CheckCheck, MessageSquare, QrCode,
ArrowUpRight, Plus, Trash2, ExternalLink, Settings2,
@@ -65,7 +65,8 @@ type Tab = 'pending' | 'published' | 'all' | 'preview' | 'settings'
// ── Component ─────────────────────────────────────────────────────────────────
export function ReviewsPage() {
const { slug } = useParams<{ slug: string }>()
const { user } = useAuth()
const slug = user?.hotelSlug ?? ''
const [reviews, setReviews] = useState<ReviewApi[]>([])
const [loading, setLoading] = useState(true)