const VendorsView = ({ selectedProperty }) => { const { useState, useEffect, useRef } = React; const [vendors, setVendors] = useState([]); const [propertyVendors, setPropertyVendors] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { loadVendors(); if (selectedProperty) { loadPropertyVendors(); } }, [selectedProperty]); const loadVendors = async () => { try { const res = await fetch('/api/vendors'); if (res.ok) { const data = await res.json(); setVendors(data.vendors || []); } } catch (error) { console.error('Failed to load vendors:', error); } finally { setLoading(false); } }; const loadPropertyVendors = async () => { if (!selectedProperty) return; try { const res = await fetch(`/api/properties/${selectedProperty.property_code}/vendors`); if (res.ok) { const data = await res.json(); setPropertyVendors(data.property_vendors || []); } } catch (error) { console.error('Failed to load property vendors:', error); } }; if (loading) { return (
{selectedProperty ? `Viewing vendors for ${selectedProperty.name}` : 'All vendors'}
{pv.service_name}
{pv.description && ({pv.description}
)}No vendors are currently configured
Contact: {vendor.contact_name}
)} {vendor.contact_email && (Email: {vendor.contact_email}
)} {vendor.contact_phone && (Phone: {vendor.contact_phone}
)} {vendor.website && ( Visit Website → )}