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 <noreply@anthropic.com>
This commit is contained in:
parent
faff04fab2
commit
12cd941da5
1 changed files with 14 additions and 5 deletions
|
|
@ -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')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue