import React from 'react'; import { useNavigate } from 'react-router-dom'; import { useAppStateContext } from '../context/user.data.context'; const STATUS_BADGE_CLASS: Record = { active: 'bg-green-100 text-green-800', trialing: 'bg-green-100 text-green-800', cancelled: 'bg-red-100 text-red-800', canceled: 'bg-red-100 text-red-800', expired: 'bg-yellow-100 text-yellow-800', past_due: 'bg-yellow-100 text-yellow-800', pending: 'bg-blue-100 text-blue-800', }; const PlanStatusCard = (): JSX.Element | null => { const navigate = useNavigate(); const { user } = useAppStateContext(); if (!user) return null; const status = (user.stripe_subscription_status || '').toLowerCase(); const trialDaysLeft = user.trial_days || 0; const onTrial = !user.has_active_subscription && trialDaysLeft > 0; const planSnapshot = user.plan_snapshot ? String(user.plan_snapshot).replace(/_/g, ' ') : null; const planDisplay = planSnapshot ? planSnapshot : onTrial ? 'Hyper Scaling (Trial)' : 'None'; const badgeClass = STATUS_BADGE_CLASS[status] || 'bg-gray-100 text-gray-800'; const primaryCta = (() => { if (onTrial) { return { label: 'Activate Hyper Scaling', href: '/pricing?plan=HYPER_SCALING', }; } if (!user.has_active_subscription && trialDaysLeft === 0) { return { label: 'Choose a plan', href: '/pricing' }; } return null; })(); return (
Your Plan: {planDisplay} {status && ( {status.toUpperCase()} )} {onTrial && ( {`${trialDaysLeft} day${trialDaysLeft === 1 ? '' : 's'} left`} )}
{onTrial && (
)}
{primaryCta && ( )}
); }; export default PlanStatusCard;