import { useState, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import { getOrdersList } from '../../services/billing_api'; import { AlertCircle, Loader, FileText, X } from 'lucide-react'; // Importation des composants import DashboardServiceCard from '../../components/dashboard/DashboardServiceCard'; import NewServiceCard from '../../components/dashboard/NewServiceCard'; import NotificationModal from '../../components/ui/NotificationModal'; import WebServiceSubscriptionManager from '../../components/dashboard/WebServiceSubscriptionManager'; export default function Dashboard() { const navigate = useNavigate(); const [orders, setOrders] = useState([]); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); const [activeSubscriptionModal, setActiveSubscriptionModal] = useState(null); const [customAlert, setCustomAlert] = useState(null); const triggerAlert = (title, message, type = "info") => setCustomAlert({ title, message, type }); const fetchInventory = async () => { setIsLoading(true); try { const data = await getOrdersList(); if (data.list) { // LE FILTRE CHIRURGICAL PAR PREFIXE const filteredOrders = data.list.filter(order => { const title = (order.title || '').toLowerCase(); const type = (order.type || '').toLowerCase(); const isGhostProduct = type === 'domain' || title.startsWith('domain ') || title.startsWith('domaine ') || title.startsWith('enregistrement '); return !isGhostProduct; }); setOrders(filteredOrders); } else { setOrders([]); } } catch (err) { setError(err.message || "Impossible de récupérer la télémétrie des services."); } finally { setIsLoading(false); } }; useEffect(() => { fetchInventory(); }, []); // 🌟 Plus besoin de charger les IPs, on ouvre juste la modale comptable ! const handleManageSubscription = (order) => { // 1. Détection du type de service const titleLower = (order.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'); // C'est un hébergement web s'il ne correspond à aucun des cas ci-dessus const isWeb = !isVPS && !isCloud && !isDB; // 2. Logique de blocage if (isWeb) { // On ouvre la modale comptable uniquement pour le WEB setActiveSubscriptionModal(order); } else { // On affiche une notification pour les autres types d'instances triggerAlert( "Action non disponible", "La modification autonome d'abonnement est actuellement exclusive aux Hébergements Web. Pour restructurer cette instance, veuillez contacter les ingénieurs via le Centre de Support.", "info" ); } }; return (

TABLEAU DE BORD

Gestion financière et accréditations de vos infrastructures.

{isLoading && (
Synchronisation avec le registre comptable...
)} {error && (
{error}
)} {!isLoading && !error && (
{orders.map((order) => ( handleManageSubscription(order)} /> ))} navigate('/store')} />
)} {/* 🌟 LA MODALE DE GESTION D'ABONNEMENT */} {activeSubscriptionModal && (

GESTION DE L'ABONNEMENT

setActiveSubscriptionModal(null)} onRefresh={fetchInventory} onAlert={triggerAlert} />
)} setCustomAlert(null)} />
); }