blob: ff08f6cf724b67c47ecdc1a864635d8f17a48e18 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
import { useEffect, useState } from 'react';
import { officesService } from '@/features/offices/services/officesService';
import { Office } from '@/features/offices/types';
export function useOffices() {
const [offices, setOffices] = useState<Office[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const loadOffices = async () => {
try {
setError(null);
setLoading(true);
const data = await officesService.getAll();
setOffices(data);
} catch (err: any) {
setError(err?.message ?? 'No se pudieron cargar los espacios');
} finally {
setLoading(false);
}
};
useEffect(() => {
loadOffices();
}, []);
return {
offices,
loading,
error,
reload: loadOffices,
};
}
|