🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
as (#615)
Bill Yang954e9d151e79
diff --git a/client/src/app/settings/organization/subscription/page.tsx b/client/src/app/settings/organization/subscription/page.tsxindex e11e0ccf4..e37017ff1 100644--- a/client/src/app/settings/organization/subscription/page.tsx+++ b/client/src/app/settings/organization/subscription/page.tsx@@ -11,6 +11,7 @@ import { useSetPageTitle } from "../../../../hooks/useSetPageTitle";import { FreePlan } from "../../../../components/subscription/FreePlan";import { Building } from "lucide-react";import { authClient } from "@/lib/auth";+import { AppSumoPlan } from "../../../../components/subscription/AppSumoPlan";export default function OrganizationSubscriptionPage() {useSetPageTitle("Rybbit · Organization Subscription");@@ -63,6 +64,10 @@ export default function OrganizationSubscriptionPage() {return <TrialPlan />;}+ if (activeSubscription.appSumoPlan) {+ return <AppSumoPlan />;+ }+return <PaidPlan />;};diff --git a/client/src/components/subscription/AppSumoPlan.tsx b/client/src/components/subscription/AppSumoPlan.tsxnew file mode 100644index 000000000..8718583ae--- /dev/null+++ b/client/src/components/subscription/AppSumoPlan.tsx@@ -0,0 +1,94 @@+import { authClient } from "@/lib/auth";+import { AlertTriangle, ArrowRight } from "lucide-react";+import { DateTime } from "luxon";+import { useRouter } from "next/navigation";+import { DEFAULT_EVENT_LIMIT } from "../../lib/subscription/constants";+import { useStripeSubscription } from "../../lib/subscription/useStripeSubscription";+import { Alert, AlertDescription, AlertTitle } from "../ui/alert";+import { Button } from "../ui/button";+import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "../ui/card";+import { Progress } from "../ui/progress";+import { UsageChart } from "../UsageChart";++export function AppSumoPlan() {+ const { data: subscription } = useStripeSubscription();+ const { data: activeOrg } = authClient.useActiveOrganization();+ const router = useRouter();++ // Get the active organization ID+ const organizationId = activeOrg?.id;++ // Get last 30 days of data for the chart+ const endDate = DateTime.now().toISODate();+ const startDate = DateTime.now().minus({ days: 30 }).toISODate();++ if (!subscription) return null;++ const currentUsage = subscription?.monthlyEventCount || 0;+ const limit = subscription?.eventLimit || DEFAULT_EVENT_LIMIT;++ // Calculate percentage of limit used+ const percentageUsed = Math.min((currentUsage / limit) * 100, 100);+ const isNearLimit = percentageUsed > 80;+ const isLimitExceeded = currentUsage >= limit;++ return (+ <div className="space-y-6">+ <Card>+ <CardHeader>+ <CardTitle className="flex items-center">AppSumo Plan</CardTitle>+ <CardDescription>+ You are on the AppSumo lifetime plan with up to {subscription?.eventLimit.toLocaleString()} events per+ month.+ </CardDescription>+ </CardHeader>+ <CardContent>+ <div className="space-y-6">+ {isLimitExceeded ? (+ <Alert className="bg-red-50 dark:bg-red-900/20 border-red-200 dark:border-red-800">+ <AlertTriangle className="h-4 w-4 text-red-500 dark:text-red-400" />+ <AlertTitle>Event Limit Exceeded</AlertTitle>+ <AlertDescription>+ You have exceeded your monthly event limit. Please upgrade to a Pro plan to continue collecting+ analytics.+ </AlertDescription>+ </Alert>+ ) : (+ isNearLimit && (+ <Alert className="bg-amber-50 dark:bg-amber-900/20 border-amber-200 dark:border-amber-800">+ <AlertTriangle className="h-4 w-4 text-amber-500 dark:text-amber-400" />+ <AlertTitle>Approaching Limit</AlertTitle>+ <AlertDescription>+ You are approaching your monthly event limit. Consider upgrading to a paid plan for higher limits.+ </AlertDescription>+ </Alert>+ )+ )}++ <div className="space-y-2">+ <h3 className="font-medium mb-2">Usage</h3>+ <div className="space-y-4">+ <div>+ <div className="flex justify-between mb-1">+ <span className="text-sm">Events</span>+ <span className="text-sm">+ {currentUsage.toLocaleString()} / {limit.toLocaleString()}+ </span>+ </div>+ <Progress value={percentageUsed} className={isNearLimit ? "bg-amber-100 dark:bg-amber-900" : ""} />+ </div>+ </div>+ </div>++ {organizationId && <UsageChart organizationId={organizationId} startDate={startDate} endDate={endDate} />}+ </div>+ </CardContent>+ <CardFooter>+ <Button onClick={() => router.push("/subscribe")} variant={"success"}>+ Upgrade To Pro <ArrowRight className="ml-2 h-4 w-4" />+ </Button>+ </CardFooter>+ </Card>+ </div>+ );+}diff --git a/client/src/lib/subscription/useStripeSubscription.ts b/client/src/lib/subscription/useStripeSubscription.tsindex 4279e8e5e..6cf81407d 100644--- a/client/src/lib/subscription/useStripeSubscription.ts+++ b/client/src/lib/subscription/useStripeSubscription.ts@@ -17,6 +17,7 @@ interface SubscriptionData {trialDaysRemaining?: number;message?: string; // For expired trial messageisPro?: boolean;+ appSumoPlan?: string;}export function useStripeSubscription() {diff --git a/server/src/api/stripe/getSubscription.ts b/server/src/api/stripe/getSubscription.tsindex 0f32948d1..1c4da24c3 100644--- a/server/src/api/stripe/getSubscription.ts+++ b/server/src/api/stripe/getSubscription.ts@@ -22,6 +22,7 @@ export async function getSubscriptionInner(organizationId: string) {stripeCustomerId: organization.stripeCustomerId,monthlyEventCount: organization.monthlyEventCount,createdAt: organization.createdAt,+ name: organization.name,}).from(organization).where(eq(organization.id, organizationId))@@ -33,6 +34,19 @@ export async function getSubscriptionInner(organizationId: string) {return null;}+ if (org.name.includes("AppSumo")) {+ return {+ id: null,+ planName: "free",+ status: "active",+ eventLimit: 1000000,+ currentPeriodEnd: getStartOfNextMonth(),+ currentPeriodStart: getStartOfMonth(),+ monthlyEventCount: org.monthlyEventCount || 0,+ appSumoPlan: "1m",+ };+ }+// Check if organization has an active Stripe subscriptionif (org.stripeCustomerId) {// 2. List active subscriptions for the customer from Stripediff --git a/server/src/services/usageService.ts b/server/src/services/usageService.tsindex c9cc7c71a..d08cb95c4 100644--- a/server/src/services/usageService.ts+++ b/server/src/services/usageService.ts@@ -73,10 +73,7 @@ class UsageService {}).from(member).innerJoin(user, eq(member.userId, user.id))- .where(and(- eq(member.organizationId, organizationId),- eq(member.role, "owner")- ));+ .where(and(eq(member.organizationId, organizationId), eq(member.role, "owner")));return owners.length > 0 ? owners[0].email : null;} catch (error) {@@ -116,6 +113,9 @@ class UsageService {if (orgData.name === "tomato 2" || orgData.name === "Zam") {return [Infinity, this.getStartOfMonth()];}+ if (orgData.name.includes("AppSumo")) {+ return [1000000, this.getStartOfMonth()];+ }if (!orgData.stripeCustomerId) {// No Stripe customer ID, use default limit and start of current monthreturn [DEFAULT_EVENT_LIMIT, this.getStartOfMonth()];@@ -300,15 +300,8 @@ class UsageService {// Send email to the owner if foundif (ownerEmail) {try {- await sendLimitExceededEmail(- ownerEmail,- orgData.name,- eventCount,- eventLimit- );- this.logger.info(- `Sent limit exceeded email to owner ${ownerEmail} for organization ${orgData.name}`- );+ await sendLimitExceededEmail(ownerEmail, orgData.name, eventCount, eventLimit);+ this.logger.info(`Sent limit exceeded email to owner ${ownerEmail} for organization ${orgData.name}`);} catch (error) {this.logger.error(error as Error,@@ -316,9 +309,7 @@ class UsageService {);}} else {- this.logger.warn(- `No owner found for organization ${orgData.name}, skipping limit exceeded email`- );+ this.logger.warn(`No owner found for organization ${orgData.name}, skipping limit exceeded email`);}}