import React, { useState, useEffect } from 'react'; import { fetchOrganizationUsage } from '../api/organization'; import { useNotification } from '../context/NotificationContext'; import '../assets/organization-animations.css'; export default function Organization() { const [info, setInfo] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(''); const { showMessage } = useNotification(); // Estado para animar el progress bar const [animatedPercent, setAnimatedPercent] = useState(0); useEffect(() => { fetchOrganizationUsage() .then(data => { setInfo(data); setLoading(false); }) .catch(err => { console.error('Error fetching organization data:', err); setError('Error al cargar la información de la organización.'); setLoading(false); }); }, [showMessage]); // Animación del progress bar useEffect(() => { if (!info) return; const used = info.espacio_utilizado_gb || 0; const limit = info.limite_almacenamiento_gb || 1; const percent = Math.min(100, (100 * used / limit)); let start = 0; // Si ya está en el valor correcto, no animar if (animatedPercent === percent) return; // Animar de 0 a percent const step = () => { setAnimatedPercent(prev => { if (prev < percent) { const next = Math.min(prev + 2, percent); // velocidad de animación if (next < percent) { setTimeout(step, 10); } return next; } else { return percent; } }); }; setAnimatedPercent(0); setTimeout(step, 200); // pequeño delay para que se note la animación // eslint-disable-next-line }, [info]); if (loading) return (
Obteniendo datos de la organización...
{error}
Información y métricas de uso de tu organización