import { useState, useEffect, useCallback } from 'react'; import { getOrdersList, getOrderDetails } from '../../services/billing_api'; import { useVPC } from '../../services/useVPC'; import { Server, Globe, Folder, Trash2, Loader, Plus, AlertCircle } from 'lucide-react'; // Importation de tes nouveaux composants modulaires ! import NotificationModal from '../../components/ui/NotificationModal'; import InstanceCard from '../../components/services/InstanceCard'; import VpsDeployer from '../../components/services/VpsDeployer'; import VpsManager from '../../components/services/VpsManager'; import WebManager from '../../components/services/WebManager'; export default function Services() { const [services, setServices] = useState([]); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); const [newVpcName, setNewVpcName] = useState(""); const [isConnecting, setIsConnecting] = useState(null); const [activeServiceModal, setActiveServiceModal] = useState(null); const [customAlert, setCustomAlert] = useState(null); const { vpcs, createVPC, deleteVPC, assignToVPC, removeFromVPC } = useVPC(); const triggerAlert = (title, message, type = "info") => setCustomAlert({ title, message, type }); const fetchServices = useCallback(async () => { try { const data = await getOrdersList(); if (data.list && data.list.length > 0) { const detailedServices = await Promise.all(data.list.map(async (order) => { let hDetails = null; if (order.status === 'active' && (order.plugin === 'hosting' || (order.title || '').toLowerCase().includes('vps'))) { try { hDetails = await getOrderDetails(order.id); } catch (e) {} } return { ...order, hostingDetails: hDetails }; })); const filteredServices = detailedServices.filter(s => { const type = (s.type || '').toLowerCase(); const title = (s.title || '').toLowerCase(); const isGhostProduct = type === 'domain' || title.includes('domain') || title.includes('domaine') || title.includes('enregistrement'); return (s.status === 'active' || s.status === 'pending_setup') && !isGhostProduct; }); setServices(filteredServices); } } catch (err) { setError(err.message || "Impossible de charger la télémétrie."); } finally { setIsLoading(false); } }, []); useEffect(() => { fetchServices(); }, [fetchServices]); const handleOpenConsole = async (service) => { const titleLower = (service.title || '').toLowerCase(); const isVPS = titleLower.includes('vps') || titleLower.includes('compute'); const isCloud = titleLower.includes('cloud') || titleLower.includes('nextcloud'); const isDB = titleLower.includes('db') || titleLower.includes('base') || titleLower.includes('sql'); const isWeb = !isVPS && !isCloud && !isDB; setIsConnecting(service.id); try { if (isCloud) { const titleMatch = (service.title || '').match(/(?: for | pour )(.+)$/i); const domainUrl = titleMatch ? titleMatch[1].trim() : service.domain; if (domainUrl) window.open(`https://${domainUrl}`, '_blank'); } else if (isDB) { window.open('https://pma.gise.be/', '_blank'); } else if (isVPS || isWeb) { const freshDetails = await getOrderDetails(service.id); setActiveServiceModal({ type: isVPS ? 'vps' : 'web', data: service, details: freshDetails }); } } catch (err) { triggerAlert("Erreur", err.message, "error"); } finally { setIsConnecting(null); } }; const assignedServiceIds = vpcs.flatMap(vpc => vpc.services); const freeServices = services.filter(s => !assignedServiceIds.includes(s.id)); return (
Orchestration des environnements et des Virtual Private Clouds.