add rest of tier types

This commit is contained in:
miloschwartz
2026-02-09 17:52:28 -08:00
committed by Owen Schwartz
parent a4fc91e6e6
commit 2a10cb4e6d
3 changed files with 15 additions and 14 deletions

View File

@@ -13,12 +13,13 @@
import { build } from "@server/build"; import { build } from "@server/build";
import { db, customers, subscriptions } from "@server/db"; import { db, customers, subscriptions } from "@server/db";
import { Tier } from "@server/types/Tiers";
import { eq, and, ne } from "drizzle-orm"; import { eq, and, ne } from "drizzle-orm";
export async function getOrgTierData( export async function getOrgTierData(
orgId: string orgId: string
): Promise<{ tier: "tier1" | "tier2" | "tier3" | null; active: boolean }> { ): Promise<{ tier: Tier | null; active: boolean }> {
let tier: "tier1" | "tier2" | "tier3" | null = null; let tier: Tier | null = null;
let active = false; let active = false;
if (build !== "saas") { if (build !== "saas") {

View File

@@ -20,8 +20,9 @@ import {
getScaleFeaturePriceSet, getScaleFeaturePriceSet,
} from "@server/lib/billing/features"; } from "@server/lib/billing/features";
import Stripe from "stripe"; import Stripe from "stripe";
import { Tier } from "@server/types/Tiers";
export type SubscriptionType = "tier1" | "tier2" | "tier3" | "license"; export type SubscriptionType = Tier | "license";
export function getSubType(fullSubscription: Stripe.Response<Stripe.Subscription>): SubscriptionType | null { export function getSubType(fullSubscription: Stripe.Response<Stripe.Subscription>): SubscriptionType | null {
// Determine subscription type by checking subscription items // Determine subscription type by checking subscription items

View File

@@ -49,6 +49,8 @@ import {
} from "@server/routers/billing/types"; } from "@server/routers/billing/types";
import { useTranslations } from "use-intl"; import { useTranslations } from "use-intl";
import Link from "next/link"; import Link from "next/link";
import { Tier } from "@server/types/Tiers";
import { w } from "@faker-js/faker/dist/airline-DF6RqYmq";
// Plan tier definitions matching the mockup // Plan tier definitions matching the mockup
type PlanId = "free" | "homelab" | "team" | "business" | "enterprise"; type PlanId = "free" | "homelab" | "team" | "business" | "enterprise";
@@ -58,7 +60,7 @@ interface PlanOption {
name: string; name: string;
price: string; price: string;
priceDetail?: string; priceDetail?: string;
tierType: "tier1" | "tier2" | "tier3" | null; // Maps to backend tier types tierType: Tier | null;
} }
// Tier limits for display in confirmation dialog // Tier limits for display in confirmation dialog
@@ -69,7 +71,7 @@ interface TierLimits {
remoteNodes: number; remoteNodes: number;
} }
const tierLimits: Record<"tier1" | "tier2" | "tier3", TierLimits> = { const tierLimits: Record<Tier, TierLimits> = {
tier1: { tier1: {
sites: 3, sites: 3,
users: 3, users: 3,
@@ -155,7 +157,7 @@ export default function BillingPage() {
const [hasSubscription, setHasSubscription] = useState(false); const [hasSubscription, setHasSubscription] = useState(false);
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [currentTier, setCurrentTier] = useState< const [currentTier, setCurrentTier] = useState<
"tier1" | "tier2" | "tier3" | null Tier | null
>(null); >(null);
// Usage IDs // Usage IDs
@@ -167,7 +169,7 @@ export default function BillingPage() {
// Confirmation dialog state // Confirmation dialog state
const [showConfirmDialog, setShowConfirmDialog] = useState(false); const [showConfirmDialog, setShowConfirmDialog] = useState(false);
const [pendingTier, setPendingTier] = useState<{ const [pendingTier, setPendingTier] = useState<{
tier: "tier1" | "tier2" | "tier3"; tier: Tier,
action: "upgrade" | "downgrade"; action: "upgrade" | "downgrade";
planName: string; planName: string;
price: string; price: string;
@@ -194,10 +196,7 @@ export default function BillingPage() {
if (tierSub?.subscription) { if (tierSub?.subscription) {
setCurrentTier( setCurrentTier(
tierSub.subscription.type as tierSub.subscription.type as Tier
| "tier1"
| "tier2"
| "tier3"
); );
setHasSubscription( setHasSubscription(
tierSub.subscription.status === "active" tierSub.subscription.status === "active"
@@ -243,7 +242,7 @@ export default function BillingPage() {
}, [org.org.orgId]); }, [org.org.orgId]);
const handleStartSubscription = async ( const handleStartSubscription = async (
tier: "tier1" | "tier2" | "tier3" tier: Tier
) => { ) => {
setIsLoading(true); setIsLoading(true);
try { try {
@@ -300,7 +299,7 @@ export default function BillingPage() {
} }
}; };
const handleChangeTier = async (tier: "tier1" | "tier2" | "tier3") => { const handleChangeTier = async (tier: Tier) => {
if (!hasSubscription) { if (!hasSubscription) {
// If no subscription, start a new one // If no subscription, start a new one
handleStartSubscription(tier); handleStartSubscription(tier);
@@ -343,7 +342,7 @@ export default function BillingPage() {
}; };
const showTierConfirmation = ( const showTierConfirmation = (
tier: "tier1" | "tier2" | "tier3", tier: Tier,
action: "upgrade" | "downgrade", action: "upgrade" | "downgrade",
planName: string, planName: string,
price: string price: string