import React, {Suspense, useEffect, useState} from 'react'; import Card from "components/ui/card"; import {cn} from "lib/utils"; import PerformanceIcons from "app/page-optimizer/components/performance-widgets/PerformanceIcons"; import { CheckBadgeIcon, EyeIcon, EyeSlashIcon,InformationCircleIcon } from "@heroicons/react/24/outline"; import {Switch} from "components/ui/switch"; import {Label} from "components/ui/label"; import {Skeleton} from "components/ui/skeleton" import PerformanceProgressBar from "components/performance-progress-bar"; import {getSummary, saveGeneralSettings} from "../../../store/app/appActions"; import useCommonDispatch from "../../../hooks/useCommonDispatch"; import {useAppContext} from "../../../context/app"; import {useSelector} from "react-redux"; import {RootState} from "../../../store/app/appTypes"; import {optimizerData} from "../../../store/app/appSelector"; import { Tooltip } from 'components/ui/tooltip'; import TooltipText from 'components/ui/tooltip-text'; interface SectionHeaderProps { title: string; tooltip?: string; } interface UsageBarProps { label: string; usage?: number; allowedUsage?: number; note?: string; used_gb_formatted?: string; additional_usage_gb?: number; } const CDNSummary = ({className}: {className: string}) => { const {dispatch} = useCommonDispatch(); const {options} = useAppContext(); const {cdnUsage, imageUsage, cacheUsage, license} = useSelector(optimizerData); const [licenseInfo, setLicenseInfo] = useState(null); const [nextBillingDate, setNextBillingDate] = useState(''); useEffect(() => { const storedLicense = localStorage.getItem('rapidLoadLicense'); if (storedLicense) { try { setLicenseInfo(JSON.parse(storedLicense)); } catch (error) { console.error("Error parsing license data", error); } } else if(license) { setLicenseInfo(license); } const currentDate = new Date(); const nextMonth = new Date(currentDate); nextMonth.setMonth(currentDate.getMonth() + 1); if (licenseInfo?.next_billing) { const nextBilling = new Date(licenseInfo.next_billing * 1000); setNextBillingDate(nextMonth.toLocaleDateString('en-US', { month: 'short' }) + ' ' + nextBilling.getDate()); } }, [license, licenseInfo?.next_billing]); const SectionHeader = ({title, tooltip}: SectionHeaderProps) => (
{title}
); // const UsageBar = ({label, usage = 0, allowedUsage = 0, note, used_gb_formatted, additional_usage_gb}: UsageBarProps) => { // const progressWidth = allowedUsage ? `${(usage / allowedUsage) * 100}` : "0"; // return ( //
//
//
// {label} // { usage? usage < 1 ? usage.toFixed(2) : usage : '0'} GB / {allowedUsage ? allowedUsage : 30} GB //
//
// {note} //
//
//
//
//
//
// ); // }; const UsageBar = ({label, usage = 0, allowedUsage = 0, note, used_gb_formatted, additional_usage_gb = 0}: UsageBarProps) => { const totalUsage = usage; const progressWidth = allowedUsage ? `${Math.min((usage / allowedUsage) * 100, 100)}` : "0"; const allowedPercentage = allowedUsage ? Math.min((allowedUsage / totalUsage) * 100, 100) : 0; const additionalPercentage = totalUsage > allowedUsage ? Math.min(((totalUsage - allowedUsage) / totalUsage) * 100, 100) : 0; const finalprogressWidth = allowedPercentage - 100; return (
{label} {usage ? (usage < 1 ? usage.toFixed(2) : usage) : '0'} GB / {allowedUsage ? allowedUsage : 30} GB
{note}
{/* Allowed Usage Progress */}
0 ? 'rounded-r-none' : ''}`} style={{ width: `${progressWidth}%` }} >
{/* White Line at Additional Usage Start */} {additional_usage_gb > 0 && (
)} {/* Additional Usage Progress (Red) */} {additional_usage_gb > 0 && ( <>
)}
{additional_usage_gb > 0 && ( {additionalPercentage + 100}% of included limit )}
); }; useEffect(() => { dispatch(getSummary(options, 'get_rapidload_cdn_usage')); dispatch(getSummary(options, 'get_rapidload_image_usage')); // dispatch(getSummary(options, 'get_cache_file_size')); }, [dispatch]); // useEffect(() => { // cdnUsage && console.log('CDN Summary', cdnUsage) // imageUsage && console.log('Image Usage', imageUsage) // cacheUsage && console.log('Cache Usage', cacheUsage) // }, [cdnUsage, imageUsage, cacheUsage]); return (
{/* */}
{/* {imageUsage.additional_usage_gb > 0 && } */}
{/* */}
); }; export default CDNSummary;