diff --git a/app/(dashboard)/dashboard/page.tsx b/app/(dashboard)/dashboard/page.tsx index a94141f2..6b11e142 100644 --- a/app/(dashboard)/dashboard/page.tsx +++ b/app/(dashboard)/dashboard/page.tsx @@ -1,3 +1,4 @@ +import Link from "next/link" import { redirect } from "next/navigation" import { getApiKeys } from "@/lib/app/api-key" @@ -6,6 +7,7 @@ import { getSession } from "@/lib/session" import { DashboardGenerateAPIkeysDialog } from "@/components/app/dashboard-generate-apikeys-dialog" import { DashboardTableAPIKeys } from "@/components/app/dashboard-table-apikeys" +import { Button } from "@/components/ui/button" import { Card, CardContent } from "@/components/ui/card" import { PageHeader } from "@/components/ui/page-header" @@ -21,6 +23,13 @@ export default async function PageDashboardApiKeys() { const apiKeys = await getApiKeys(session.user.id) const user = await getUser(session.user.id) + const hasActiveSubscription = user.subscriptions?.some( + (sub) => + sub.status === "active" && + !sub.isPaused && + (!sub.endsAt || new Date(sub.endsAt) > new Date()) && + sub.planId != 0 // Not free Tier + ) return (
@@ -38,10 +47,24 @@ export default async function PageDashboardApiKeys() { - + {hasActiveSubscription ? ( + + ) : ( +
+

Subscription Required

+

+ You need an active subscription to generate API keys. +

+ +
+ )}
diff --git a/app/api/pricing/tiers/route.ts b/app/api/pricing/tiers/route.ts index 73e63959..aa64d3df 100644 --- a/app/api/pricing/tiers/route.ts +++ b/app/api/pricing/tiers/route.ts @@ -61,7 +61,7 @@ export async function getTiers() { return acc }, []) - return { tiers: [...paidTiers] } + return { tiers: paidTiers } } export async function GET() { @@ -75,4 +75,4 @@ export async function GET() { { status: 500 } ) } -} \ No newline at end of file +} diff --git a/components/app/dashboard-free-tier-card.tsx b/components/app/dashboard-free-tier-card.tsx deleted file mode 100644 index 0b06cc99..00000000 --- a/components/app/dashboard-free-tier-card.tsx +++ /dev/null @@ -1,70 +0,0 @@ -"use client" - -import React, { useState } from "react" -import { AnimatePresence, motion } from "framer-motion" -import { ChevronDown } from "lucide-react" - -import { useTiers } from "@/lib/hooks/use-tiers" -import { cn } from "@/lib/utils" - -import { Icons } from "@/components/shared/icons" -import { Button } from "@/components/ui/button" -import { Card, CardContent } from "@/components/ui/card" - -export const FreeTierCard: React.FC = () => { - const [showFreeTierFeatures, setShowFreeTierFeatures] = useState(false) - const { data } = useTiers() - - const freeTier = data?.tiers.find((tier) => tier.id === "tier-free") - - if (!freeTier) { - return null - } - - return ( - - - - - {showFreeTierFeatures && ( - -
-

- These are the features available on the Free Tier. -

-
    - {freeTier.features.map((feature, index) => ( -
  • - - {feature} -
  • - ))} -
-
-
- )} -
-
-
- ) -} diff --git a/components/app/pricing-client.tsx b/components/app/pricing-client.tsx index 883e55b1..d9f778ed 100644 --- a/components/app/pricing-client.tsx +++ b/components/app/pricing-client.tsx @@ -34,6 +34,11 @@ export function PricingClient({ initialData }: PricingClientProps) { return } + const paidTiers = initialData.tiers.filter( + (tier) => tier.id !== "tier-free-plan" + ) + console.log(paidTiers) + return (
@@ -51,15 +56,15 @@ export function PricingClient({ initialData }: PricingClientProps) { onFrequencyChange={setFrequency} /> -
- {initialData.tiers.map((tier) => ( +
+ {paidTiers.map((tier) => (

-

Choose Your Plan diff --git a/lib/app/user-profile.ts b/lib/app/user-profile.ts index 85c3b833..34a5a68d 100644 --- a/lib/app/user-profile.ts +++ b/lib/app/user-profile.ts @@ -1,11 +1,12 @@ "use server" import { cookies } from "next/headers" -import { User } from "@prisma/client" +import { Subscription, User } from "@prisma/client" import { getIronSession } from "iron-session" import { prisma } from "@/lib/prisma" import { SERVER_SESSION_SETTINGS, SessionData } from "@/lib/session" +import { getCurrentSubscription } from "./actions" export async function Logout() { const session = await getIronSession( @@ -27,7 +28,7 @@ export async function updateUser( }) } -export async function getUser(userId: string): Promise { +export async function getUser(userId: string): Promise { const user = await prisma.user.findUnique({ where: { id: userId, @@ -36,8 +37,14 @@ export async function getUser(userId: string): Promise { if (!user) { throw new Error("User not found") } - return user + + const subscription = await getCurrentSubscription(userId) + return { + ...user, + subscriptions: subscription ? [subscription] : [] + } } + export async function createUser(data: Omit): Promise { return await prisma.user.create({ data, diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 9b7eba23..6ec1bd43 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -16,7 +16,6 @@ model User { organizationSlug String? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt - lemonSqueezyCustomerId String? @unique AddressLabel AddressLabel[] apiKeys ApiKey[] subscriptions Subscription[]