fix(kvytky): client-side tariff fallback when static build has no server
Some checks are pending
CI / Type Check (push) Waiting to run
CI / Lint (push) Waiting to run
CI / Unit Tests (push) Waiting to run
Deploy / Build & Push Image (push) Waiting to run
Deploy / Deploy to VPS (push) Blocked by required conditions

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 <noreply@anthropic.com>
This commit is contained in:
Vadym Samoilenko 2026-06-08 14:50:21 +01:00
parent faff04fab2
commit 12cd941da5

View file

@ -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<Tariff[]>(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<TabId>('all')