2022-03-02 11:51:16 +00:00
|
|
|
import dayjs from "dayjs";
|
|
|
|
import relativeTime from "dayjs/plugin/relativeTime";
|
2022-04-12 11:22:26 +00:00
|
|
|
import prettyBytes from "pretty-bytes";
|
2022-03-02 11:51:16 +00:00
|
|
|
|
|
|
|
import { useUser } from "../../contexts/user";
|
2022-03-04 11:03:52 +00:00
|
|
|
import useActivePlan from "../../hooks/useActivePlan";
|
2022-03-04 12:53:56 +00:00
|
|
|
import { ContainerLoadingIndicator } from "../LoadingIndicator";
|
2022-03-02 11:51:16 +00:00
|
|
|
|
|
|
|
import LatestPayment from "./LatestPayment";
|
|
|
|
import SuggestedPlan from "./SuggestedPlan";
|
|
|
|
|
|
|
|
dayjs.extend(relativeTime);
|
|
|
|
|
|
|
|
const CurrentPlan = () => {
|
|
|
|
const { user, error: userError } = useUser();
|
2022-03-04 11:03:52 +00:00
|
|
|
const { plans, activePlan, error: plansError } = useActivePlan(user);
|
2022-03-02 11:51:16 +00:00
|
|
|
|
|
|
|
if (!user || !activePlan) {
|
2022-03-04 12:53:56 +00:00
|
|
|
return <ContainerLoadingIndicator />;
|
2022-03-02 11:51:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (userError || plansError) {
|
|
|
|
return (
|
|
|
|
<div className="flex text-palette-300 flex-col space-y-4 h-full justify-center items-center">
|
|
|
|
<p>An error occurred while loading this data.</p>
|
|
|
|
<p>We'll retry automatically.</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-04-12 11:22:26 +00:00
|
|
|
<div className="flex flex-col h-full">
|
2022-03-02 11:51:16 +00:00
|
|
|
<h4>{activePlan.name}</h4>
|
2022-04-12 11:22:26 +00:00
|
|
|
<div className="text-palette-400 justify-between flex flex-col grow">
|
|
|
|
{activePlan.price === 0 && activePlan.limits && (
|
2022-04-13 06:29:11 +00:00
|
|
|
<p>{prettyBytes(activePlan.limits.storageLimit, { binary: true })} without paying a dime! 🎉</p>
|
2022-04-12 11:22:26 +00:00
|
|
|
)}
|
2022-03-02 11:51:16 +00:00
|
|
|
{activePlan.price !== 0 &&
|
|
|
|
(user.subscriptionCancelAtPeriodEnd ? (
|
|
|
|
<p>Your subscription expires {dayjs(user.subscribedUntil).fromNow()}</p>
|
|
|
|
) : (
|
|
|
|
<p className="first-letter:uppercase">{dayjs(user.subscribedUntil).fromNow(true)} until the next payment</p>
|
|
|
|
))}
|
2022-04-12 11:22:59 +00:00
|
|
|
|
2022-04-12 11:22:26 +00:00
|
|
|
{user.subscriptionStatus && <LatestPayment user={user} />}
|
2022-03-02 11:51:16 +00:00
|
|
|
<SuggestedPlan plans={plans} activePlan={activePlan} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default CurrentPlan;
|