Skip to content

Commit 186a139

Browse files
committed
fix(webapp): billing alert preview uses current limit instead of stale saved amount
After a customer raised their billing limit, the alert-threshold percentage preview kept calculating dollar amounts against the previous limit until they re-saved their alerts. This happened because the preview reused the alert record's snapshotted amount whenever saved percentage levels existed. The preview now returns the snapshot only when it still matches the current effective/plan limit, and otherwise falls back to the current effective limit, so the preview reflects the saved billing limit immediately. Adds a regression test covering the raised-limit scenario. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TywtuVBcXSNVTV6nJbgLk8
1 parent 11d8a05 commit 186a139

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: webapp
3+
type: fix
4+
---
5+
6+
Raising your billing limit now updates the alert threshold preview amounts right away, instead of showing figures based on the previous limit until you save your alerts again.

apps/webapp/app/components/billing/billingAlertsFormat.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,6 @@ export function getAlertPreviewLimitCents(
315315
planLimitCents: number
316316
): number {
317317
const amountCents = getSavedAlertAmountCents(alerts);
318-
if (amountCents > 0 && percentageAlertLevelsToUiThresholds(alerts.alertLevels).length > 0) {
319-
return amountCents;
320-
}
321318
if (percentageAlertAmountMatches(amountCents, effectiveLimitCents, planLimitCents)) {
322319
return amountCents;
323320
}

apps/webapp/test/billingAlertsFormat.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ describe("billingAlertsFormat", () => {
9090
).toBe(10_000);
9191
});
9292

93+
it("previews percentage alerts against the current limit after it is raised", () => {
94+
// Alerts were saved against an old $30 limit; the customer has since raised
95+
// it to $300. The preview should follow the current limit, not the snapshot.
96+
expect(
97+
getAlertPreviewLimitCents(
98+
{ amount: 30, emails: [], alertLevels: [0.75, 0.9] },
99+
30_000,
100+
10_000
101+
)
102+
).toBe(30_000);
103+
});
104+
93105
it("normalizes legacy API alerts with dollar amount field and whole percents", () => {
94106
expect(
95107
normalizeBillingAlertsFromApi(

0 commit comments

Comments
 (0)