b1987dc090
## Summary Adds Billing Limits to the webapp. Customers can set a monthly spend cap. When usage crosses the limit, billable environments enter a grace period. If the limit is not resolved before grace expires, new triggers are rejected until the organization increases or removes the limit.
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import type { BillingLimitResult } from "~/services/billingLimit.schemas";
|
|
|
|
export enum OrgBannerKind {
|
|
LimitRejected = "limit-rejected",
|
|
LimitGrace = "limit-grace",
|
|
NoLimitConfigured = "no-limit",
|
|
Upgrade = "upgrade",
|
|
EnvironmentWarning = "env-warning",
|
|
None = "none",
|
|
}
|
|
|
|
export function selectOrgBanner(input: {
|
|
billingLimit?: BillingLimitResult;
|
|
hasExceededFreeTier?: boolean;
|
|
showEnvironmentWarning?: boolean;
|
|
/** Self-serve billing UI — hide configure-limit prompt for managed customers. */
|
|
showSelfServe?: boolean;
|
|
}): OrgBannerKind {
|
|
const { billingLimit, hasExceededFreeTier, showEnvironmentWarning, showSelfServe = true } = input;
|
|
|
|
if (billingLimit?.isConfigured) {
|
|
const status = billingLimit.limitState.status;
|
|
if (status === "rejected") {
|
|
return OrgBannerKind.LimitRejected;
|
|
}
|
|
if (status === "grace") {
|
|
return OrgBannerKind.LimitGrace;
|
|
}
|
|
}
|
|
|
|
if (hasExceededFreeTier) {
|
|
return OrgBannerKind.Upgrade;
|
|
}
|
|
|
|
if (billingLimit && !billingLimit.isConfigured && showSelfServe) {
|
|
return OrgBannerKind.NoLimitConfigured;
|
|
}
|
|
|
|
if (showEnvironmentWarning) {
|
|
return OrgBannerKind.EnvironmentWarning;
|
|
}
|
|
|
|
return OrgBannerKind.None;
|
|
}
|