From 12cd941da5d3bd82367a47c139c2e4dce0cec393 Mon Sep 17 00:00:00 2001 From: Vadym Samoilenko Date: Mon, 8 Jun 2026 14:50:21 +0100 Subject: [PATCH] fix(kvytky): client-side tariff fallback when static build has no server At Docker build time Next.js renders /kvytky statically before the server starts, so getTariffs() gets empty array. KvytkyTicketsClient now fetches /api/tickets/tariffs on mount when serverTariffs is empty. Co-Authored-By: Claude Sonnet 4.6 --- .../sections/KvytkyTicketsClient.tsx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/components/sections/KvytkyTicketsClient.tsx b/src/components/sections/KvytkyTicketsClient.tsx index 07d3a9f..50ca7ad 100644 --- a/src/components/sections/KvytkyTicketsClient.tsx +++ b/src/components/sections/KvytkyTicketsClient.tsx @@ -1,7 +1,7 @@ 'use client' /* eslint-disable @next/next/no-img-element */ -import { useMemo, useState } from 'react' +import { useEffect, useMemo, useState } from 'react' import { useCart } from '@/context/CartContext' import { CHIP_ICONS, @@ -126,11 +126,20 @@ export function KvytkyTicketsClient({ title = 'Локації та Атракціони', tabLabels = DEFAULT_TAB_LABELS, }: KvytkyTicketsClientProps) { + const [tariffs, setTariffs] = useState(serverTariffs) + + useEffect(() => { + if (serverTariffs.length > 0) return + fetch('/api/tickets/tariffs') + .then((r) => r.json()) + .then((d: { tariffs?: Tariff[] }) => { + if (d.tariffs && d.tariffs.length > 0) setTariffs(d.tariffs) + }) + .catch(() => {}) + }, [serverTariffs.length]) + // Combo tariffs have their own section - const singleTariffs = useMemo( - () => serverTariffs.filter((t) => t.categoryTag !== 'combo'), - [serverTariffs] - ) + const singleTariffs = useMemo(() => tariffs.filter((t) => t.categoryTag !== 'combo'), [tariffs]) const [activeTab, setActiveTab] = useState('all')