29 lines
925 B
TypeScript
29 lines
925 B
TypeScript
import { useState, useEffect } from 'react';
|
|
import { pb } from '@/services/pocketbase';
|
|
import type { ManagedContract } from '@/types/ManagedContract';
|
|
|
|
export const useContracts = () => {
|
|
const [contracts, setContracts] = useState<ManagedContract[]>([]);
|
|
const [isLoading, setIsLoading] = useState(true);
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
useEffect(() => {
|
|
const fetchContracts = async () => {
|
|
try {
|
|
setIsLoading(true);
|
|
const records = await pb.collection('aegis_managed_contracts').getFullList<ManagedContract>({
|
|
sort: '-created',
|
|
});
|
|
setContracts(records);
|
|
} catch (err) {
|
|
console.error("Erreur contrats :", err);
|
|
setError("Impossible de charger le catalogue des services.");
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
};
|
|
fetchContracts();
|
|
}, []);
|
|
|
|
return { contracts, isLoading, error };
|
|
}; |