Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable the free tier and only have the paid tiers #34

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions app/(dashboard)/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Link from "next/link"
import { redirect } from "next/navigation"

import { getApiKeys } from "@/lib/app/api-key"
Expand All @@ -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"

Expand All @@ -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 (
<section className="w-full py-2 sm:p-10">
Expand All @@ -38,10 +47,24 @@ export default async function PageDashboardApiKeys() {
<IsSignedIn>
<Card className="w-full p-6">
<CardContent>
<DashboardGenerateAPIkeysDialog
user={user}
apiKeysCount={apiKeys.length}
/>
{hasActiveSubscription ? (
<DashboardGenerateAPIkeysDialog
user={user}
apiKeysCount={apiKeys.length}
/>
) : (
<div className="flex flex-col items-center justify-center space-y-4 p-6 text-center">
<h3 className="text-lg font-semibold">Subscription Required</h3>
<p className="text-muted-foreground">
You need an active subscription to generate API keys.
</p>
<Button asChild>
<Link href="/dashboard/subscription">
View Subscription Plans
</Link>
</Button>
</div>
)}
</CardContent>

<DashboardTableAPIKeys apiKeys={apiKeys} />
Expand Down
4 changes: 2 additions & 2 deletions app/api/pricing/tiers/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export async function getTiers() {
return acc
}, [])

return { tiers: [...paidTiers] }
return { tiers: paidTiers }
}

export async function GET() {
Expand All @@ -75,4 +75,4 @@ export async function GET() {
{ status: 500 }
)
}
}
}
70 changes: 0 additions & 70 deletions components/app/dashboard-free-tier-card.tsx

This file was deleted.

11 changes: 8 additions & 3 deletions components/app/pricing-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export function PricingClient({ initialData }: PricingClientProps) {
return <PricingLoading />
}

const paidTiers = initialData.tiers.filter(
(tier) => tier.id !== "tier-free-plan"
)
console.log(paidTiers)

return (
<section className="md:py-17 container grid items-center gap-10 pb-8 pt-10 duration-500 animate-in fade-in-50">
<div className="mx-auto flex max-w-[58rem] flex-col items-center justify-center gap-4 text-center">
Expand All @@ -51,15 +56,15 @@ export function PricingClient({ initialData }: PricingClientProps) {
onFrequencyChange={setFrequency}
/>

<div className="isolate mx-auto grid max-w-md grid-cols-1 gap-8 lg:mx-0 lg:max-w-none lg:grid-cols-4">
{initialData.tiers.map((tier) => (
<div className="isolate mx-auto grid max-w-md grid-cols-1 gap-8 lg:mx-0 lg:max-w-none lg:grid-cols-3">
{paidTiers.map((tier) => (
<div
key={tier.id}
className={cn(
tier.featured
? "bg-secondary-foreground ring-secondary-foreground"
: "ring-secondary",
"rounded-3xl p-8 ring-1 xl:p-10"
"rounded-3xl p-8 ring-1 xl:m-5 xl:p-10"
)}
>
<h3
Expand Down
2 changes: 0 additions & 2 deletions components/app/subscription-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { useToast } from "@/lib/hooks/use-toast"
import { useUser } from "@/lib/hooks/use-user"

import { AppPricingRadio } from "@/components/app/app-pricing-radio"
import { FreeTierCard } from "@/components/app/dashboard-free-tier-card"
import { PricingCard } from "@/components/app/dashboard-pricing-card"
import { PricingLoading } from "@/components/app/pricing-loading"
import { SubscriptionActions } from "@/components/app/subscription-actions"
Expand Down Expand Up @@ -143,7 +142,6 @@ export function SubscriptionClient({ initialData }: SubscriptionClientProps) {
if (!subscription?.planId) {
return (
<Card className="container mt-4 grid items-center gap-5 rounded-3xl py-8">
<FreeTierCard />
<div className="mx-auto flex max-w-[58rem] flex-col items-center justify-center gap-4 text-center">
<h1 className="text-center text-3xl font-bold leading-tight text-primary sm:text-4xl md:text-5xl lg:text-6xl">
Choose Your Plan
Expand Down
13 changes: 10 additions & 3 deletions lib/app/user-profile.ts
Original file line number Diff line number Diff line change
@@ -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<SessionData>(
Expand All @@ -27,7 +28,7 @@ export async function updateUser(
})
}

export async function getUser(userId: string): Promise<User> {
export async function getUser(userId: string): Promise<User & { subscriptions?: Subscription[] }> {
const user = await prisma.user.findUnique({
where: {
id: userId,
Expand All @@ -36,8 +37,14 @@ export async function getUser(userId: string): Promise<User> {
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<User, 'createdAt' | 'updatedAt'>): Promise<User> {
return await prisma.user.create({
data,
Expand Down
1 change: 0 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ model User {
organizationSlug String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
lemonSqueezyCustomerId String? @unique
AddressLabel AddressLabel[]
apiKeys ApiKey[]
subscriptions Subscription[]
Expand Down