diff --git a/src/App.jsx b/src/App.jsx
index e891607..5ba0454 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -17,7 +17,8 @@ import Home from './pages/public/Home';
// Import des Pages Privées (Espace Client)
import Dashboard from './pages/app/Dashboard';
import Store from './pages/app/Store';
-//import Services from './pages/app/Services';
+import Checkout from './pages/app/Checkout';
+import Services from './pages/app/Services';
export default function App() {
return (
@@ -44,7 +45,8 @@ export default function App() {
}>
} />
} />
- {/* } /> */}
+ } />
+ } />
diff --git a/src/pages/app/Checkout.jsx b/src/pages/app/Checkout.jsx
new file mode 100644
index 0000000..861a432
--- /dev/null
+++ b/src/pages/app/Checkout.jsx
@@ -0,0 +1,195 @@
+import { useState, useEffect } from 'react';
+import { useParams, useSearchParams, useNavigate } from 'react-router-dom';
+import { resetCart, addToCart, checkoutCart, getProductList, getClientProfile } from '../../services/api';
+
+export default function Checkout() {
+ const { productId } = useParams();
+ const [searchParams] = useSearchParams();
+ const period = searchParams.get('period');
+ const navigate = useNavigate();
+
+ const [product, setProduct] = useState(null);
+ const [userProfile, setUserProfile] = useState(null);
+ const [isLoading, setIsLoading] = useState(true);
+ const [isProcessing, setIsProcessing] = useState(false);
+ const [error, setError] = useState(null);
+
+ // Chargement asynchrone sécurisé
+ useEffect(() => {
+ const loadData = async () => {
+ try {
+ // 1. On charge d'abord le produit (Requête Publique)
+ const productData = await getProductList();
+ const foundProduct = productData.list?.find(p => p.id === parseInt(productId));
+
+ if (!foundProduct) {
+ setError("Le produit demandé n'existe pas dans le catalogue.");
+ setIsLoading(false);
+ return;
+ }
+ setProduct(foundProduct);
+
+ // 2. Ensuite, on tente de charger le profil (Requête Privée)
+ try {
+ const profileData = await getClientProfile();
+ setUserProfile(profileData);
+ } catch (profileErr) {
+ // Si on tombe ici, c'est que FOSSBilling refuse l'accès au profil.
+ console.error("Rejet API Profil :", profileErr);
+ setError("Accès refusé. Vous devez être connecté à votre compte pour provisionner une instance.");
+ // Tu pourras décommenter la ligne suivante plus tard pour forcer la redirection :
+ // navigate('/login');
+ setIsLoading(false);
+ return;
+ }
+
+ } catch (err) {
+ // Erreur serveur globale (FOSSBilling hors ligne)
+ console.error("Erreur Globale Serveur :", err);
+ setError(`Impossible de contacter le serveur de facturation : ${err.message}`);
+ } finally {
+ setIsLoading(false);
+ }
+ };
+ loadData();
+ }, [productId]);
+
+ // Outil de traduction des catégories FOSSBilling
+ // Vérifie que ces ID correspondent bien à ce que tu as dans ton FOSSBilling
+ const getCategoryTag = (categoryId) => {
+ const map = {
+ 1: 'web', // Hébergement Web
+ 4: 'vps', // Serveurs VPS
+ 2: 'db', // Base de données
+ 3: 'cloud' // Cloud Privé
+ };
+ return map[categoryId] || 'srv'; // 'srv' en solution de secours
+ };
+
+ // Exécution de la commande sur FOSSBilling
+ const handleConfirmOrder = async () => {
+ setIsProcessing(true);
+ setError(null);
+ try {
+ await resetCart();
+
+ // ⚙️ NOUVEL ALGORITHME D'ISOLATION UNITAIRE
+
+ // 1. Nettoyage strict du prénom (uniquement lettres et chiffres, pas de tirets)
+ let cleanName = 'user';
+ if (userProfile && userProfile.first_name) {
+ cleanName = userProfile.first_name
+ .toLowerCase()
+ .normalize("NFD").replace(/[\u0300-\u036f]/g, "") // Supprime les accents
+ .replace(/[^a-z0-9]/g, ""); // Supprime tout le reste (espaces, tirets, etc.)
+ }
+
+ // 2. Récupération du tag de catégorie (web, vps, db, cloud)
+ const catTag = getCategoryTag(product.product_category_id);
+
+ // 3. Génération d'une chaîne aléatoire alphanumérique de 4 caractères
+ const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
+ let randomHash = '';
+ for (let i = 0; i < 4; i++) {
+ randomHash += chars.charAt(Math.floor(Math.random() * chars.length));
+ }
+
+ // 4. Création du nom unique pour le domaine (ex: adam-web-b4m2)
+ const serverName = `${cleanName}-${catTag}-${randomHash}`;
+ const fullServerName = `${serverName}.gise.be`;
+
+ // ⚙️ STRUCTURE D'INJECTION POUR FOSSBILLING & HESTIACP
+ const productConfig = {
+ hostname: fullServerName,
+
+ domain: {
+ action: 'register',
+ register_sld: serverName, // Devient l'identifiant unique de la commande
+ register_tld: '.gise.be',
+ register_years: 1
+ }
+ };
+
+ await addToCart(productId, period, productConfig);
+ await checkoutCart();
+
+ navigate('/dashboard', {
+ state: { successMessage: `Instance initialisée sur ${serverName}.gise.be` }
+ });
+
+ } catch (err) {
+ setError(err.message || "La transaction a échoué. L'API a refusé le contrat.");
+ } finally {
+ setIsProcessing(false);
+ }
+ };
+
+ if (isLoading) {
+ return (
+
+
ANALYSE DU CONTRAT EN COURS...
+
+ );
+ }
+
+ return (
+
+
CONFIRMATION DE COMMANDE
+
+ {error && (
+
+ ERREUR: {error}
+
+ )}
+
+ {product && (
+
+
+
+ Instance sélectionnée
+ {product.title}
+
+
+
+ Cycle de facturation
+
+ {period === '1W' ? 'Hebdomadaire (7 jours)' : period === '1M' ? 'Mensuel (30 jours)' : 'Annuel (365 jours)'}
+
+
+
+
+ Total à régler immédiatement :
+
+ {product.pricing.recurrent[period]?.price} €
+
+
+
+
+
+ En validant cette commande, vous autorisez le Terminal Nexus à provisionner les ressources matérielles. Un domaine sécurisé .gise.be vous sera automatiquement attribué.
+
+
+
+ navigate('/store')}
+ disabled={isProcessing}
+ className="w-1/3 bg-transparent hover:bg-gray-800 text-gray-400 border border-gray-700 py-3 rounded-lg font-bold tracking-widest transition-colors"
+ >
+ ANNULER
+
+
+
+ {isProcessing ? 'PROVISIONNEMENT...' : 'INITIALISER L\'INSTANCE'}
+
+
+
+ )}
+
+ );
+}
\ No newline at end of file
diff --git a/src/pages/app/Dashboard.jsx b/src/pages/app/Dashboard.jsx
index e468094..19563f5 100644
--- a/src/pages/app/Dashboard.jsx
+++ b/src/pages/app/Dashboard.jsx
@@ -13,11 +13,31 @@ export default function Dashboard() {
useEffect(() => {
const fetchInventory = async () => {
try {
- // Appel à FOSSBilling via notre api.js
const data = await getClientOrders();
- // FOSSBilling renvoie souvent la liste dans data.list
- setOrders(data.list || []);
+ if (data.list) {
+ // LE FILTRE CHIRURGICAL PAR PREFIXE
+ const filteredOrders = data.list.filter(order => {
+ const title = (order.title || '').toLowerCase();
+ const type = (order.type || '').toLowerCase();
+
+ // On masque la commande SI :
+ // 1. Le type technique est "domain"
+ // 2. OU le titre COMMENCE par "domain", "domaine" ou "enregistrement"
+ const isGhostProduct =
+ type === 'domain' ||
+ title.startsWith('domain ') ||
+ title.startsWith('domaine ') ||
+ title.startsWith('enregistrement ');
+
+ // On retourne true (on affiche) uniquement si ce n'est pas un produit fantôme
+ return !isGhostProduct;
+ });
+
+ setOrders(filteredOrders);
+ } else {
+ setOrders([]);
+ }
} catch (err) {
setError(err.message || "Impossible de récupérer la télémétrie des services.");
} finally {
diff --git a/src/pages/app/Services.jsx b/src/pages/app/Services.jsx
index e69de29..beb095a 100644
--- a/src/pages/app/Services.jsx
+++ b/src/pages/app/Services.jsx
@@ -0,0 +1,293 @@
+import { useState, useEffect } from 'react';
+import { getMyServices, getServiceDetails, getHostingServiceDetails, resetHostingPassword, launchSSOGateway } from '../../services/api';
+import { useVPC } from '../../services/useVPC';
+import { Server, Database, Cloud, Globe, Folder, Trash2, ExternalLink, Loader, Plus } from 'lucide-react';
+
+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); // Pour le loader du bouton Auto-Login
+ const [ssoVault, setSsoVault] = useState(null);
+
+ // Branchement du moteur logique VPC
+ const { vpcs, createVPC, deleteVPC, assignToVPC, removeFromVPC } = useVPC();
+
+ // 1. Récupération et Filtrage des Infrastructures
+ useEffect(() => {
+ const fetchServices = async () => {
+ try {
+ const data = await getMyServices();
+
+ if (data.list && data.list.length > 0) {
+ // On récupère les mots de passe de chaque service pour le bouton Auto-Login
+ const detailedServices = await Promise.all(
+ data.list.map(async (order) => {
+ const details = await getServiceDetails(order.id);
+ return details;
+ })
+ );
+
+ // LE FILTRE CHIRURGICAL : On exclut les produits "Domaine" fantômes
+ const filteredServices = detailedServices.filter(s => {
+ const type = (s.type || '').toLowerCase();
+ const title = (s.title || '').toLowerCase();
+ const isGhostProduct =
+ type === 'domain' ||
+ title.startsWith('domain ') ||
+ title.startsWith('domaine ') ||
+ title.startsWith('enregistrement ');
+
+ // On garde les actifs/en préparation qui ne sont pas des domaines
+ return (s.status === 'active' || s.status === 'pending_setup') && !isGhostProduct;
+ });
+
+ setServices(filteredServices);
+ }
+ } catch (err) {
+ setError(err.message || "Impossible de charger la télémétrie des services.");
+ } finally {
+ setIsLoading(false);
+ }
+ };
+ fetchServices();
+ }, []);
+
+ // 2. Moteur de Connexion Furtive (SSO HestiaCP) avec contournement du bloqueur de pop-up
+ const handleAutoLogin = async (service) => {
+ setIsConnecting(service.id);
+
+ try {
+ // 1. Récupération de l'utilisateur
+ const hostingDetails = await getHostingServiceDetails(service.id);
+ const username = hostingDetails.username;
+ if (!username) throw new Error("Infrastructure non synchronisée avec le métal.");
+
+ // 2. Ghost Reset (Génération du mot de passe jetable)
+ const secureHash = Math.random().toString(36).slice(-8) + Math.random().toString(36).slice(-4).toUpperCase();
+ const rollingPassword = `Nx${secureHash}`;
+
+ console.log("Ghost Reset généré pour", username);
+ await resetHostingPassword(service.id, rollingPassword);
+
+ // 3. On affiche le Coffre-Fort à l'utilisateur
+ setSsoVault({
+ username: username,
+ password: rollingPassword,
+ url: 'https://panel.gise.be/login/'
+ });
+
+ } catch (err) {
+ alert("Échec du protocole d'accès : " + err.message);
+ } finally {
+ setIsConnecting(null);
+ }
+ };
+
+ // Utilitaires UI
+ const getServiceIcon = (title) => {
+ const t = (title || '').toLowerCase();
+ if (t.includes('vps') || t.includes('serveur')) return ;
+ if (t.includes('cloud') || t.includes('nextcloud')) return ;
+ if (t.includes('db') || t.includes('base') || t.includes('sql')) return ;
+ return ;
+ };
+
+ // Composant Interne : La Carte d'Instance
+ const InstanceCard = ({ service }) => (
+
+
+
+
+ {getServiceIcon(service.title)}
+
+ {service.status === 'active' ? (
+
ONLINE
+ ) : (
+
DEPLOYING
+ )}
+
+
+
{service.title}
+
{service.domain || `ID: #${service.id}`}
+
+
+
+ {/* Sélecteur VPC */}
+
+ Projet:
+ {
+ const val = e.target.value;
+ if (val === "free") removeFromVPC(service.id);
+ else if (val) assignToVPC(service.id, val);
+ }}
+ className="bg-black border border-gray-700 text-gray-300 rounded px-2 py-1 outline-none focus:border-cyan-400 text-xs w-[140px]"
+ defaultValue={vpcs.find(v => v.services.includes(service.id))?.id || "free"}
+ >
+ -- Libre --
+ {vpcs.map(vpc => (
+ {vpc.name}
+ ))}
+
+
+
+ {/* Bouton d'accès Auto-Login */}
+
handleAutoLogin(service)}
+ disabled={isConnecting === service.id || service.status !== 'active'}
+ className="w-full flex items-center justify-center space-x-2 bg-cyan-400/10 hover:bg-cyan-400 text-cyan-400 hover:text-gray-900 border border-cyan-400 py-2.5 rounded-lg font-bold text-sm tracking-wide transition-all disabled:opacity-50"
+ >
+ {isConnecting === service.id ? (
+ <>CONNEXION... >
+ ) : (
+ <>CONSOLE D'ADMINISTRATION >
+ )}
+
+
+
+ );
+
+ // Tri des instances (Libres vs Assignées)
+ const assignedServiceIds = vpcs.flatMap(vpc => vpc.services);
+ const freeServices = services.filter(s => !assignedServiceIds.includes(s.id));
+
+ if (isLoading) return ANALYSE DU RÉSEAU...
;
+
+ return (
+
+
+ {/* EN-TÊTE ET CRÉATION VPC */}
+
+
+
INVENTAIRE RÉSEAU
+
Orchestration des environnements et des Virtual Private Clouds.
+
+
+
+
setNewVpcName(e.target.value)}
+ className="bg-black border border-gray-800 rounded-lg px-4 py-2 text-sm text-white focus:outline-none focus:border-cyan-400 w-64"
+ />
+
{ createVPC(newVpcName); setNewVpcName(""); }}
+ disabled={!newVpcName.trim()}
+ className="bg-cyan-400 text-gray-900 px-4 py-2 rounded-lg font-bold text-sm disabled:opacity-50 hover:bg-cyan-300 flex items-center"
+ >
+ CRÉER GROUPE
+
+
+
+
+ {error &&
{error}
}
+
+ {/* LES VPC (Groupes de projets) */}
+
+ {vpcs.map(vpc => {
+ const vpcServices = services.filter(s => vpc.services.includes(s.id));
+
+ return (
+
+
+
+
+
{vpc.name.toUpperCase()}
+ {vpcServices.length} INSTANCES
+
+
deleteVPC(vpc.id)} className="text-gray-500 hover:text-red-400 transition-colors flex items-center text-sm">
+ Démanteler VPC
+
+
+
+
+ {vpcServices.length === 0 ? (
+
+ Réseau virtuel vide. Assigner des instances depuis le pool libre.
+
+ ) : (
+ vpcServices.map(service =>
)
+ )}
+
+
+ );
+ })}
+
+
+ {/* LE POOL LIBRE (Instances non groupées) */}
+
+
+ POOL D'INSTANCES LIBRES
+
+
+
+ {freeServices.length === 0 ? (
+
+ Aucune instance libre. Toutes vos accréditations sont assignées à des VPC.
+
+ ) : (
+ freeServices.map(service =>
)
+ )}
+
+
+ {/* MODAL DU COFFRE-FORT ÉPHÉMÈRE */}
+ {ssoVault && (
+
+
+
+
+
ACCÈS AUTORISÉ
+ setSsoVault(null)} className="text-gray-400 hover:text-white transition">
+ ✖
+
+
+
+
+ Le pare-feu HestiaCP bloque les injections de session directes. Un mot de passe de session jetable vient d'être généré sur le métal. Copiez-le et connectez-vous.
+
+
+
+
+
Utilisateur
+
+ {ssoVault.username}
+ navigator.clipboard.writeText(ssoVault.username)}
+ className="text-xs bg-gray-800 hover:bg-gray-700 text-white px-3 py-1 rounded transition"
+ >Copier
+
+
+
+
+
Clé Éphémère
+
+ {ssoVault.password}
+ navigator.clipboard.writeText(ssoVault.password)}
+ className="text-xs bg-cyan-600 hover:bg-cyan-500 text-white px-3 py-1 rounded transition shadow-lg shadow-cyan-500/30"
+ >Copier
+
+
+
+
+
+
+
+
+ )}
+
+ );
+}
\ No newline at end of file
diff --git a/src/pages/app/Store.jsx b/src/pages/app/Store.jsx
index 25b1da2..b58b2b9 100644
--- a/src/pages/app/Store.jsx
+++ b/src/pages/app/Store.jsx
@@ -178,7 +178,7 @@ const ProductCard = ({ product, selectedPeriod, categoryName }) => {
navigate(`/checkout/${product.id}`)}
+ onClick={() => navigate(`/checkout/${product.id}?period=${selectedPeriod}`)}
className={`w-full py-3 rounded-lg font-bold tracking-widest transition-all flex justify-center items-center space-x-2
${priceData.isAvailable
? "bg-cyan-400/10 hover:bg-cyan-400 text-cyan-400 hover:text-gray-900 border border-cyan-400 group-hover:shadow-[0_0_20px_rgba(34,211,238,0.2)]"
diff --git a/src/services/api.js b/src/services/api.js
index b0031fb..2e218a2 100644
--- a/src/services/api.js
+++ b/src/services/api.js
@@ -1,28 +1,67 @@
const BASE_URL = import.meta.env.VITE_API_BASE_URL || '';
const CUSTOM_API_BASE_URL = import.meta.env.VITE_CUSTOM_API_BASE_URL || '';
-const apiCall = async (url, body = null) => {
- // Configuration de base pour l'appel réseau
+// Le moteur de requête unifié et intelligent
+const apiCall = async (endpoint, param2 = 'GET', param3 = null) => {
+ let method = 'GET';
+ let body = null;
+
+ // DÉTECTION DE SIGNATURE (Le bouclier anti-crash)
+ if (typeof param2 === 'string') {
+ // Cas 1 : On a bien envoyé (URL, "POST", {données})
+ method = param2.toUpperCase();
+ body = param3;
+ } else if (typeof param2 === 'object' && param2 !== null) {
+ // Cas 2 : L'ancienne méthode a envoyé (URL, {données})
+ // On redirige l'objet vers le body, et on force en POST
+ body = param2;
+ method = (typeof param3 === 'string') ? param3.toUpperCase() : 'POST';
+ }
+
+ // 1. Récupération du sésame
+ const token = localStorage.getItem('token');
+
+ // 2. Préparation de l'enveloppe
+ const headers = {
+ 'Content-Type': 'application/json',
+ 'Accept': 'application/json'
+ };
+
+ if (token) {
+ headers['Authorization'] = `Bearer ${token}`;
+ }
+
+ // 3. Configuration finale garantie sans objets égarés
const options = {
- method: body ? 'POST' : 'GET', // Devient GET s'il n'y a pas de body (ex: getClientProfile)
- headers: {
- 'Content-Type': 'application/json',
- 'Accept': 'application/json',
- },
- credentials: 'include', // CRUCIAL : Maintient la session active avec FOSSBilling
+ method: method,
+ headers: headers,
+ credentials: 'include'
};
if (body) {
options.body = JSON.stringify(body);
}
- const response = await fetch(url, options);
- const data = await response.json();
-
- // Interception des erreurs de l'API FOSSBilling
- if (data.error) throw new Error(data.error.message);
-
- return data.result;
+ try {
+ const response = await fetch(endpoint, options);
+
+ if (response.status === 401 || response.status === 403) {
+ throw new Error("Accès refusé. Session expirée ou non valide.");
+ }
+
+ const data = await response.json();
+
+ // Gestion des erreurs internes de l'API
+ if (data.error) {
+ throw new Error(data.error.message || "Erreur renvoyée par le serveur de facturation.");
+ }
+
+ return data.result || data;
+
+ } catch (error) {
+ console.error(`[API FAIL] ${method} ${endpoint} :`, error);
+ throw error;
+ }
};
// ==========================================
@@ -32,9 +71,6 @@ const apiCall = async (url, body = null) => {
export const loginClient = (email, password) =>
apiCall(`${BASE_URL}/api/guest/client/login`, { email, password });
-export const getClientProfile = () =>
- apiCall(`${BASE_URL}/api/client/profile/get`);
-
// Récupère la liste des services/commandes du client
export const getClientOrders = () =>
apiCall(`${BASE_URL}/api/client/order/get_list`);
@@ -47,6 +83,39 @@ export const getOrderService = (order_id) =>
export const getProductList = () =>
apiCall(`${BASE_URL}/api/guest/product/get_list`);
+// Vide le panier (Action PUBLIQUE : on passe par l'API Guest)
+export const resetCart = async () => {
+ try {
+ // Changement : api/guest/ au lieu de api/client/
+ const cart = await apiCall(`${BASE_URL}/api/guest/cart/get`, 'GET');
+
+ if (cart && cart.items && cart.items.length > 0) {
+ for (const item of cart.items) {
+ // Changement : api/guest/
+ await apiCall(`${BASE_URL}/api/guest/cart/remove_item`, 'POST', { id: item.id });
+ }
+ }
+ } catch (err) {
+ console.warn("Nettoyage du panier ignoré :", err);
+ }
+};
+
+// Ajoute un produit au panier avec ses options étalées à la racine
+export const addToCart = (productId, period, additionalData = {}) =>
+ apiCall(`${BASE_URL}/api/guest/cart/add_item`, 'POST', {
+ id: productId,
+ period: period,
+ ...additionalData // Les 3 petits points "étalent" le contenu de l'objet
+ });
+
+// Valide le panier (Action PRIVÉE : on reste sur l'API Client pour générer la facture)
+export const checkoutCart = () =>
+ apiCall(`${BASE_URL}/api/client/cart/checkout`, 'POST');
+
+// Récupère les informations du client connecté
+export const getClientProfile = () =>
+ apiCall(`${BASE_URL}/api/client/profile/get`, 'GET');
+
// ==========================================
// ROUTES PERSONNALISÉES (CUSTOM API)
// ==========================================
@@ -65,7 +134,7 @@ export const registerUnifiedClient = async (email, username, password, firstName
last_name: lastName
})
});
-
+
const data = await response.json();
if (data.error) throw new Error(data.error.message);
return data.result;
@@ -73,4 +142,51 @@ export const registerUnifiedClient = async (email, username, password, firstName
console.error("Erreur lors de l'inscription unifiée :", err);
throw new Error("Échec de l'inscription. Veuillez réessayer plus tard.");
}
-}
\ No newline at end of file
+}
+
+// Récupère la liste de toutes les commandes actives du client
+export const getMyServices = () =>
+ apiCall(`${BASE_URL}/api/client/order/get_list`, 'GET');
+
+// Récupère les détails secrets d'un service (dont le mot de passe HestiaCP/VPS)
+export const getServiceDetails = (orderId) =>
+ apiCall(`${BASE_URL}/api/client/order/get`, 'POST', { id: orderId });
+
+// Récupère les secrets spécifiques du service physique attaché à une commande
+export const getHostingServiceDetails = (orderId) =>
+ apiCall(`${BASE_URL}/api/client/order/service`, 'POST', { id: orderId });
+
+// Force la réinitialisation du mot de passe sur le serveur distant (HestiaCP)
+export const resetHostingPassword = (orderId, newPassword) =>
+ apiCall(`${BASE_URL}/api/client/servicehosting/change_password`, 'POST', {
+ order_id: orderId,
+ password: newPassword,
+ password_confirm: newPassword
+ });
+
+// Déclenche le sas de connexion SSO via le navigateur (Ne pas utiliser apiCall ici)
+export const launchSSOGateway = (username, password) => {
+ const form = document.createElement('form');
+ form.method = 'POST';
+
+ // Tu peux utiliser ta BASE_URL si elle pointe vers web.gise.be
+ // Sinon, on garde l'URL absolue vers ton API personnalisée
+ form.action = `${CUSTOM_API_BASE_URL}/custom_api/sso.php`;
+ form.target = '_blank';
+
+ const userField = document.createElement('input');
+ userField.type = 'hidden';
+ userField.name = 'user';
+ userField.value = username;
+ form.appendChild(userField);
+
+ const passField = document.createElement('input');
+ passField.type = 'hidden';
+ passField.name = 'password';
+ passField.value = password;
+ form.appendChild(passField);
+
+ document.body.appendChild(form);
+ form.submit();
+ document.body.removeChild(form);
+};
\ No newline at end of file
diff --git a/src/services/useVPC.js b/src/services/useVPC.js
new file mode 100644
index 0000000..292d113
--- /dev/null
+++ b/src/services/useVPC.js
@@ -0,0 +1,56 @@
+import { useState, useEffect } from 'react';
+
+// Le moteur logique pour la gestion des groupes d'infrastructures
+export const useVPC = () => {
+ // 1. Initialisation : On cherche s'il y a déjà des VPC sauvegardés
+ const [vpcs, setVpcs] = useState(() => {
+ const saved = localStorage.getItem('nexus_vpcs');
+ return saved ? JSON.parse(saved) : [];
+ });
+
+ // 2. Sauvegarde automatique à chaque modification
+ useEffect(() => {
+ localStorage.setItem('nexus_vpcs', JSON.stringify(vpcs));
+ }, [vpcs]);
+
+ // 3. Créer un nouveau VPC
+ const createVPC = (name) => {
+ if (!name.trim()) return;
+ const newVpc = {
+ id: `vpc_${Date.now()}`,
+ name: name,
+ services: [] // Tableau qui contiendra les IDs des commandes (ex: [13, 14])
+ };
+ setVpcs([...vpcs, newVpc]);
+ };
+
+ // 4. Supprimer un VPC (Les services à l'intérieur ne sont pas supprimés, ils redeviennent "Libres")
+ const deleteVPC = (vpcId) => {
+ setVpcs(vpcs.filter(vpc => vpc.id !== vpcId));
+ };
+
+ // 5. Assigner un service à un VPC
+ const assignToVPC = (serviceId, targetVpcId) => {
+ setVpcs(vpcs.map(vpc => {
+ // On retire d'abord le service de tous les VPC pour éviter les doublons (1 service = 1 VPC max)
+ const cleanedServices = vpc.services.filter(id => id !== serviceId);
+
+ // Si c'est le VPC cible, on ajoute le service
+ if (vpc.id === targetVpcId) {
+ return { ...vpc, services: [...cleanedServices, serviceId] };
+ }
+ // Sinon on retourne le VPC nettoyé
+ return { ...vpc, services: cleanedServices };
+ }));
+ };
+
+ // 6. Retirer un service d'un VPC (Le rendre "Libre")
+ const removeFromVPC = (serviceId) => {
+ setVpcs(vpcs.map(vpc => ({
+ ...vpc,
+ services: vpc.services.filter(id => id !== serviceId)
+ })));
+ };
+
+ return { vpcs, createVPC, deleteVPC, assignToVPC, removeFromVPC };
+};
\ No newline at end of file