Skip to content

Commit 2030b30

Browse files
committed
fix: event limit indicator
1 parent c779010 commit 2030b30

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

apps/dashboard/components/analytics/event-limit-indicator.tsx

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
import { WarningIcon } from "@phosphor-icons/react";
44
import { useQuery } from "@tanstack/react-query";
5-
import { useRouter } from "next/navigation";
6-
import { Button } from "@/components/ui/button";
5+
import Link from "next/link";
6+
import { buttonVariants } from "@/components/ui/button";
77
import { orpc } from "@/lib/orpc";
88

99
export function EventLimitIndicator() {
10-
const router = useRouter();
1110
const { data } = useQuery({
1211
...orpc.organizations.getUsage.queryOptions(),
1312
});
@@ -18,12 +17,17 @@ export function EventLimitIndicator() {
1817

1918
const balance = data.balance ?? 0;
2019
const planLimit = data.includedUsage ?? 0;
20+
const overageAllowed = data.overageAllowed ?? false;
2121

2222
// Balance > Plan limit = Bonus credits, show remaining
2323
// Balance < Plan limit = Normal usage, balance is remaining
2424
// Balance < 0 = Overage
2525

2626
if (balance < 0) {
27+
// Don't show overage warning if user is allowed to have overage
28+
if (overageAllowed) {
29+
return null;
30+
}
2731
// Overage state
2832
const overage = Math.abs(balance);
2933
return (
@@ -40,14 +44,16 @@ export function EventLimitIndicator() {
4044
</div>
4145
</div>
4246
{data.canUserUpgrade ? (
43-
<Button
44-
className="h-6 px-2 text-xs"
45-
onClick={() => router.push("/billing?tab=plans")}
46-
size="sm"
47-
variant="ghost"
47+
<Link
48+
className={buttonVariants({
49+
variant: "ghost",
50+
size: "sm",
51+
className: "h-6 px-2 text-xs",
52+
})}
53+
href="/billing/plans"
4854
>
4955
Upgrade
50-
</Button>
56+
</Link>
5157
) : (
5258
<span className="text-muted-foreground text-xs">Contact owner</span>
5359
)}
@@ -86,14 +92,16 @@ export function EventLimitIndicator() {
8692
</div>
8793
</div>
8894
{data.canUserUpgrade ? (
89-
<Button
90-
className="h-6 px-2 text-xs"
91-
onClick={() => router.push("/billing?tab=plans")}
92-
size="sm"
93-
variant="ghost"
95+
<Link
96+
className={buttonVariants({
97+
variant: "ghost",
98+
size: "sm",
99+
className: "h-6 px-2 text-xs",
100+
})}
101+
href="/billing/plans"
94102
>
95103
Upgrade
96-
</Button>
104+
</Link>
97105
) : (
98106
<span className="text-muted-foreground text-xs">Contact owner</span>
99107
)}

packages/rpc/src/routers/organizations.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ export const organizationsRouter = {
260260
const unlimited = data.unlimited ?? false;
261261
const balance = data.balance ?? 0;
262262
const includedUsage = data.included_usage ?? 0;
263+
const overageAllowed = data.overage_allowed ?? false;
263264

264265
const remaining = unlimited ? null : Math.max(0, usageLimit - used);
265266

@@ -270,6 +271,7 @@ export const organizationsRouter = {
270271
balance,
271272
remaining,
272273
includedUsage,
274+
overageAllowed,
273275
isOrganizationUsage: Boolean(orgResult?.activeOrgId),
274276
canUserUpgrade:
275277
!orgResult?.activeOrgId || orgResult.ownerId === context.user.id,

0 commit comments

Comments
 (0)