🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Remove subscription API and update related components for improved clarity
Bill Yang00c76644f53f
diff --git a/client/src/api/admin/subscription.ts b/client/src/api/admin/subscription.tsdeleted file mode 100644index 9cfe0c44c..000000000--- a/client/src/api/admin/subscription.ts+++ /dev/null@@ -1,45 +0,0 @@-import { useQuery } from "@tanstack/react-query";-import { BACKEND_URL } from "../../lib/const";-import { authedFetchWithError } from "../utils";--export type Subscription = {- id: string;- status: "active" | "trialing" | "canceled" | "incomplete" | "past_due";- plan: string;- stripeCustomerId?: string;- stripeSubscriptionId?: string;- trialStart?: Date;- trialEnd?: string | null | Date;- createdAt?: Date;- updatedAt?: Date;- cancelAt?: string | null;- canceledAt?: Date | null;- periodStart?: Date | string;- periodEnd?: Date | string;- cancelAtPeriodEnd: boolean;- referenceId?: string;- limits?: {- events: number;- [key: string]: any;- };- seats?: number;- metadata?: Record<string, any>;-};--export type SubscriptionWithUsage = Subscription & {- monthlyEventCount: number;- overMonthlyLimit: boolean;- monthlyEventLimit: number;-};--export function useSubscriptionWithUsage() {- return useQuery<SubscriptionWithUsage>({- queryKey: ["subscriptionWithUsage"],- queryFn: async () => {- const res = await authedFetchWithError<SubscriptionWithUsage>(- `${BACKEND_URL}/user/subscription`- );- return res;- },- });-}diff --git a/client/src/app/settings/subscription/utils/useStripeSubscription.ts b/client/src/app/settings/subscription/utils/useStripeSubscription.tsindex 701893c2b..b9b4d9504 100644--- a/client/src/app/settings/subscription/utils/useStripeSubscription.ts+++ b/client/src/app/settings/subscription/utils/useStripeSubscription.ts@@ -4,7 +4,15 @@ import { BACKEND_URL } from "../../../../lib/const";interface SubscriptionData {id: string;planName: string;- status: string;+ status:+ | "incomplete"+ | "incomplete_expired"+ | "trialing"+ | "active"+ | "past_due"+ | "canceled"+ | "unpaid"+ | "paused";currentPeriodEnd: string;monthlyEventCount: number;eventLimit: number;diff --git a/client/src/app/subscribe/page.tsx b/client/src/app/subscribe/page.tsxindex 90ca45b40..844336872 100644--- a/client/src/app/subscribe/page.tsx+++ b/client/src/app/subscribe/page.tsx@@ -8,6 +8,8 @@ import { useState } from "react";import { toast } from "sonner";import { StandardPage } from "../../components/StandardPage";import { BACKEND_URL } from "../../lib/const";+import { useStripeSubscription } from "../settings/subscription/utils/useStripeSubscription";+import { useRouter } from "next/navigation";// Available event tiers for the sliderconst EVENT_TIERS = [@@ -132,10 +134,15 @@ export default function Subscribe() {}// Get pricing information- const proPricing = findPriceForTier(eventLimit, isAnnual ? "year" : "month");const monthlyPrice = findPriceForTier(eventLimit, "month")?.price || 0;const annualPrice = findPriceForTier(eventLimit, "year")?.price || 0;+ const { data: subscription } = useStripeSubscription();+ const router = useRouter();+ if (subscription?.status === "active") {+ router.push("/settings/subscription");+ }+return (<StandardPage><div className="container mx-auto py-12 px-4">@@ -292,8 +299,7 @@ export default function Subscribe() {<p className="text-neutral-300">We'll notify you when you're approaching your limit. You caneither upgrade to a higher plan or continue with your current- plan (events beyond the limit won't be tracked). Remember, an- event is either a pageview or a custom event you've defined.+ plan (events beyond the limit won't be tracked).</p></div></div>diff --git a/docs/src/app/pricing/page.jsx b/docs/src/app/pricing/page.jsxindex 3cb1d4a47..37c311fd6 100644--- a/docs/src/app/pricing/page.jsx+++ b/docs/src/app/pricing/page.jsx@@ -33,7 +33,7 @@ export default function Pricing() {<div className="bg-neutral-800/20 p-5 rounded-lg border border-neutral-700"><h4 className="font-medium mb-2">What happens if I go over my event limit?</h4><p className="text-neutral-300">- We'll notify you when you're approaching your limit. You can either upgrade to a higher plan or continue with your current plan (events beyond the limit won't be tracked). Remember, an event is either a pageview or a custom event you've defined.+ We'll notify you when you're approaching your limit. You can either upgrade to a higher plan or continue with your current plan (events beyond the limit won't be tracked).</p></div></div>