import React from 'react' import { cookies } from 'next/headers' import { headers } from 'next/headers' interface Route { id: string from_city_name: string to_city_name: string from_country_name: string to_country_name: string formatted_departure: string formatted_arrival: string formatted_cargo_type: string formatted_transport: string comment?: string owner_type: string } async function getRoutes() { const cookieStore = await cookies() const headersList = await headers() const protocol = headersList.get('x-forwarded-proto') || 'http' const host = headersList.get('host') || 'localhost:3000' const response = await fetch(`${protocol}://${host}/api/account/routes`, { method: 'GET', headers: { 'Content-Type': 'application/json', Cookie: cookieStore.toString(), }, }) if (!response.ok) { const error = await response.json() console.error('Error fetching routes:', error) throw new Error(error.message || 'Failed to fetch routes') } return response.json() } export default async function UserRoutes() { let routes: Route[] = [] try { routes = (await getRoutes()) || [] } catch (error) { console.error('Component error:', error) return (
{error instanceof Error ? error.message : 'Не удалось загрузить маршруты'}
) } return (

Мои маршруты

{(!routes || routes.length === 0) && (

У вас пока нет завершенных маршрутов

Создавайте или принимайте заявки на перевозку, чтобы они отобразились тут

)} {routes.length > 0 && (
{routes.map(route => (
ID маршрута: #{route.id}
{route.owner_type === 'customer' ? 'Заказчик' : 'Перевозчик'}
{route.from_city_name} / {route.from_country_name}
{route.formatted_departure}
{route.to_city_name} / {route.to_country_name}
{route.formatted_arrival}
Тип груза:
{route.formatted_cargo_type}
Способ перевозки:
{route.formatted_transport}
{route.comment && (
Комментарий: {route.comment}
)}
))}
)}
) }