Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

πŸ’„ Redesign billing plan cards and render billing settings on the server (#2685)

Luke Vellaa095c518b978
diff --git a/apps/web/biome.json b/apps/web/biome.json
index 5710cff6e..2d5482eff 100644
--- a/apps/web/biome.json
+++ b/apps/web/biome.json
@@ -269,7 +269,6 @@
"src/trpc/routers/user.ts",
"src/trpc/routers/polls/comments.ts",
"src/trpc/routers/polls/participants.ts",
- "src/features/billing/components/subscription-status-label.tsx",
"src/features/licensing/actions.ts",
"src/features/poll/components/desktop-poll/participant-row.tsx",
"src/features/poll/components/mobile-poll/poll-option.tsx",
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index 5ea9ab539..d7740144a 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -651,7 +651,10 @@
"ssoAuthenticationOnly": "Authentication is managed through Single Sign-On (SSO). Password management is not available.",
"startOfWeek": "Start of week",
"submit": "Submit",
- "subscriptionCancelOn": "Cancels {date}",
+ "subscriptionCardEndsOn": "Ends {date}",
+ "subscriptionCardPerMonth": "per month",
+ "subscriptionCardPerYear": "per year",
+ "subscriptionCardRenewsOn": "Renews {date}",
"subscriptionStatusActive": "Active",
"subscriptionStatusCanceled": "Canceled",
"subscriptionStatusIncomplete": "Incomplete",
@@ -659,7 +662,6 @@
"subscriptionStatusPastDue": "Past due",
"subscriptionStatusPaused": "Paused",
"subscriptionStatusTrialing": "Trialing",
- "subscriptionStatusUnknown": "Unknown",
"subscriptionStatusUnpaid": "Unpaid",
"support": "Support",
"supportDescription": "Need help with anything?",
diff --git a/apps/web/src/app/[locale]/(space)/settings/billing/components/billing-plan.tsx b/apps/web/src/app/[locale]/(space)/settings/billing/components/billing-plan.tsx
deleted file mode 100644
index 54fb6c2ab..000000000
--- a/apps/web/src/app/[locale]/(space)/settings/billing/components/billing-plan.tsx
+++ /dev/null
@@ -1,39 +0,0 @@
-"use client";
-
-import { Card } from "@rallly/ui/card";
-import type React from "react";
-import {
- SpaceTierIcon,
- SpaceTierLabel,
-} from "@/features/space/components/space-tier";
-import type { SpaceTier } from "@/features/space/schema";
-import { Trans } from "@/i18n/client";
-
-export function BillingPlan({
- tier,
- status,
- seats,
-}: {
- tier: SpaceTier;
- status?: React.ReactNode;
- seats: number;
-}) {
- return (
- <Card className="flex items-center gap-x-6 p-4">
- <SpaceTierIcon tier={tier} />
- <div className="flex-1">
- <div className="font-semibold text-sm">
- <SpaceTierLabel tier={tier} />
- </div>
- <p className="text-muted-foreground text-sm">{status}</p>
- </div>
- <div className="text-muted-foreground text-sm">
- <Trans
- i18nKey="seatCount"
- defaults="{count, plural, {one, # seat} {other, # seats}}"
- values={{ count: seats }}
- />
- </div>
- </Card>
- );
-}
diff --git a/apps/web/src/app/[locale]/(space)/settings/billing/components/contact-support-link.tsx b/apps/web/src/app/[locale]/(space)/settings/billing/components/contact-support-link.tsx
new file mode 100644
index 000000000..e85c8e910
--- /dev/null
+++ b/apps/web/src/app/[locale]/(space)/settings/billing/components/contact-support-link.tsx
@@ -0,0 +1,24 @@
+"use client";
+
+import { posthog } from "@rallly/posthog/client";
+import { buttonVariants } from "@rallly/ui";
+import { Icon } from "@rallly/ui/icon";
+import { SendIcon } from "lucide-react";
+import { Trans } from "@/i18n/client";
+
+export function ContactSupportLink() {
+ return (
+ <a
+ href="mailto:[email protected]"
+ className={buttonVariants()}
+ onClick={() => {
+ posthog?.capture("space_billing:support_button_click");
+ }}
+ >
+ <Icon>
+ <SendIcon />
+ </Icon>
+ <Trans i18nKey="contactSupport" defaults="Contact Support" />
+ </a>
+ );
+}
diff --git a/apps/web/src/app/[locale]/(space)/settings/billing/components/hobby-plan-card.tsx b/apps/web/src/app/[locale]/(space)/settings/billing/components/hobby-plan-card.tsx
new file mode 100644
index 000000000..655338db0
--- /dev/null
+++ b/apps/web/src/app/[locale]/(space)/settings/billing/components/hobby-plan-card.tsx
@@ -0,0 +1,56 @@
+"use client";
+
+import { posthog } from "@rallly/posthog/client";
+import { Button } from "@rallly/ui/button";
+import { showPayWall } from "@/features/billing/client";
+import { SpaceTierIcon } from "@/features/space/components/space-tier";
+import { Trans } from "@/i18n/client";
+import {
+ PlanCard,
+ PlanCardContent,
+ PlanCardDescription,
+ PlanCardFooter,
+ PlanCardHeader,
+ PlanCardIcon,
+ PlanCardPrice,
+ PlanCardPriceValue,
+ PlanCardTitle,
+} from "./plan-card";
+
+export function HobbyPlanCard({ className }: { className?: string }) {
+ return (
+ <PlanCard className={className}>
+ <PlanCardHeader>
+ <PlanCardIcon>
+ <SpaceTierIcon tier="hobby" />
+ </PlanCardIcon>
+ <PlanCardContent>
+ <PlanCardTitle>Hobby</PlanCardTitle>
+ <PlanCardDescription>
+ <Trans
+ i18nKey="seatCount"
+ defaults="{count, plural, one {# seat} other {# seats}}"
+ values={{ count: 1 }}
+ />
+ </PlanCardDescription>
+ </PlanCardContent>
+ <PlanCardPrice>
+ <PlanCardPriceValue>
+ <Trans i18nKey="priceFree" defaults="Free" />
+ </PlanCardPriceValue>
+ </PlanCardPrice>
+ </PlanCardHeader>
+ <PlanCardFooter>
+ <Button
+ variant="primary"
+ onClick={() => {
+ showPayWall();
+ posthog?.capture("space_billing:upgrade_button_click");
+ }}
+ >
+ <Trans i18nKey="upgradeToPro" defaults="Upgrade to Pro" />
+ </Button>
+ </PlanCardFooter>
+ </PlanCard>
+ );
+}
diff --git a/apps/web/src/app/[locale]/(space)/settings/billing/components/plan-card.tsx b/apps/web/src/app/[locale]/(space)/settings/billing/components/plan-card.tsx
new file mode 100644
index 000000000..5ad531953
--- /dev/null
+++ b/apps/web/src/app/[locale]/(space)/settings/billing/components/plan-card.tsx
@@ -0,0 +1,108 @@
+import { cn } from "@rallly/ui";
+import { Card } from "@rallly/ui/card";
+import type * as React from "react";
+
+export function PlanCard({ className, ...props }: React.ComponentProps<"div">) {
+ return <Card className={cn("@container", className)} {...props} />;
+}
+
+export function PlanCardHeader({
+ className,
+ ...props
+}: React.ComponentProps<"div">) {
+ return (
+ <div
+ className={cn(
+ "flex @sm:flex-row flex-col items-start @sm:items-center gap-3 p-3",
+ className,
+ )}
+ {...props}
+ />
+ );
+}
+
+export function PlanCardFooter({
+ className,
+ ...props
+}: React.ComponentProps<"div">) {
+ return (
+ <div
+ className={cn("border-card-border border-t p-3", className)}
+ {...props}
+ />
+ );
+}
+
+export function PlanCardIcon({
+ className,
+ ...props
+}: React.ComponentProps<"div">) {
+ return <div className={cn("shrink-0", className)} {...props} />;
+}
+
+export function PlanCardContent({
+ className,
+ ...props
+}: React.ComponentProps<"div">) {
+ return <div className={cn("min-w-0 flex-1", className)} {...props} />;
+}
+
+export function PlanCardTitle({
+ className,
+ ...props
+}: React.ComponentProps<"div">) {
+ return (
+ <div
+ className={cn(
+ "flex items-center gap-x-2 font-semibold text-sm",
+ className,
+ )}
+ {...props}
+ />
+ );
+}
+
+export function PlanCardDescription({
+ className,
+ ...props
+}: React.ComponentProps<"p">) {
+ return (
+ <p
+ className={cn("truncate text-muted-foreground text-sm", className)}
+ {...props}
+ />
+ );
+}
+
+export function PlanCardPrice({
+ className,
+ ...props
+}: React.ComponentProps<"div">) {
+ return (
+ <div
+ className={cn("@sm:mr-2 shrink-0 @sm:text-right", className)}
+ {...props}
+ />
+ );
+}
+
+export function PlanCardPriceValue({
+ className,
+ ...props
+}: React.ComponentProps<"div">) {
+ return (
+ <div
+ className={cn("font-semibold text-sm tabular-nums", className)}
+ {...props}
+ />
+ );
+}
+
+export function PlanCardPriceDescription({
+ className,
+ ...props
+}: React.ComponentProps<"p">) {
+ return (
+ <p className={cn("text-muted-foreground text-sm", className)} {...props} />
+ );
+}
diff --git a/apps/web/src/app/[locale]/(space)/settings/billing/components/pro-plan-card.tsx b/apps/web/src/app/[locale]/(space)/settings/billing/components/pro-plan-card.tsx
new file mode 100644
index 000000000..63cee88a5
--- /dev/null
+++ b/apps/web/src/app/[locale]/(space)/settings/billing/components/pro-plan-card.tsx
@@ -0,0 +1,149 @@
+"use client";
+
+import { posthog } from "@rallly/posthog/client";
+import { Button } from "@rallly/ui/button";
+import { DialogTrigger } from "@rallly/ui/dialog";
+import { Icon } from "@rallly/ui/icon";
+import { ArmchairIcon, CreditCardIcon, DotIcon } from "lucide-react";
+import { openCustomerPortalAction } from "@/features/billing/actions";
+import { SubscriptionStatusBadge } from "@/features/billing/components/subscription-status-badge";
+import type {
+ BillingInterval,
+ SubscriptionStatus,
+} from "@/features/billing/schema";
+import { SpaceTierIcon } from "@/features/space/components/space-tier";
+import { Trans } from "@/i18n/client";
+import { useDateTime, useDateTimeConfig } from "@/lib/datetime/client";
+import { useSafeAction } from "@/lib/safe-action/client";
+import { ManageSeatsDialog } from "./manage-seats-dialog";
+import {
+ PlanCard,
+ PlanCardContent,
+ PlanCardDescription,
+ PlanCardFooter,
+ PlanCardHeader,
+ PlanCardIcon,
+ PlanCardPrice,
+ PlanCardPriceDescription,
+ PlanCardPriceValue,
+ PlanCardTitle,
+} from "./plan-card";
+
+export function ProPlanCard({
+ amount,
+ currency,
+ interval,
+ seats,
+ usedSeats,
+ status,
+ cancelAtPeriodEnd,
+ periodEnd,
+ className,
+}: {
+ amount: number;
+ currency: string;
+ interval: BillingInterval;
+ seats: number;
+ usedSeats: number;
+ status: SubscriptionStatus;
+ cancelAtPeriodEnd: boolean;
+ periodEnd: Date;
+ className?: string;
+}) {
+ const { locale } = useDateTimeConfig();
+ const { formatDateTime } = useDateTime();
+ const openCustomerPortal = useSafeAction(openCustomerPortalAction);
+
+ // amount is the per-seat unit amount in the currency's minor unit
+ const price = new Intl.NumberFormat(locale, {
+ style: "currency",
+ currency: currency.toUpperCase(),
+ }).format((amount * seats) / 100);
+
+ const date = formatDateTime(periodEnd, "date");
+ const endsAtPeriodEnd = status === "canceled" || cancelAtPeriodEnd;
+
+ return (
+ <PlanCard className={className}>
+ <PlanCardHeader>
+ <PlanCardIcon>
+ <SpaceTierIcon tier="pro" />
+ </PlanCardIcon>
+ <PlanCardContent>
+ <div className="flex items-center gap-x-2">
+ <PlanCardTitle>Pro</PlanCardTitle>
+ <SubscriptionStatusBadge status={status} />
+ </div>
+ <PlanCardDescription className="flex items-center">
+ <Trans
+ i18nKey="seatCount"
+ defaults="{count, plural, one {# seat} other {# seats}}"
+ values={{ count: seats }}
+ />
+ <Icon>
+ <DotIcon />
+ </Icon>
+ {endsAtPeriodEnd ? (
+ <Trans
+ i18nKey="subscriptionCardEndsOn"
+ defaults="Ends {date}"
+ values={{ date }}
+ />
+ ) : (
+ <Trans
+ i18nKey="subscriptionCardRenewsOn"
+ defaults="Renews {date}"
+ values={{ date }}
+ />
+ )}
+ </PlanCardDescription>
+ </PlanCardContent>
+ <PlanCardPrice>
+ <PlanCardPriceValue>{price}</PlanCardPriceValue>
+ <PlanCardPriceDescription>
+ {interval === "month" ? (
+ <Trans i18nKey="subscriptionCardPerMonth" defaults="per month" />
+ ) : (
+ <Trans i18nKey="subscriptionCardPerYear" defaults="per year" />
+ )}
+ </PlanCardPriceDescription>
+ </PlanCardPrice>
+ </PlanCardHeader>
+ <PlanCardFooter>
+ <div className="flex gap-2">
+ <Button
+ loading={openCustomerPortal.isExecuting}
+ onClick={() => {
+ posthog?.capture("space_billing:billing_portal_button_click");
+ openCustomerPortal.execute({});
+ }}
+ >
+ <Icon>
+ <CreditCardIcon />
+ </Icon>
+ <Trans
+ i18nKey="manageSubscription"
+ defaults="Manage Subscription"
+ />
+ </Button>
+ <ManageSeatsDialog usedSeats={usedSeats} currentSeats={seats}>
+ <DialogTrigger
+ render={
+ <Button
+ onClick={() => {
+ posthog?.capture("space_billing:manage_seats_button_click");
+ }}
+ />
+ }
+ >
+ <Icon>
+ <ArmchairIcon />
+ </Icon>
+ <Trans i18nKey="manageSeats" defaults="Manage Seats" />
+ </DialogTrigger>
+ </ManageSeatsDialog>
+ </div>
+ </PlanCardFooter>
+ </PlanCard>
+ );
+}
diff --git a/apps/web/src/app/[locale]/(space)/settings/billing/page-client.tsx b/apps/web/src/app/[locale]/(space)/settings/billing/page-client.tsx
deleted file mode 100644
index cd7e907c2..000000000
--- a/apps/web/src/app/[locale]/(space)/settings/billing/page-client.tsx
+++ /dev/null
@@ -1,234 +0,0 @@
-"use client";
-
-import { posthog } from "@rallly/posthog/client";
-import { buttonVariants } from "@rallly/ui";
-import { Alert, AlertDescription, AlertTitle } from "@rallly/ui/alert";
-import { Button } from "@rallly/ui/button";
-import { DialogTrigger } from "@rallly/ui/dialog";
-import { Icon } from "@rallly/ui/icon";
-import {
- ArmchairIcon,
- CheckCircleIcon,
- CreditCardIcon,
- SendIcon,
- ShieldXIcon,
-} from "lucide-react";
-import { useSearchParams } from "next/navigation";
-import {
- EmptyState,
- EmptyStateDescription,
- EmptyStateIcon,
- EmptyStateTitle,
-} from "@/components/empty-state";
-import {
- PageSection,
- PageSectionContent,
- PageSectionDescription,
- PageSectionDivider,
- PageSectionGroup,
- PageSectionHeader,
- PageSectionTitle,
-} from "@/components/page-layout";
-import {
- SettingsPage,
- SettingsPageContent,
- SettingsPageDescription,
- SettingsPageHeader,
- SettingsPageTitle,
-} from "@/components/settings-layout";
-import { openCustomerPortalAction } from "@/features/billing/actions";
-import { showPayWall } from "@/features/billing/client";
-import { SubscriptionStatusLabel } from "@/features/billing/components/subscription-status-label";
-import { useSpace } from "@/features/space/client";
-import type { SpaceTier } from "@/features/space/schema";
-import { Trans } from "@/i18n/client";
-import { useSafeAction } from "@/lib/safe-action/client";
-import { trpc } from "@/trpc/client";
-import { BillingPlan } from "./components/billing-plan";
-import { ManageSeatsDialog } from "./components/manage-seats-dialog";
-
-export function BillingPageClient() {
- const { data: space, getMemberAbility } = useSpace();
- const ability = getMemberAbility();
- const canManageBilling = ability.can("manage", "Billing");
-
- if (!canManageBilling) {
- return (
- <EmptyState className="h-full">
- <EmptyStateIcon>
- <ShieldXIcon />
- </EmptyStateIcon>
- <EmptyStateTitle>
- <Trans i18nKey="accessDenied" defaults="Access Denied" />
- </EmptyStateTitle>
- <EmptyStateDescription>
- <Trans
- i18nKey="ownerPermissionsRequired"
- defaults="Only space owners can access billing settings."
- />
- </EmptyStateDescription>
- </EmptyState>
- );
- }
-
- return <BillingPageContent tier={space.tier} />;
-}
-
-function BillingPageContent({ tier }: { tier: SpaceTier }) {
- const searchParams = useSearchParams();
- const openCustomerPortal = useSafeAction(openCustomerPortalAction);
-
- const [subscription] = trpc.billing.getSubscription.useSuspenseQuery();
- const [seats] = trpc.spaces.getSeats.useSuspenseQuery();
-
- const didUpdateSeats = searchParams.has("seats_updated");
-
- return (
- <SettingsPage>
- <SettingsPageHeader>
- <SettingsPageTitle>
- <Trans i18nKey="billing" defaults="Billing" />
- </SettingsPageTitle>
- <SettingsPageDescription>
- <Trans
- i18nKey="billingDescription"
- defaults="Manage your billing information and subscription."
- />
- </SettingsPageDescription>
- </SettingsPageHeader>
- <SettingsPageContent>
- <PageSectionGroup>
- <PageSection>
- <PageSectionHeader>
- <PageSectionTitle>
- <Trans i18nKey="billingPlanTitle" defaults="Plan" />
- </PageSectionTitle>
- <PageSectionDescription>
- <Trans
- i18nKey="billingSubscriptionDescription"
- defaults="Manage your current subscription plan"
- />
- </PageSectionDescription>
- </PageSectionHeader>
- <PageSectionContent>
- <BillingPlan
- tier={tier}
- status={
- subscription ? (
- <SubscriptionStatusLabel
- status={subscription.status}
- cancelAtPeriodEnd={subscription.cancelAtPeriodEnd}
- periodEnd={subscription.periodEnd}
- />
- ) : (
- <Trans i18nKey="priceFree" />
- )
- }
- seats={seats.total}
- />
- <div>
- {subscription ? (
- <div className="flex justify-between gap-2">
- <Button
- loading={openCustomerPortal.isExecuting}
- onClick={() => {
- posthog?.capture(
- "space_billing:billing_portal_button_click",
- );
- openCustomerPortal.execute({});
- }}
- >
- <Icon>
- <CreditCardIcon />
- </Icon>
- <Trans
- i18nKey="manageSubscription"
- defaults="Manage Subscription"
- />
- </Button>
- <ManageSeatsDialog
- usedSeats={seats.used}
- currentSeats={seats.total}
- >
- <DialogTrigger
- render={
- <Button
- onClick={() => {
- posthog?.capture(
- "space_billing:manage_seats_button_click",
- );
- }}
- />
- }
- >
- <Icon>
- <ArmchairIcon />
- </Icon>
- <Trans i18nKey="manageSeats" defaults="Manage Seats" />
- </DialogTrigger>
- </ManageSeatsDialog>
- </div>
- ) : (
- <Button
- variant="primary"
- onClick={() => {
- showPayWall();
- posthog?.capture("space_billing:upgrade_button_click");
- }}
- >
- <Trans i18nKey="upgradeToPro" />
- </Button>
- )}
- </div>
- {didUpdateSeats ? (
- <Alert variant="success">
- <CheckCircleIcon />
- <AlertTitle>
- <Trans
- i18nKey="seatsUpdatedAlertTitle"
- defaults="Seats Updated"
- />
- </AlertTitle>
- <AlertDescription>
- <Trans
- i18nKey="seatsUpdatedAlertDescription"
- defaults="Your seat allocation has been successfully updated. The changes will be reflected in your next billing cycle."
- />
- </AlertDescription>
- </Alert>
- ) : null}
- </PageSectionContent>
- </PageSection>
- <PageSectionDivider />
- <PageSection>
- <PageSectionHeader>
- <PageSectionTitle>
- <Trans i18nKey="support" defaults="Support" />
- </PageSectionTitle>
- <PageSectionDescription>
- <Trans
- i18nKey="supportDescription"
- defaults="Need help with anything?"
- />
- </PageSectionDescription>
- </PageSectionHeader>
- <PageSectionContent>
- <a
- href="mailto:[email protected]"
- className={buttonVariants()}
- onClick={() => {
- posthog?.capture("space_billing:support_button_click");
- }}
- >
- <Icon>
- <SendIcon />
- </Icon>
- <Trans i18nKey="contactSupport" defaults="Contact Support" />
- </a>
- </PageSectionContent>
- </PageSection>
- </PageSectionGroup>
- </SettingsPageContent>
- </SettingsPage>
- );
-}
diff --git a/apps/web/src/app/[locale]/(space)/settings/billing/page.tsx b/apps/web/src/app/[locale]/(space)/settings/billing/page.tsx
index 641c4bc65..80b2fbf49 100644
--- a/apps/web/src/app/[locale]/(space)/settings/billing/page.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/billing/page.tsx
@@ -1,27 +1,188 @@
-import { dehydrate, HydrationBoundary } from "@tanstack/react-query";
+import { Alert, AlertDescription, AlertTitle } from "@rallly/ui/alert";
+import { CheckCircleIcon, ShieldXIcon } from "lucide-react";
import type { Metadata } from "next";
-import { notFound } from "next/navigation";
+import { notFound, redirect } from "next/navigation";
+import {
+ EmptyState,
+ EmptyStateDescription,
+ EmptyStateIcon,
+ EmptyStateTitle,
+} from "@/components/empty-state";
+import {
+ PageSection,
+ PageSectionContent,
+ PageSectionDescription,
+ PageSectionDivider,
+ PageSectionGroup,
+ PageSectionHeader,
+ PageSectionTitle,
+} from "@/components/page-layout";
+import {
+ SettingsPage,
+ SettingsPageContent,
+ SettingsPageDescription,
+ SettingsPageHeader,
+ SettingsPageTitle,
+} from "@/components/settings-layout";
+import { getSpaceSubscription } from "@/features/billing/data";
+import {
+ getActiveSpaceForUser,
+ getSpaceSeatCount,
+} from "@/features/space/data";
+import { defineAbilityForMember } from "@/features/space/member/ability";
+import { getCurrentUser } from "@/features/user/data";
+import { Trans } from "@/i18n/client";
import { getTranslation } from "@/i18n/server";
import { isFeatureEnabled } from "@/lib/feature-flags/server";
-import { createPrivateSSRHelper } from "@/trpc/server/create-ssr-helper";
-import { BillingPageClient } from "./page-client";
+import { getPathname } from "@/lib/pathname";
+import { buildSafeRedirectUrl } from "@/lib/utils/redirect";
+import { ContactSupportLink } from "./components/contact-support-link";
+import { HobbyPlanCard } from "./components/hobby-plan-card";
+import { ProPlanCard } from "./components/pro-plan-card";
-export default async function BillingSettingsPage() {
+export default async function BillingSettingsPage({
+ searchParams,
+}: {
+ searchParams: Promise<{ seats_updated?: string }>;
+}) {
if (!isFeatureEnabled("billing")) {
notFound();
}
- const helpers = await createPrivateSSRHelper();
+ const user = await getCurrentUser();
- await Promise.all([
- helpers.billing.getSubscription.prefetch(),
- helpers.spaces.getSeats.prefetch(),
- ]);
+ if (!user) {
+ redirect(
+ buildSafeRedirectUrl({
+ destination: "/login",
+ returnUrl: await getPathname(),
+ }),
+ );
+ }
+
+ const space = await getActiveSpaceForUser(user.id);
+
+ if (!space) {
+ redirect(
+ buildSafeRedirectUrl({
+ destination: "/setup",
+ returnUrl: await getPathname(),
+ }),
+ );
+ }
+
+ const ability = defineAbilityForMember({
+ user: { id: user.id },
+ space: { id: space.id, ownerId: space.ownerId, role: space.role },
+ });
+
+ if (!ability.can("manage", "Billing")) {
+ return (
+ <EmptyState className="h-full">
+ <EmptyStateIcon>
+ <ShieldXIcon />
+ </EmptyStateIcon>
+ <EmptyStateTitle>
+ <Trans i18nKey="accessDenied" defaults="Access Denied" />
+ </EmptyStateTitle>
+ <EmptyStateDescription>
+ <Trans
+ i18nKey="ownerPermissionsRequired"
+ defaults="Only space owners can access billing settings."
+ />
+ </EmptyStateDescription>
+ </EmptyState>
+ );
+ }
+
+ const [subscription, usedSeats, { seats_updated: didUpdateSeats }] =
+ await Promise.all([
+ getSpaceSubscription(space.id),
+ getSpaceSeatCount(space.id),
+ searchParams,
+ ]);
return (
- <HydrationBoundary state={dehydrate(helpers.queryClient)}>
- <BillingPageClient />
- </HydrationBoundary>
+ <SettingsPage>
+ <SettingsPageHeader>
+ <SettingsPageTitle>
+ <Trans i18nKey="billing" defaults="Billing" />
+ </SettingsPageTitle>
+ <SettingsPageDescription>
+ <Trans
+ i18nKey="billingDescription"
+ defaults="Manage your billing information and subscription."
+ />
+ </SettingsPageDescription>
+ </SettingsPageHeader>
+ <SettingsPageContent>
+ <PageSectionGroup>
+ <PageSection>
+ <PageSectionHeader>
+ <PageSectionTitle>
+ <Trans i18nKey="billingPlanTitle" defaults="Plan" />
+ </PageSectionTitle>
+ <PageSectionDescription>
+ <Trans
+ i18nKey="billingSubscriptionDescription"
+ defaults="Manage your current subscription plan"
+ />
+ </PageSectionDescription>
+ </PageSectionHeader>
+ <PageSectionContent>
+ {subscription?.active ? (
+ <ProPlanCard
+ amount={subscription.amount}
+ currency={subscription.currency}
+ interval={subscription.interval}
+ seats={subscription.quantity}
+ usedSeats={usedSeats}
+ status={subscription.status}
+ cancelAtPeriodEnd={subscription.cancelAtPeriodEnd}
+ periodEnd={subscription.periodEnd}
+ />
+ ) : (
+ <HobbyPlanCard />
+ )}
+ {didUpdateSeats !== undefined ? (
+ <Alert variant="success">
+ <CheckCircleIcon />
+ <AlertTitle>
+ <Trans
+ i18nKey="seatsUpdatedAlertTitle"
+ defaults="Seats Updated"
+ />
+ </AlertTitle>
+ <AlertDescription>
+ <Trans
+ i18nKey="seatsUpdatedAlertDescription"
+ defaults="Your seat allocation has been successfully updated. The changes will be reflected in your next billing cycle."
+ />
+ </AlertDescription>
+ </Alert>
+ ) : null}
+ </PageSectionContent>
+ </PageSection>
+ <PageSectionDivider />
+ <PageSection>
+ <PageSectionHeader>
+ <PageSectionTitle>
+ <Trans i18nKey="support" defaults="Support" />
+ </PageSectionTitle>
+ <PageSectionDescription>
+ <Trans
+ i18nKey="supportDescription"
+ defaults="Need help with anything?"
+ />
+ </PageSectionDescription>
+ </PageSectionHeader>
+ <PageSectionContent>
+ <ContactSupportLink />
+ </PageSectionContent>
+ </PageSection>
+ </PageSectionGroup>
+ </SettingsPageContent>
+ </SettingsPage>
);
}
diff --git a/apps/web/src/features/billing/components/subscription-status-badge.tsx b/apps/web/src/features/billing/components/subscription-status-badge.tsx
new file mode 100644
index 000000000..2c956af43
--- /dev/null
+++ b/apps/web/src/features/billing/components/subscription-status-badge.tsx
@@ -0,0 +1,65 @@
+"use client";
+
+import { Badge } from "@rallly/ui/badge";
+import type { SubscriptionStatus } from "@/features/billing/schema";
+import { Trans } from "@/i18n/client";
+
+export function SubscriptionStatusBadge({
+ status,
+}: {
+ status: SubscriptionStatus;
+}) {
+ switch (status) {
+ case "active":
+ return (
+ <Badge variant="green">
+ <Trans i18nKey="subscriptionStatusActive" defaults="Active" />
+ </Badge>
+ );
+ case "trialing":
+ return (
+ <Badge variant="secondary">
+ <Trans i18nKey="subscriptionStatusTrialing" defaults="Trialing" />
+ </Badge>
+ );
+ case "paused":
+ return (
+ <Badge>
+ <Trans i18nKey="subscriptionStatusPaused" defaults="Paused" />
+ </Badge>
+ );
+ case "past_due":
+ return (
+ <Badge variant="destructive">
+ <Trans i18nKey="subscriptionStatusPastDue" defaults="Past due" />
+ </Badge>
+ );
+ case "unpaid":
+ return (
+ <Badge variant="destructive">
+ <Trans i18nKey="subscriptionStatusUnpaid" defaults="Unpaid" />
+ </Badge>
+ );
+ case "canceled":
+ return (
+ <Badge>
+ <Trans i18nKey="subscriptionStatusCanceled" defaults="Canceled" />
+ </Badge>
+ );
+ case "incomplete":
+ return (
+ <Badge>
+ <Trans i18nKey="subscriptionStatusIncomplete" defaults="Incomplete" />
+ </Badge>
+ );
+ case "incomplete_expired":
+ return (
+ <Badge>
+ <Trans
+ i18nKey="subscriptionStatusIncompleteExpired"
+ defaults="Incomplete expired"
+ />
+ </Badge>
+ );
+ }
+}
diff --git a/apps/web/src/features/billing/components/subscription-status-label.tsx b/apps/web/src/features/billing/components/subscription-status-label.tsx
deleted file mode 100644
index 4ca50dbe9..000000000
--- a/apps/web/src/features/billing/components/subscription-status-label.tsx
+++ /dev/null
@@ -1,70 +0,0 @@
-"use client";
-
-import type { SubscriptionStatus } from "@rallly/database";
-import { Trans, useTranslation } from "@/i18n/client";
-import { useDateTime } from "@/lib/datetime/client";
-
-interface SubscriptionStatusLabelProps {
- status: SubscriptionStatus;
- cancelAtPeriodEnd: boolean;
- periodEnd: Date;
-}
-
-export const SubscriptionStatusLabel = ({
- status,
- cancelAtPeriodEnd,
- periodEnd,
-}: SubscriptionStatusLabelProps) => {
- const { t } = useTranslation();
- const { formatDateTime } = useDateTime();
-
- const statusConfig: Record<
- string,
- {
- label: string;
- }
- > = {
- active: {
- label: t("subscriptionStatusActive", { defaultValue: "Active" }),
- },
- paused: {
- label: t("subscriptionStatusPaused", { defaultValue: "Paused" }),
- },
- trialing: {
- label: t("subscriptionStatusTrialing", { defaultValue: "Trialing" }),
- },
- past_due: {
- label: t("subscriptionStatusPastDue", { defaultValue: "Past due" }),
- },
- canceled: {
- label: t("subscriptionStatusCanceled", { defaultValue: "Canceled" }),
- },
- unpaid: {
- label: t("subscriptionStatusUnpaid", { defaultValue: "Unpaid" }),
- },
- incomplete: {
- label: t("subscriptionStatusIncomplete", { defaultValue: "Incomplete" }),
- },
- incomplete_expired: {
- label: t("subscriptionStatusIncompleteExpired", {
- defaultValue: "Incomplete expired",
- }),
- },
- unknown: {
- label: t("subscriptionStatusUnknown", { defaultValue: "Unknown" }),
- },
- };
-
- const config = statusConfig[status] || statusConfig.unknown;
-
- if (status === "active" && cancelAtPeriodEnd) {
- return (
- <Trans
- i18nKey="subscriptionCancelOn"
- defaults="Cancels {date}"
- values={{ date: formatDateTime(periodEnd, "date") }}
- />
- );
- }
- return <>{config.label}</>;
-};
diff --git a/apps/web/src/features/billing/schema.ts b/apps/web/src/features/billing/schema.ts
index 5356479e7..588f819d8 100644
--- a/apps/web/src/features/billing/schema.ts
+++ b/apps/web/src/features/billing/schema.ts
@@ -3,6 +3,18 @@ import * as z from "zod";
export const billingIntervalSchema = z.enum(["month", "year"]);
export type BillingInterval = z.infer<typeof billingIntervalSchema>;
+export const subscriptionStatusSchema = z.enum([
+ "incomplete",
+ "incomplete_expired",
+ "active",
+ "paused",
+ "trialing",
+ "past_due",
+ "canceled",
+ "unpaid",
+]);
+export type SubscriptionStatus = z.infer<typeof subscriptionStatusSchema>;
+
export const customerMetadataSchema = z.object({
userId: z.string(),
});
diff --git a/apps/web/src/trpc/routers/billing.ts b/apps/web/src/trpc/routers/billing.ts
index 6ef7816e0..cc819e84f 100644
--- a/apps/web/src/trpc/routers/billing.ts
+++ b/apps/web/src/trpc/routers/billing.ts
@@ -24,9 +24,6 @@ export const billing = router({
return space?.tier ?? ("hobby" as const);
}),
- getSubscription: spaceOwnerProcedure.query(async ({ ctx }) => {
- return await getSpaceSubscription(ctx.space.id);
- }),
updateSeats: spaceOwnerProcedure
.input(z.object({ seatDelta: z.int() }))
.mutation(async ({ ctx, input }) => {
diff --git a/packages/database/prisma/seed.ts b/packages/database/prisma/seed.ts
index 254ba824c..d5785d602 100644
--- a/packages/database/prisma/seed.ts
+++ b/packages/database/prisma/seed.ts
@@ -6,6 +6,7 @@ import {
scheduledEvents,
spaceMembers,
spaces,
+ subscriptions,
users,
} from "./seed/data";
@@ -32,7 +33,17 @@ async function main() {
await prisma.spaceMember.createMany({ data: spaceMembers });
console.info(`βœ“ ${spaceMembers.length} space members`);
- // 4. Scheduled events + invites
+ // 4. Subscriptions
+ await prisma.subscription.createMany({
+ data: subscriptions.map((sub) => ({
+ ...sub,
+ periodStart: new Date(sub.periodStart),
+ periodEnd: new Date(sub.periodEnd),
+ })),
+ });
+ console.info(`βœ“ ${subscriptions.length} subscriptions`);
+
+ // 5. Scheduled events + invites
let inviteCount = 0;
for (const evt of scheduledEvents) {
const eventId = evt.id ?? nextId();
@@ -78,7 +89,7 @@ async function main() {
`βœ“ ${scheduledEvents.length} scheduled events, ${inviteCount} invites`,
);
- // 5. Polls + options + participants + votes + comments
+ // 6. Polls + options + participants + votes + comments
let optionCount = 0;
let participantCount = 0;
let voteCount = 0;
@@ -175,7 +186,7 @@ async function main() {
`βœ“ ${polls.length} polls, ${optionCount} options, ${participantCount} participants, ${voteCount} votes, ${commentCount} comments`,
);
- // 6. Event types
+ // 7. Event types
const now = Date.now();
await prisma.eventType.createMany({
data: eventTypes.map((et, i) => ({
diff --git a/packages/database/prisma/seed/data.ts b/packages/database/prisma/seed/data.ts
index 7cc0fa1b3..726b0a14e 100644
--- a/packages/database/prisma/seed/data.ts
+++ b/packages/database/prisma/seed/data.ts
@@ -5,6 +5,8 @@ import type {
ScheduledEventStatus,
SpaceMemberRole,
SpaceTier,
+ SubscriptionInterval,
+ SubscriptionStatus,
VoteType,
} from "../../generated/prisma/client";
@@ -79,6 +81,44 @@ export const spaceMembers: Array<{
{ id: "sm-6", spaceId: "space-2", userId: "user-5", role: "MEMBER" },
];
+// ─── Subscriptions ───────────────────────────────────────────────────────────
+// Every pro space needs one so billing settings reflect a real subscription.
+// `amount` is the per-seat unit amount in the currency's minor unit.
+
+export const subscriptions: Array<{
+ id: string;
+ spaceId: string;
+ userId: string;
+ priceId: string;
+ subscriptionItemId: string;
+ quantity: number;
+ amount: number;
+ currency: string;
+ interval: SubscriptionInterval;
+ status: SubscriptionStatus;
+ active: boolean;
+ cancelAtPeriodEnd: boolean;
+ periodStart: string;
+ periodEnd: string;
+}> = [
+ {
+ id: "sub-1",
+ spaceId: "space-2",
+ userId: "user-1",
+ priceId: "price_seed_pro_monthly",
+ subscriptionItemId: "si_seed_pro_monthly",
+ quantity: 6,
+ amount: 700,
+ currency: "usd",
+ interval: "month",
+ status: "active",
+ active: true,
+ cancelAtPeriodEnd: false,
+ periodStart: d(-14),
+ periodEnd: d(16),
+ },
+];
+
// ─── Poll definitions ────────────────────────────────────────────────────────
// Each participant's `votes` array maps 1:1 with the `options` array.