import React, { useState, useEffect } from 'react'; import { Shop } from '../types'; import { shopApi } from '../services/api'; const ShopList: React.FC = () => { const [shops, setShops] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(''); useEffect(() => { fetchShops(); }, []); const fetchShops = async () => { try { setLoading(true); const response = await shopApi.getAll(); setShops(response.data); } catch (err) { setError('Failed to fetch shops'); console.error('Error fetching shops:', err); } finally { setLoading(false); } }; if (loading) { return (
); } return (

Shops

{error && (
{error}
)}
{shops.length === 0 ? (

No shops

Get started by adding your first shop.

) : (
{shops.map((shop) => (

{shop.name}

{shop.city}
{shop.address && (
{shop.address}
)}
Added {new Date(shop.created_at).toLocaleDateString()}
))}
)}
); }; export default ShopList;