import React, { useState, useEffect } from "react"; import axios from "axios"; import { Link } from "react-router-dom"; import PlanCardSkeleton from "./PlanCardSkeleton"; import { useSubscription } from "../../hooks/useAuth"; const SubscriptionPlans = () => { const [plans, setPlans] = useState([]); const [frequency, setFrequency] = useState(1); const { data, isLoading, isError, error } = useSubscription(frequency); const [loading, setLoading] = useState(false); const [isOpen, setIsOpen] = useState(true); console.log(data); const frequencyLabel = (freq) => { switch (freq) { case 0: return "1 mo"; case 1: return "3 mo"; case 2: return "6 mo"; case 3: return "1 yr"; default: return "mo"; } }; return (
{/* Frequency Switcher */}
{["Monthly", "Quarterly", "Half-Yearly", "Yearly"].map( (label, idx) => ( ) )}
{/* Cards */}
{isLoading ? ( // Show 3 skeletons <> ) : data?.length === 0 ? (
No plans found
) : isError ? (

{error.message}

{error.name}

) : ( data.map((plan, index) => (
{/* Header */}

{plan.planName}

{plan.description}

{/* Price */}

{plan.currency?.symbol} {plan.price} / {frequencyLabel(frequency)}

{/* Storage & Trial */}
Storage {plan.maxStorage} MB
Trial Days {plan.trialDays}
{/* Features */}
Features
{plan.features?.modules && Object.entries(plan.features.modules) .sort(([, a], [, b]) => Number(b.enabled) - Number(a.enabled)) .map(([key, mod]) => { if (!mod || !mod.name) return null; const isFirst = index === 0; return (

{mod.features?.length > 0 ? (
    {mod.features.map((feat) => (
  • {feat.name}
  • ))}
) : (

No additional features

)}
); })}
{/* Button */}
Subscribe Request a Demo
)) )}
); }; export default SubscriptionPlans;