import dayjs from "dayjs"; import relativeTime from "dayjs/plugin/relativeTime"; import { useUser } from "../../contexts/user"; import useSubscriptionPlans from "../../hooks/useSubscriptionPlans"; import LatestPayment from "./LatestPayment"; import SuggestedPlan from "./SuggestedPlan"; dayjs.extend(relativeTime); const CurrentPlan = () => { const { user, error: userError } = useUser(); const { activePlan, plans, error: plansError } = useSubscriptionPlans(user); if (!user || !activePlan) { return ( // TODO: a nicer loading indicator
Loading...
); } if (userError || plansError) { return (

An error occurred while loading this data.

We'll retry automatically.

); } return (

{activePlan.name}

{activePlan.price === 0 &&

100GB without paying a dime! 🎉

} {activePlan.price !== 0 && (user.subscriptionCancelAtPeriodEnd ? (

Your subscription expires {dayjs(user.subscribedUntil).fromNow()}

) : (

{dayjs(user.subscribedUntil).fromNow(true)} until the next payment

))}
); }; export default CurrentPlan;