Skip to content

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

✨ Show open poll usage on the polls page and the home polls tile (#3498)

Luke Vella3c7b03e5b45f
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index fb661b5a1..99bbe3c8f 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -222,6 +222,7 @@
"copyEditLink": "Copy edit link",
"copyLink": "Copy link",
"create": "Create",
+ "createAnAccount": "Create an account",
"createApiKey": "Create API key",
"createApiKeyDescription": "Create a new API key for programmatic access to your space",
"createdTime": "Created {relativeTime}",
@@ -685,11 +686,16 @@
"noWebhooksDescription": "Add a webhook to receive events on your own server",
"oidcAutoSignInDescription": "You are being redirected to the login page...",
"openPollCount": "{count, plural, other {# open}}",
+ "openPollCountOfLimit": "{openCount} of {limit} open",
"openPollLimitFreeDescription": "{planName} includes up to {limit} open polls at a time. Finalize or close polls to make room, or upgrade for unlimited open polls.",
"openPollLimitGuestDescription": "Guests can have one open poll at a time. Finalize or close polls to make room, or log in to increase your limit.",
"openPollLimitReachedTitle": "Open poll limit reached",
"openPollLimitUsage": "{openCount} of {limit}",
"openPolls": "Open polls",
+ "openPollUsageAtLimitHint": "Finalize or close a poll to create a new one, or upgrade for unlimited open polls.",
+ "openPollUsageButton": "{limit, plural, one {{openCount} of # open poll} other {{openCount} of # open polls}}",
+ "openPollUsageGuestHint": "Guests can have {limit} open poll at a time. Create an account to have up to {freeLimit}.",
+ "openPollUsageHint": "Your plan allows up to {limit} open polls at a time.",
"opensInNewTab": "(opens in new tab)",
"optional": "(optional)",
"optionalLabel": "(Optional)",
diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/dashboard-home.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/dashboard-home.tsx
index 9789b3339..ad49f3aca 100644
--- a/apps/web/src/app/[locale]/(space)/(dashboard)/dashboard-home.tsx
+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/dashboard-home.tsx
@@ -16,12 +16,14 @@ import {
PollPageIcon,
SettingsPageIcon,
} from "@/components/page-icons";
+import type { OpenPollUsage } from "@/features/poll/limit/types";
import { getTranslation } from "@/i18n/server";
import { isFeatureEnabled } from "@/lib/feature-flags/server";
import { PasswordSetupAlert } from "./password-setup-alert";
export async function DashboardHome({
openPollCount,
+ openPollUsage,
upcomingEventCount,
memberCount,
seatCount,
@@ -30,6 +32,8 @@ export async function DashboardHome({
canManageMembers,
}: {
openPollCount: number;
+ /** The organizer's own usage, which replaces the space-wide count while a limit applies */
+ openPollUsage: OpenPollUsage | null;
upcomingEventCount: number;
memberCount: number;
seatCount: number;
@@ -100,14 +104,28 @@ export async function DashboardHome({
/>
</TileTitle>
<TileDescription>
- <Trans
- t={t}
- i18n={i18n}
- ns="app"
- i18nKey="openPollCount"
- defaults="{count, plural, other {# open}}"
- values={{ count: openPollCount }}
- />
+ {openPollUsage?.limit != null ? (
+ <Trans
+ t={t}
+ i18n={i18n}
+ ns="app"
+ i18nKey="openPollCountOfLimit"
+ defaults="{openCount} of {limit} open"
+ values={{
+ openCount: openPollUsage.openCount,
+ limit: openPollUsage.limit,
+ }}
+ />
+ ) : (
+ <Trans
+ t={t}
+ i18n={i18n}
+ ns="app"
+ i18nKey="openPollCount"
+ defaults="{count, plural, other {# open}}"
+ values={{ count: openPollCount }}
+ />
+ )}
</TileDescription>
</Tile>
diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/page.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/page.tsx
index 833bd107b..546a18767 100644
--- a/apps/web/src/app/[locale]/(space)/(dashboard)/page.tsx
+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/page.tsx
@@ -1,4 +1,5 @@
import type { Metadata } from "next";
+import { loadOptionalOpenPollUsage } from "@/features/poll/limit/loaders";
import { loadPollStatusCounts } from "@/features/poll/loaders";
import {
loadActiveSpace,
@@ -10,20 +11,28 @@ import { getTranslation } from "@/i18n/server";
import { DashboardHome } from "./dashboard-home";
export default async function Page() {
- const [user, space, pollStatusCounts, upcomingEventCount, hasNoAccounts] =
- await Promise.all([
- loadUser(),
- loadActiveSpace(),
- loadPollStatusCounts(),
- loadUpcomingEventCount(),
- loadUserHasNoAccounts(),
- ]);
+ const [
+ user,
+ space,
+ pollStatusCounts,
+ openPollUsage,
+ upcomingEventCount,
+ hasNoAccounts,
+ ] = await Promise.all([
+ loadUser(),
+ loadActiveSpace(),
+ loadPollStatusCounts(),
+ loadOptionalOpenPollUsage(),
+ loadUpcomingEventCount(),
+ loadUserHasNoAccounts(),
+ ]);
const ability = defineAbilityForMember({ user: { id: user.id }, space });
return (
<DashboardHome
openPollCount={pollStatusCounts.open}
+ openPollUsage={openPollUsage}
upcomingEventCount={upcomingEventCount}
memberCount={space.memberCount}
seatCount={space.seatCount}
diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/page.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/page.tsx
index 38f17eab9..ff5021641 100644
--- a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/page.tsx
+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/page.tsx
@@ -1,10 +1,18 @@
import { dehydrate, HydrationBoundary } from "@tanstack/react-query";
import type { Metadata } from "next";
+import { Suspense } from "react";
+import { OpenPollUsageMeter } from "@/features/poll/limit/components/open-poll-usage-meter";
+import { loadOptionalOpenPollUsage } from "@/features/poll/limit/loaders";
import { loadPollStatusCounts } from "@/features/poll/loaders";
import { getTranslation } from "@/i18n/server";
import { createPrivateSSRHelper } from "@/trpc/server/create-ssr-helper";
import { PollsPage } from "./polls-page";
+async function OpenPollUsageSlot() {
+ const usage = await loadOptionalOpenPollUsage();
+ return usage ? <OpenPollUsageMeter usage={usage} /> : null;
+}
+
export default async function Page() {
const helpers = await createPrivateSSRHelper();
@@ -17,7 +25,14 @@ export default async function Page() {
return (
<HydrationBoundary state={dehydrate(helpers.queryClient)}>
- <PollsPage counts={counts} />
+ <PollsPage
+ counts={counts}
+ usageMeter={
+ <Suspense fallback={null}>
+ <OpenPollUsageSlot />
+ </Suspense>
+ }
+ />
</HydrationBoundary>
);
}
diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/polls-page.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/polls-page.tsx
index 602aa66ec..0d43182ac 100644
--- a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/polls-page.tsx
+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/polls-page.tsx
@@ -84,7 +84,13 @@ function PollsEmptyState() {
);
}
-export function PollsPage({ counts }: { counts: Record<PollStatus, number> }) {
+export function PollsPage({
+ counts,
+ usageMeter,
+}: {
+ counts: Record<PollStatus, number>;
+ usageMeter: React.ReactNode;
+}) {
const searchParams = useSearchParams();
const { t } = useTranslation();
const { data: space } = useSpace();
@@ -113,6 +119,7 @@ export function PollsPage({ counts }: { counts: Record<PollStatus, number> }) {
<Trans i18nKey="polls" defaults="Polls" />
</ListViewTitle>
<ListViewActions>
+ {usageMeter}
<Link
href="/new"
className={buttonVariants({ variant: "primary" })}
diff --git a/apps/web/src/features/billing/client.tsx b/apps/web/src/features/billing/client.tsx
index b8b3cb111..b983d45f4 100644
--- a/apps/web/src/features/billing/client.tsx
+++ b/apps/web/src/features/billing/client.tsx
@@ -59,7 +59,8 @@ export type PayWallTrigger = {
| "finalize-dialog"
| "poll-footer"
| "polls-list"
- | "poll-limit";
+ | "poll-limit"
+ | "poll-limit-meter";
setting?: string;
action?: string;
pollId?: string;
diff --git a/apps/web/src/features/billing/components/pay-wall-dialog.tsx b/apps/web/src/features/billing/components/pay-wall-dialog.tsx
index 2dd939b02..321308636 100644
--- a/apps/web/src/features/billing/components/pay-wall-dialog.tsx
+++ b/apps/web/src/features/billing/components/pay-wall-dialog.tsx
@@ -205,6 +205,7 @@ const leadingBenefitByTrigger: Partial<Record<PayWallTrigger["from"], string>> =
"api-keys": "apiAccess",
"poll-footer": "removeAttribution",
"poll-limit": "unlimitedOpenPolls",
+ "poll-limit-meter": "unlimitedOpenPolls",
};
// The benefit that triggered the pay wall leads the list. Unlimited open
diff --git a/apps/web/src/features/poll/limit/components/open-poll-limit-dialog.tsx b/apps/web/src/features/poll/limit/components/open-poll-limit-dialog.tsx
index 52a5ff580..812227a27 100644
--- a/apps/web/src/features/poll/limit/components/open-poll-limit-dialog.tsx
+++ b/apps/web/src/features/poll/limit/components/open-poll-limit-dialog.tsx
@@ -1,7 +1,7 @@
"use client";
import { posthog } from "@rallly/posthog/client";
-import { buttonVariants, cn } from "@rallly/ui";
+import { buttonVariants } from "@rallly/ui";
import { Button } from "@rallly/ui/button";
import {
Dialog,
@@ -12,7 +12,6 @@ import {
DialogTitle,
useDialog,
} from "@rallly/ui/dialog";
-import { Progress } from "@rallly/ui/progress";
import { BarChart2Icon } from "lucide-react";
import { usePathname } from "next/navigation";
import React from "react";
@@ -24,8 +23,9 @@ import { PayWallDialog } from "@/features/billing/components/pay-wall-dialog";
import { PLAN_NAMES } from "@/features/billing/constants";
import type { OpenPollLimitSource } from "@/features/poll/limit/client";
import { useOpenPollLimitStore } from "@/features/poll/limit/client";
+import { OpenPollUsageBar } from "@/features/poll/limit/components/open-poll-usage-bar";
import type { OpenPollUsage } from "@/features/poll/limit/types";
-import { Trans, useTranslation } from "@/i18n/client";
+import { Trans } from "@/i18n/client";
/**
* Single, app-wide instance. Open it from anywhere with
@@ -163,46 +163,6 @@ function OpenPollLimitContent({
);
}
-function OpenPollUsageBar({
- openCount,
- limit,
-}: {
- openCount: number;
- limit: number;
-}) {
- const { t } = useTranslation();
- const isAtLimit = openCount >= limit;
- const usageText = t("openPollLimitUsage", {
- defaultValue: "{openCount} of {limit}",
- openCount,
- limit,
- });
- return (
- <div className="space-y-2">
- <div className="flex items-baseline justify-between gap-4 text-sm">
- <span className="font-medium">
- <Trans i18nKey="openPolls" defaults="Open polls" />
- </span>
- <span
- className={cn(
- "text-muted-foreground tabular-nums",
- isAtLimit && "text-destructive",
- )}
- >
- {usageText}
- </span>
- </div>
- <Progress
- value={Math.min((openCount / limit) * 100, 100)}
- aria-label={t("openPolls", { defaultValue: "Open polls" })}
- getAriaValueText={() => usageText}
- className="h-2"
- indicatorClassName={cn(isAtLimit && "bg-destructive bg-none")}
- />
- </div>
- );
-}
-
function OpenPollLimitActions({
usage,
onRegisterClick,
diff --git a/apps/web/src/features/poll/limit/components/open-poll-usage-bar.tsx b/apps/web/src/features/poll/limit/components/open-poll-usage-bar.tsx
new file mode 100644
index 000000000..76910ed40
--- /dev/null
+++ b/apps/web/src/features/poll/limit/components/open-poll-usage-bar.tsx
@@ -0,0 +1,49 @@
+"use client";
+
+import { cn } from "@rallly/ui";
+import { Progress } from "@rallly/ui/progress";
+import { Trans, useTranslation } from "@/i18n/client";
+
+export function OpenPollUsageBar({
+ openCount,
+ limit,
+ label = <Trans i18nKey="openPolls" defaults="Open polls" />,
+}: {
+ openCount: number;
+ limit: number;
+ /** Replaces the default label, e.g. with a popover title */
+ label?: React.ReactNode;
+}) {
+ const { t } = useTranslation();
+ const isAtLimit = openCount >= limit;
+ const usageText = t("openPollLimitUsage", {
+ defaultValue: "{openCount} of {limit}",
+ openCount,
+ limit,
+ });
+ return (
+ <div className="space-y-2">
+ <div className="flex items-baseline justify-between gap-4 text-sm">
+ <span className="font-medium">{label}</span>
+ <span
+ className={cn(
+ "text-muted-foreground tabular-nums",
+ isAtLimit && "text-destructive",
+ )}
+ >
+ {usageText}
+ </span>
+ </div>
+ <Progress
+ value={Math.min((openCount / limit) * 100, 100)}
+ aria-label={t("openPolls", { defaultValue: "Open polls" })}
+ getAriaValueText={() => usageText}
+ className="h-2 bg-gray-100 dark:bg-gray-800"
+ indicatorClassName={cn(
+ "bg-none",
+ isAtLimit ? "bg-destructive" : "bg-green-500",
+ )}
+ />
+ </div>
+ );
+}
diff --git a/apps/web/src/features/poll/limit/components/open-poll-usage-meter.tsx b/apps/web/src/features/poll/limit/components/open-poll-usage-meter.tsx
new file mode 100644
index 000000000..56735d79c
--- /dev/null
+++ b/apps/web/src/features/poll/limit/components/open-poll-usage-meter.tsx
@@ -0,0 +1,152 @@
+"use client";
+
+import { posthog } from "@rallly/posthog/client";
+import { buttonVariants, cn } from "@rallly/ui";
+import { Button } from "@rallly/ui/button";
+import {
+ Popover,
+ PopoverContent,
+ PopoverDescription,
+ PopoverTitle,
+ PopoverTrigger,
+} from "@rallly/ui/popover";
+import React from "react";
+import { LoginLink } from "@/components/login-link";
+import { showPayWall } from "@/features/billing/client";
+import { FREE_OPEN_POLL_LIMIT } from "@/features/billing/constants";
+import { OpenPollUsageBar } from "@/features/poll/limit/components/open-poll-usage-bar";
+import type { OpenPollUsage } from "@/features/poll/limit/types";
+import {
+ isAtOpenPollLimit,
+ isNearOpenPollLimit,
+} from "@/features/poll/limit/utils";
+import { Trans, useTranslation } from "@/i18n/client";
+
+function UsageDonut({
+ value,
+ isAtLimit,
+}: {
+ value: number;
+ isAtLimit: boolean;
+}) {
+ const radius = 6;
+ const circumference = 2 * Math.PI * radius;
+ return (
+ <svg viewBox="0 0 16 16" className="size-4 -rotate-90" aria-hidden="true">
+ <circle
+ cx="8"
+ cy="8"
+ r={radius}
+ fill="none"
+ strokeWidth="2.5"
+ className="stroke-gray-100 dark:stroke-gray-800"
+ />
+ <circle
+ cx="8"
+ cy="8"
+ r={radius}
+ fill="none"
+ strokeWidth="2.5"
+ strokeLinecap="round"
+ strokeDasharray={circumference}
+ strokeDashoffset={circumference * (1 - Math.min(value, 1))}
+ className={cn(isAtLimit ? "stroke-destructive" : "stroke-green-500")}
+ />
+ </svg>
+ );
+}
+
+export function OpenPollUsageMeter({ usage }: { usage: OpenPollUsage }) {
+ const { t } = useTranslation();
+ const [open, setOpen] = React.useState(false);
+
+ if (usage.limit === null || !isNearOpenPollLimit(usage)) {
+ return null;
+ }
+
+ const eventProperties = {
+ tier: usage.tier,
+ open_count: usage.openCount,
+ limit: usage.limit,
+ source: "meter",
+ };
+
+ return (
+ <Popover open={open} onOpenChange={setOpen}>
+ <PopoverTrigger
+ render={<Button variant="ghost" />}
+ onClick={() => {
+ posthog?.capture("poll_limit:meter_click", eventProperties);
+ }}
+ >
+ <UsageDonut
+ value={usage.openCount / usage.limit}
+ isAtLimit={isAtOpenPollLimit(usage)}
+ />
+ <span className="tabular-nums">
+ {t("openPollUsageButton", {
+ defaultValue:
+ "{limit, plural, one {{openCount} of # open poll} other {{openCount} of # open polls}}",
+ openCount: usage.openCount,
+ limit: usage.limit,
+ })}
+ </span>
+ </PopoverTrigger>
+ <PopoverContent align="end" className="w-80 gap-4">
+ <div className="space-y-2">
+ <OpenPollUsageBar
+ openCount={usage.openCount}
+ limit={usage.limit}
+ label={
+ <PopoverTitle render={<span />}>
+ <Trans i18nKey="openPolls" defaults="Open polls" />
+ </PopoverTitle>
+ }
+ />
+ <PopoverDescription>
+ {usage.tier === "guest" ? (
+ <Trans
+ i18nKey="openPollUsageGuestHint"
+ defaults="Guests can have {limit} open poll at a time. Create an account to have up to {freeLimit}."
+ values={{ limit: usage.limit, freeLimit: FREE_OPEN_POLL_LIMIT }}
+ />
+ ) : isAtOpenPollLimit(usage) ? (
+ <Trans
+ i18nKey="openPollUsageAtLimitHint"
+ defaults="Finalize or close a poll to create a new one, or upgrade for unlimited open polls."
+ />
+ ) : (
+ <Trans
+ i18nKey="openPollUsageHint"
+ defaults="Your plan allows up to {limit} open polls at a time."
+ values={{ limit: usage.limit }}
+ />
+ )}
+ </PopoverDescription>
+ </div>
+ {usage.tier === "guest" ? (
+ <LoginLink
+ className={cn(buttonVariants({ size: "sm" }), "self-start")}
+ onClick={() => {
+ posthog?.capture("poll_limit:register_click", eventProperties);
+ }}
+ >
+ <Trans i18nKey="createAnAccount" defaults="Create an account" />
+ </LoginLink>
+ ) : usage.tier === "hobby" ? (
+ <Button
+ size="sm"
+ className="self-start"
+ onClick={() => {
+ posthog?.capture("poll_limit:upgrade_click", eventProperties);
+ setOpen(false);
+ showPayWall({ from: "poll-limit-meter" });
+ }}
+ >
+ <Trans i18nKey="upgradeToPro" defaults="Upgrade to Pro" />
+ </Button>
+ ) : null}
+ </PopoverContent>
+ </Popover>
+ );
+}
diff --git a/apps/web/src/features/poll/limit/utils.test.ts b/apps/web/src/features/poll/limit/utils.test.ts
index 9d32c719b..f9ff8e2b0 100644
--- a/apps/web/src/features/poll/limit/utils.test.ts
+++ b/apps/web/src/features/poll/limit/utils.test.ts
@@ -1,5 +1,10 @@
import { describe, expect, it } from "vitest";
-import { getOpenPollLimit, getOpenPollTier, isAtOpenPollLimit } from "./utils";
+import {
+ getOpenPollLimit,
+ getOpenPollTier,
+ isAtOpenPollLimit,
+ isNearOpenPollLimit,
+} from "./utils";
describe("getOpenPollLimit", () => {
it("is 1 for guests, 3 for free and unlimited on Pro", () => {
@@ -40,3 +45,23 @@ describe("isAtOpenPollLimit", () => {
).toBe(false);
});
});
+
+describe("isNearOpenPollLimit", () => {
+ it("is reached one poll short of the limit", () => {
+ expect(isNearOpenPollLimit({ tier: "hobby", limit: 3, openCount: 1 })).toBe(
+ false,
+ );
+ expect(isNearOpenPollLimit({ tier: "hobby", limit: 3, openCount: 2 })).toBe(
+ true,
+ );
+ expect(isNearOpenPollLimit({ tier: "hobby", limit: 3, openCount: 5 })).toBe(
+ true,
+ );
+ });
+
+ it("is never reached without a limit", () => {
+ expect(
+ isNearOpenPollLimit({ tier: "pro", limit: null, openCount: 1000 }),
+ ).toBe(false);
+ });
+});
diff --git a/apps/web/src/features/poll/limit/utils.ts b/apps/web/src/features/poll/limit/utils.ts
index 42173101a..3d65f33f4 100644
--- a/apps/web/src/features/poll/limit/utils.ts
+++ b/apps/web/src/features/poll/limit/utils.ts
@@ -28,3 +28,11 @@ export function getOpenPollLimit({
export function isAtOpenPollLimit({ limit, openCount }: OpenPollUsage) {
return limit !== null && openCount >= limit;
}
+
+/**
+ * One poll short of the limit or beyond it: the point where usage is worth
+ * showing. Below that a meter is noise for most free organizers.
+ */
+export function isNearOpenPollLimit({ limit, openCount }: OpenPollUsage) {
+ return limit !== null && openCount >= limit - 1;
+}