'use client'; import { useState } from 'react'; import { PageLayout, Pagination, StatusBadge, EmptyState } from '@/components/ui'; import AircraftAddModal from '@/components/AircraftAddModal'; import { useAircraftData } from '@/hooks/useSWRData'; import { aircraftApi } from '@/lib/api/api-client'; import { RequireRole } from '@/lib/auth-context'; export default function AircraftPage() { const [page, setPage] = useState(1); const [search, setSearch] = useState(''); const [isAddOpen, setIsAddOpen] = useState(false); const { data, isLoading, mutate } = useAircraftData({ q: search || undefined, page, limit: 25 }); const aircraft = data?.items || (Array.isArray(data) ? data : []); const total = data?.total || aircraft.length; const pages = data?.pages || 1; const handleAdd = async (d: any) => { try { await aircraftApi.create(d); mutate(); setIsAddOpen(false); } catch (e: any) { alert(e.message); } }; const handleDelete = async (id: string) => { if (!confirm('Удалить ВС?')) return; try { await aircraftApi.delete(id); mutate(); } catch (e: any) { alert(e.message); } }; return ( { setSearch(e.target.value); setPage(1); }} className="input-field w-60" /> }> {isLoading ?
Загрузка...
: aircraft.length > 0 ? ( <>
{aircraft.map((a: any) => ( ))}
РегистрацияТипМодель ОператорНалёт (ч)Статус Действия
{a.registration_number || a.registrationNumber} {a.aircraft_type || a.aircraftType} {a.model || '—'} {a.operator || a.operator_name || '—'} {a.flight_hours || a.flightHours || '—'}
) : } setIsAddOpen(false)} onAdd={handleAdd} />
); }