Skip to content

Commit

Permalink
Don't show current plan if expired
Browse files Browse the repository at this point in the history
  • Loading branch information
elie222 committed Jan 5, 2025
1 parent 6218ee6 commit 0e98ae1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions apps/web/app/(app)/premium/Pricing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { LoadingContent } from "@/components/LoadingContent";
import { usePremium } from "@/components/PremiumAlert";
import { Button } from "@/components/Button";
import { Button as ShadcnButton } from "@/components/ui/button";
import { getUserTier } from "@/utils/premium";
import { getUserTier, isPremiumExpired } from "@/utils/premium";
import {
frequencies,
pricingAdditonalEmail,
Expand Down Expand Up @@ -57,6 +57,7 @@ export function Pricing(props: { header?: React.ReactNode }) {

const affiliateCode = useAffiliateCode();
const premiumTier = getUserTier(data?.premium);
const isExpired = isPremiumExpired(data?.premium);

const header = props.header || (
<div className="mb-12">
Expand Down Expand Up @@ -174,7 +175,8 @@ export function Pricing(props: { header?: React.ReactNode }) {

<Layout className="isolate mx-auto mt-10 grid max-w-md grid-cols-1 gap-y-8">
{tiers.map((tier, tierIdx) => {
const isCurrentPlan = tier.tiers[frequency.value] === premiumTier;
const isCurrentPlan =
!isExpired && tier.tiers[frequency.value] === premiumTier;

const user = session.data?.user;

Expand Down
8 changes: 8 additions & 0 deletions apps/web/utils/premium/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ export const getUserTier = (
return premium?.tier || getUserPlan(premium?.lemonSqueezyRenewsAt);
};

export const isPremiumExpired = (
premium?: Pick<Premium, "lemonSqueezyRenewsAt"> | null,
) => {
return (
!!premium?.lemonSqueezyRenewsAt && premium.lemonSqueezyRenewsAt < new Date()
);
};

export const isAdminForPremium = (
premiumAdmins: { id: string }[],
userId?: string,
Expand Down

1 comment on commit 0e98ae1

@vercel
Copy link

@vercel vercel bot commented on 0e98ae1 Jan 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.