'use client' import React, { useEffect, useState } from 'react' import { useSession } from 'next-auth/react' import Link from 'next/link' import Cookies from 'js-cookie' interface Address { id: string street: string city: string postcode: string } interface Route { id: string name: string | null status: string } interface HistoryRecord { id: string action: string createdAt: string route: Route address: Address } export default function HistoryPage() { const { data: session, status } = useSession() const [history, setHistory] = useState([]) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const [messages, setMessages] = useState(null) useEffect(() => { const loadMessages = async () => { const lang = Cookies.get('NEXT_LOCALE') || 'de' const messages = await import(`@/messages/${lang}.json`) setMessages(messages.default) } loadMessages() }, []) useEffect(() => { fetchHistory() }, [session]) const fetchHistory = async () => { try { const response = await fetch('/api/history', { credentials: 'include' }) if (!response.ok) { throw new Error(messages?.history?.error) } const data = await response.json() setHistory(data) } catch (err) { console.error('Geçmiş kayıtları getirme hatası:', err) setError(err instanceof Error ? err.message : messages?.history?.error) } finally { setLoading(false) } } if (!messages || status === 'loading' || loading) { return (
) } if (status === 'unauthenticated') { return (

{messages.common.accessDenied}

{messages.common.loginRequired}

{messages.common.login}
) } return (
{messages.common.back}

{messages.history.title}

{error && (

{error}

)} {history.length === 0 ? (

{messages.history.noRecords}

) : (
    {history.map((record) => (
  • {record.address.street}, {record.address.city} {record.address.postcode}

    {messages.history.routeStatus}: {messages.history.status[record.route.status.toLowerCase()] || record.route.status}

    {new Date(record.createdAt).toLocaleString()}

    {record.action === 'ADDRESS_VIEWED' ? messages.history.addressViewed : record.action}

  • ))}
)}
) }