Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: Add isUserOnProPlan check

Richie McIlroy19ec08bd64ab
diff --git a/apps/web/app/api/settings/billing/subscribe/route.ts b/apps/web/app/api/settings/billing/subscribe/route.ts
index e784eb96c..a47975938 100644
--- a/apps/web/app/api/settings/billing/subscribe/route.ts
+++ b/apps/web/app/api/settings/billing/subscribe/route.ts
@@ -1,4 +1,4 @@
-import { stripe } from "@cap/utils";
+import { isUserOnProPlan, stripe } from "@cap/utils";
import { getCurrentUser } from "@cap/database/auth/session";
import { NextRequest } from "next/server";
import { eq } from "drizzle-orm";
@@ -32,6 +32,19 @@ export async function POST(request: NextRequest) {
});
}
+ if (
+ isUserOnProPlan({
+ subscriptionStatus: user.stripeSubscriptionStatus as string,
+ })
+ ) {
+ return new Response(JSON.stringify({ error: true, subscription: true }), {
+ status: 400,
+ headers: {
+ "Content-Type": "application/json",
+ },
+ });
+ }
+
if (!user.stripeCustomerId) {
const customer = await stripe.customers.create({
email: user.email,
diff --git a/apps/web/app/dashboard/_components/DynamicSharedLayout.tsx b/apps/web/app/dashboard/_components/DynamicSharedLayout.tsx
index 4d3ee9601..c290971ec 100644
--- a/apps/web/app/dashboard/_components/DynamicSharedLayout.tsx
+++ b/apps/web/app/dashboard/_components/DynamicSharedLayout.tsx
@@ -14,6 +14,7 @@ import {
import { users, spaces } from "@cap/database/schema";
import Link from "next/link";
+import { isUserOnProPlan } from "@cap/utils";
type SharedContext = {
spaceData: (typeof spaces.$inferSelect)[] | null;
@@ -40,7 +41,23 @@ export default function DynamicSharedLayout({
<AdminDesktopNav />
<div className="flex-1 overflow-auto focus:outline-none">
<AdminMobileNav />
- <div className="py-3 -mb-3 flex justify-end wrapper">
+ <div className="py-3 -mb-3 flex items-center justify-end wrapper space-x-3">
+ <div>
+ {isUserOnProPlan({
+ subscriptionStatus: user?.stripeSubscriptionStatus as string,
+ }) ? (
+ <Link
+ className="text-primary font-medium"
+ href="/dashboard/settings/billing"
+ >
+ Cap Pro
+ </Link>
+ ) : (
+ <Link className="text-primary font-medium" href="/pricing">
+ Upgrade to Cap Pro
+ </Link>
+ )}
+ </div>
<DropdownMenu>
<DropdownMenuTrigger
asChild
diff --git a/apps/web/components/pages/PricingPage.tsx b/apps/web/components/pages/PricingPage.tsx
index 59f274c95..8c0b47965 100644
--- a/apps/web/components/pages/PricingPage.tsx
+++ b/apps/web/components/pages/PricingPage.tsx
@@ -13,6 +13,7 @@ import {
import { Check, Construction } from "lucide-react";
import { useState } from "react";
import { getProPlanId } from "@cap/utils";
+import toast from "react-hot-toast";
export const PricingPage = () => {
const [loading, setLoading] = useState(false);
@@ -32,7 +33,11 @@ export const PricingPage = () => {
});
const data = await response.json();
- console.log("Response: ", data);
+ console.log(data);
+
+ if (data.subscription === true) {
+ toast.success("You are already on the Cap Pro plan");
+ }
if (data.url) {
window.location.href = data.url;
diff --git a/packages/utils/src/constants/plans.ts b/packages/utils/src/constants/plans.ts
index be211bf48..26fece6c1 100644
--- a/packages/utils/src/constants/plans.ts
+++ b/packages/utils/src/constants/plans.ts
@@ -7,3 +7,20 @@ export const getProPlanId = () => {
return "";
}
};
+
+export const isUserOnProPlan = ({
+ subscriptionStatus,
+}: {
+ subscriptionStatus: string;
+}) => {
+ if (
+ subscriptionStatus === "active" ||
+ subscriptionStatus === "trialing" ||
+ subscriptionStatus === "complete" ||
+ subscriptionStatus === "paid"
+ ) {
+ return true;
+ } else {
+ return false;
+ }
+};