Initial commit

This commit is contained in:
dahoud
2025-10-01 01:39:07 +00:00
commit b430bf3b96
826 changed files with 255287 additions and 0 deletions

80
hooks/useChantiers.ts Normal file
View File

@@ -0,0 +1,80 @@
import { useState, useEffect } from 'react';
import { apiClient } from '../services/api-client';
import { Chantier } from '../types/btp';
export const useChantiers = () => {
const [chantiers, setChantiers] = useState<Chantier[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const fetchChantiers = async () => {
try {
setLoading(true);
const response = await apiClient.get('/chantiers');
setChantiers(response.data);
setError(null);
} catch (err) {
console.error('Erreur lors du chargement des chantiers:', err);
setError('Erreur lors du chargement des chantiers');
} finally {
setLoading(false);
}
};
const getChantierById = async (id: string) => {
try {
const response = await apiClient.get(`/chantiers/${id}`);
return response.data;
} catch (err) {
console.error('Erreur lors du chargement du chantier:', err);
throw err;
}
};
const createChantier = async (chantier: Partial<Chantier>) => {
try {
const response = await apiClient.post('/chantiers', chantier);
await fetchChantiers();
return response.data;
} catch (err) {
console.error('Erreur lors de la création du chantier:', err);
throw err;
}
};
const updateChantier = async (id: string, chantier: Partial<Chantier>) => {
try {
const response = await apiClient.put(`/chantiers/${id}`, chantier);
await fetchChantiers();
return response.data;
} catch (err) {
console.error('Erreur lors de la mise à jour du chantier:', err);
throw err;
}
};
const deleteChantier = async (id: string) => {
try {
await apiClient.delete(`/chantiers/${id}`);
await fetchChantiers();
} catch (err) {
console.error('Erreur lors de la suppression du chantier:', err);
throw err;
}
};
useEffect(() => {
fetchChantiers();
}, []);
return {
chantiers,
loading,
error,
refresh: fetchChantiers,
getChantierById,
createChantier,
updateChantier,
deleteChantier
};
};