import { useEffect, useState } from 'react'; import { officesService } from '@/features/offices/services/officesService'; import { Office } from '@/features/offices/types'; import { getErrorMessage } from '@/shared/lib/errors/getErrorMessage'; export function useOffices() { const [offices, setOffices] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const loadOffices = async () => { try { setError(null); setLoading(true); const data = await officesService.getAll(); setOffices(data); } catch (err) { setError(getErrorMessage(err, 'No se pudieron cargar los espacios')); } finally { setLoading(false); } }; useEffect(() => { loadOffices(); }, []); return { offices, loading, error, reload: loadOffices, }; }