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 (
); } return (

Vendors

{selectedProperty ? `Viewing vendors for ${selectedProperty.name}` : 'All vendors'}

{selectedProperty && propertyVendors.length > 0 && (

Property Assigned Vendors

{propertyVendors.map((pv, idx) => (

{pv.vendor_name}

{pv.service_name}

{pv.description && (

{pv.description}

)}
{pv.updated_by && ( Updated by {pv.updated_by} )}
))}
)}

All Vendors

{vendors.length === 0 ? (
🏢

No vendors found

No vendors are currently configured

) : (
{vendors.map((vendor) => (

{vendor.name}

{vendor.contact_name && (

Contact: {vendor.contact_name}

)} {vendor.contact_email && (

Email: {vendor.contact_email}

)} {vendor.contact_phone && (

Phone: {vendor.contact_phone}

)} {vendor.website && ( Visit Website → )}
))}
)}
); }; if (typeof window !== 'undefined') window.VendorsView = VendorsView; // ═══════════════════════════════════════════════════════════════════════════ // VENUES VIEW COMPONENT // ═══════════════════════════════════════════════════════════════════════════