import { HardDrive, Folder } from 'lucide-react'; import { useStorageUsage } from '@/hooks/useStorage'; /** * Props for the StorageUsageCard component. */ interface StorageUsageCardProps { /** Additional CSS classes to apply to the card container */ className?: string; } function formatBytes(bytes: number): string { if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`; } /** * Displays storage usage statistics in a card format. * Shows total bytes used, usage percentage with color-coded progress bar, * file count, max file size, and breakdown by folder. Handles loading * and error states gracefully. * * @description Renders a card showing storage quota usage and file statistics. * @param props - The component props * @param props.className - Additional CSS classes for the card container * * @example * // Basic usage * * * @example * // With custom styling * */ export function StorageUsageCard({ className = '' }: StorageUsageCardProps) { const { data, isLoading, error } = useStorageUsage(); if (isLoading) { return (
); } if (error || !data) { return (

Unable to load storage usage

); } const usedPercent = data.maxBytes ? data.usagePercent : 0; const progressColor = usedPercent > 90 ? 'bg-red-500' : usedPercent > 70 ? 'bg-yellow-500' : 'bg-blue-500'; return (

Storage Usage

{/* Usage stats */}
{formatBytes(data.totalBytes)} used {data.maxBytes && ( of {formatBytes(data.maxBytes)} )}
{data.maxBytes && (
)}
{/* Files count */}
Total files {data.totalFiles.toLocaleString()}
{/* Max file size */} {data.maxFileSize && (
Max file size {formatBytes(data.maxFileSize)}
)} {/* Files by folder */} {Object.keys(data.filesByFolder).length > 0 && (

By Folder

{Object.entries(data.filesByFolder).map(([folder, count]) => (
{folder}
{count}
))}
)}
); }