import { Head } from '@inertiajs/react'; import { useEffect, useState } from 'react'; import { type BreadcrumbItem } from '@/types'; import AppLayout from '@/layouts/app-layout'; import { Phone, Mail } from 'lucide-react'; import { Link } from '@inertiajs/react'; const getBreadcrumbs = (section: string, slug: string): BreadcrumbItem[] => [ { title: 'Strona Główna', href: '/', }, { title: section || slug.replace(/-/g, ' '), href: `/administracja/${slug}`, }, ]; interface Employee { name: string; slug?: string; sort_order?: number; employees: Array<{ type: string; data: { [key: string]: string | null; }; }>; } interface EmployeesApiResponse { main: Record; extra: Record; } interface EmployeesPageProps { slug: string; } export default function Employees(props: EmployeesPageProps) { const { slug } = props; const [employees, setEmployees] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { setLoading(true); fetch(`/api/employees?slug=${encodeURIComponent(slug)}`) .then(response => response.json()) .then(data => { setEmployees(data); setLoading(false); }) .catch(error => { setEmployees(null); setLoading(false); console.error('Error fetching employees:', error); }); }, [slug]); const mainSections = employees?.main ? Object.values(employees.main) : []; const extraSections = employees?.extra ? Object.values(employees.extra) : []; const sectionName = mainSections.length > 0 ? mainSections[0].name : ''; return (

{sectionName}

{loading ? (
Pobieranie listy pracowników...
) : !employees || (mainSections.length === 0 && extraSections.length === 0) ? ( <>
Sekcja nie istnieje lub brak pracowników w tej sekcji.
Powrót na stronę główną ) : ( <> {mainSections .sort((a: any, b: any) => (a.sort_order ?? 0) - (b.sort_order ?? 0)) .map((section: any, index: number) => (
    {section.employees.map((person: any, idx: number) => (
  • {person.data.first_name?.[0] || ''}{person.data.last_name?.[0] || ''}
    {person.data.title ? person.data.title + ' ' : ''}{person.data.first_name} {person.data.last_name}
    {person.data.position &&
    {person.data.position}
    }
    {person.data.email &&
    {person.data.email}
    } {person.data.phone &&
    {person.data.phone}
    }
  • ))}
))} {extraSections.length > 0 && (
{extraSections .sort((a: any, b: any) => (a.sort_order ?? 0) - (b.sort_order ?? 0)) .map((section: any) => (

{section.name}

    {section.employees.map((person: any, idx: number) => (
  • {person.data.first_name?.[0] || ''}{person.data.last_name?.[0] || ''}
    {person.data.title ? person.data.title + ' ' : ''}{person.data.first_name} {person.data.last_name}
    {person.data.position &&
    {person.data.position}
    }
    {person.data.email &&
    {person.data.email}
    } {person.data.phone &&
    {person.data.phone}
    }
  • ))}
))}
)} )}
); }