import { useEffect, useState } from 'react'; import Header from '../components/Header/Header'; import Footer from '../components/Footer/Footer'; import { Head } from '@inertiajs/react'; import styles from './Home.module.css'; import AppLayout from '@/layouts/AppLayout'; import { ActionButtons } from '../components/ActionButtons/ActionButtons'; import classNames from 'classnames'; interface OpeningHour { type: 'opening_hour'; data: { name: string; time: string; }; } interface Promotion { id: number; sort_order: number; title: string; description: string; additional_info: string | null; created_at: string; updated_at: string; } interface HomepageData { status: string; data: { photo: string | null; photo_mobile: string | null; title: string | null; body: string | null; delivery: string | null; address: string | null; opening_hours: OpeningHour[]; widget_link: string | null; }; } export default function Home() { const [data, setData] = useState(null); const [promotions, setPromotions] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { Promise.all([ fetch('/api/homepage').then(res => res.json()), fetch('/api/promotions').then(res => res.json()) ]) .then(([homepageResponse, promotionsResponse]) => { setData(homepageResponse.data); setPromotions(promotionsResponse.data); setLoading(false); }) .catch(error => { console.error('Error fetching data:', error); setLoading(false); }); }, []); if (loading) { return ( <> ); } return (
{data?.body && (
)}
{promotions.map((promotion) => (
{promotion.title} {promotion.description} {promotion.additional_info}
))}
{data?.delivery && (
)}
{data?.address && (
)}
Godziny otwarcia:
{data?.opening_hours.map((hour, index) => (
{hour.data.name}
{hour.data.time}
))}
{data?.widget_link ? (