Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
✨ Let space admins remove attribution from the poll footer badge (#3291)
Luke Vella1a2cf2e8e079
diff --git a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/admin-page-loader.tsx b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/admin-page-loader.tsxindex 0a820beec..ec46385e9 100644--- a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/admin-page-loader.tsx+++ b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/admin-page-loader.tsx@@ -9,13 +9,15 @@ const AdminPage = dynamic(export function AdminPageLoader({footerLinks,+ manageableSpace,}: {footerLinks: { label: string; href: string }[];+ manageableSpace: { id: string } | null;}) {return (<><PollBrandingFromContext />- <AdminPage footerLinks={footerLinks} />+ <AdminPage footerLinks={footerLinks} manageableSpace={manageableSpace} /></>);}diff --git a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/admin-page.tsx b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/admin-page.tsxindex 8094fa0f1..aa73ae603 100644--- a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/admin-page.tsx+++ b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/admin-page.tsx@@ -1,16 +1,29 @@"use client";+import { useInstancePolicy } from "@/features/instance-policy/client";+import { usePoll } from "@/features/poll/client";import { CommentsSheet } from "@/features/poll/components/comments-sheet";import { EventCard } from "@/features/poll/components/event-card";import { PollFooter } from "@/features/poll/components/poll-footer";import { ResponsiveResults } from "@/features/poll/components/responsive-results";import { VotingForm } from "@/features/poll/components/voting-form";+import { RemoveAttributionPopover } from "@/features/space/components/remove-attribution-popover";import { GuestPollAlert } from "./guest-poll-alert";export function AdminPage({footerLinks,+ manageableSpace,}: {footerLinks: { label: string; href: string }[];+ manageableSpace: { id: string } | null;}) {+ const poll = usePoll();+ const { spaceAttributionConfigurable } = useInstancePolicy();++ const canRemoveAttribution =+ spaceAttributionConfigurable &&+ manageableSpace !== null &&+ manageableSpace.id === poll.spaceId;+return (<div className="space-y-3 lg:space-y-4"><GuestPollAlert />@@ -21,7 +34,14 @@ export function AdminPage({<div className="fixed right-4 bottom-15 z-40 lg:right-6 lg:bottom-6"><CommentsSheet className="rounded-full shadow-lg" /></div>- <PollFooter footerLinks={footerLinks} />+ <PollFooter+ footerLinks={footerLinks}+ attributionAction={+ canRemoveAttribution ? (+ <RemoveAttributionPopover pollId={poll.id} />+ ) : undefined+ }+ /><div className="h-24 lg:hidden" /></div>);diff --git a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/page.tsx b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/page.tsxindex 2dedb4e6a..ba1b18312 100644--- a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/page.tsx+++ b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/page.tsx@@ -1,14 +1,28 @@import { Suspense } from "react";import { loadFooterLinks } from "@/features/instance-settings/loaders";+import { loadOptionalActiveSpace } from "@/features/space/loaders";import { AdminPageLoader } from "./admin-page-loader";-// Keeps the route shell synchronous so it can flush before the footer links-// read resolves. The page below is client-only, so this is the one server-// boundary the links can be loaded from.+// Keeps the route shell synchronous so it can flush before the reads+// resolve. The page below is client-only, so this is the one server+// boundary they can be loaded from.async function AdminPageWithFooterLinks() {- const footerLinks = await loadFooterLinks();+ const [footerLinks, activeSpace] = await Promise.all([+ loadFooterLinks(),+ loadOptionalActiveSpace(),+ ]);- return <AdminPageLoader footerLinks={footerLinks} />;+ // The attribution action updates the active space, and only its admins+ // may; the page checks the poll belongs to that space before showing it.+ const manageableSpace =+ activeSpace?.role === "admin" ? { id: activeSpace.id } : null;++ return (+ <AdminPageLoader+ footerLinks={footerLinks}+ manageableSpace={manageableSpace}+ />+ );}export default function Page() {diff --git a/apps/web/src/app/[locale]/(space)/settings/general/components/remove-attribution-setting.tsx b/apps/web/src/app/[locale]/(space)/settings/general/components/remove-attribution-setting.tsxindex 203ace573..ce38215a3 100644--- a/apps/web/src/app/[locale]/(space)/settings/general/components/remove-attribution-setting.tsx+++ b/apps/web/src/app/[locale]/(space)/settings/general/components/remove-attribution-setting.tsx@@ -6,15 +6,10 @@ import {FieldDescription,FieldLabel,} from "@rallly/ui/field";-import { toast } from "@rallly/ui/sonner";import { Switch } from "@rallly/ui/switch";-import React from "react";-import { showPayWall, useIsFree } from "@/features/billing/client";import { ProBadge } from "@/features/billing/components/pro-badge";-import { updateSpaceHideAttributionAction } from "@/features/space/actions";-import { useSpace } from "@/features/space/client";-import { Trans, useTranslation } from "@/i18n/client";-import { useSafeAction } from "@/lib/safe-action/client";+import { useHideAttributionToggle, useSpace } from "@/features/space/client";+import { Trans } from "@/i18n/client";export function RemoveAttributionSetting({disabled = false,@@ -22,34 +17,10 @@ export function RemoveAttributionSetting({disabled?: boolean;}) {const { data: space } = useSpace();- const isFree = useIsFree();- const { t } = useTranslation();-- const updateHideAttribution = useSafeAction(updateSpaceHideAttributionAction);-- // Optimistic value shown until the post-action router refresh delivers- // the updated space data; reverts automatically if the action fails.- const [hideAttribution, setOptimisticHideAttribution] = React.useOptimistic(- space.hideAttribution,- );-- const handleToggle = (newChecked: boolean) => {- if (isFree && newChecked) {- showPayWall({ from: "custom-branding", setting: "hide_attribution" });- return;- }-- React.startTransition(async () => {- setOptimisticHideAttribution(newChecked);- const result = await updateHideAttribution.executeAsync({- hideAttribution: newChecked,- });-- if (!result?.serverError && !result?.validationErrors) {- toast.success(t("saved", { defaultValue: "Saved" }));- }- });- };+ const { hideAttribution, isExecuting, toggle } = useHideAttributionToggle({+ hideAttribution: space.hideAttribution,+ payWallTrigger: { from: "custom-branding", setting: "hide_attribution" },+ });return (<Field orientation="horizontal">@@ -71,8 +42,8 @@ export function RemoveAttributionSetting({<Switchid="hide-attribution"checked={hideAttribution}- onCheckedChange={handleToggle}- disabled={disabled || updateHideAttribution.isExecuting}+ onCheckedChange={toggle}+ disabled={disabled || isExecuting}/></Field>);diff --git a/apps/web/src/features/billing/client.tsx b/apps/web/src/features/billing/client.tsxindex 60df4aede..67b499d0b 100644--- a/apps/web/src/features/billing/client.tsx+++ b/apps/web/src/features/billing/client.tsx@@ -44,7 +44,8 @@ export type PayWallTrigger = {| "space-collaboration"| "billing-settings"| "sidebar"- | "invite-dialog";+ | "invite-dialog"+ | "poll-footer";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.tsxindex 663275c08..0fd019cf9 100644--- a/apps/web/src/features/billing/components/pay-wall-dialog.tsx+++ b/apps/web/src/features/billing/components/pay-wall-dialog.tsx@@ -200,6 +200,7 @@ const leadingBenefitByTrigger: Partial<Record<PayWallTrigger["from"], string>> ={"invite-dialog": "emailInvites","api-keys": "apiAccess",+ "poll-footer": "removeAttribution",};// The benefit that triggered the pay wall leads the list.diff --git a/apps/web/src/features/poll/components/poll-footer.tsx b/apps/web/src/features/poll/components/poll-footer.tsxindex 563d1f336..e1460f065 100644--- a/apps/web/src/features/poll/components/poll-footer.tsx+++ b/apps/web/src/features/poll/components/poll-footer.tsx@@ -1,5 +1,7 @@"use client";import { posthog } from "@rallly/posthog/client";+import { cn } from "@rallly/ui";+import type React from "react";import { InstanceFooterLinks } from "@/components/instance-footer-links";import { Link } from "@/components/link";import { useBranding } from "@/features/branding/client";@@ -17,8 +19,13 @@ import { Trans } from "@/i18n/client";*/export function PollFooter({footerLinks = [],+ attributionAction,}: {footerLinks?: { label: string; href: string }[];+ // Control rendered inside the badge on the admin page (the invite page+ // passes nothing). Nested interactives are invalid inside the link, so+ // the pill becomes a wrapper holding the link and the control.+ attributionAction?: React.ReactNode;}) {const { hideAttribution } = useBranding();const poll = usePoll();@@ -32,31 +39,52 @@ export function PollFooter({return (<div className="flex flex-col items-center gap-4 py-3 text-center text-muted-foreground text-sm"><InstanceFooterLinks links={footerLinks} />- {isAttributionHidden ? null : (- <Link- className="inline-flex h-9 items-center gap-2 rounded-full border border-border bg-background px-4 font-normal text-foreground text-xs shadow-xs transition-[background-color,transform] ease-out hover:bg-gray-50 active:scale-[.98] motion-reduce:active:scale-100 dark:bg-muted dark:hover:bg-[color-mix(in_oklab,var(--color-gray-800),var(--color-gray-700)_25%)]"- href="https://rallly.co?utm_source=rallly&utm_medium=poll&utm_campaign=powered_by"- onClick={() => {- posthog?.capture("poll_footer:powered_by_link_click", {- pollId: poll.id,- spaceId: poll.spaceId,- tier: poll.space?.tier,- $groups: {- poll: poll.id,- ...(poll.spaceId ? { space: poll.spaceId } : {}),- },- });- }}- >- <Trans i18nKey="poweredBy" defaults="Powered by" />- {/* The wordmark is masked so it inherits the pill's text color in both themes */}- <span- aria-hidden="true"- className="h-3.5 w-[75px] bg-foreground [mask:url(/static/logo.svg)_no-repeat_center/contain]"- />- <span className="sr-only"> {DEFAULT_APP_NAME}</span>- </Link>+ {isAttributionHidden ? null : attributionAction ? (+ <span className={cn(pillClassName, "gap-1.5 pr-2")}>+ <PoweredByLink className="inline-flex h-full items-center gap-2" />+ {attributionAction}+ </span>+ ) : (+ <PoweredByLink+ className={cn(+ pillClassName,+ "transition-[background-color,transform] ease-out hover:bg-gray-50 active:scale-[.98] motion-reduce:active:scale-100 dark:hover:bg-[color-mix(in_oklab,var(--color-gray-800),var(--color-gray-700)_25%)]",+ )}+ />)}</div>);}++const pillClassName =+ "inline-flex h-9 items-center gap-2 rounded-full border border-border bg-background px-4 font-normal text-foreground text-xs shadow-xs dark:bg-muted";++function PoweredByLink({ className }: { className: string }) {+ const poll = usePoll();++ return (+ <Link+ className={className}+ href="https://rallly.co?utm_source=rallly&utm_medium=poll&utm_campaign=powered_by"+ onClick={() => {+ posthog?.capture("poll_footer:powered_by_link_click", {+ pollId: poll.id,+ spaceId: poll.spaceId,+ tier: poll.space?.tier,+ $groups: {+ poll: poll.id,+ ...(poll.spaceId ? { space: poll.spaceId } : {}),+ },+ });+ }}+ >+ <Trans i18nKey="poweredBy" defaults="Powered by" />+ {/* The wordmark is masked so it inherits the pill's text color in both themes */}+ <span+ aria-hidden="true"+ className="h-3.5 w-[75px] bg-foreground [mask:url(/static/logo.svg)_no-repeat_center/contain]"+ />+ <span className="sr-only"> {DEFAULT_APP_NAME}</span>+ </Link>+ );+}diff --git a/apps/web/src/features/space/client.tsx b/apps/web/src/features/space/client.tsxindex 41a8783fc..6c2e6eabd 100644--- a/apps/web/src/features/space/client.tsx+++ b/apps/web/src/features/space/client.tsx@@ -1,13 +1,19 @@"use client";+import { toast } from "@rallly/ui/sonner";import React from "react";+import type { PayWallTrigger } from "@/features/billing/client";+import { showPayWall, useIsFree } from "@/features/billing/client";import { getPrimaryColorVars } from "@/features/branding/utils";import { useInstancePolicy } from "@/features/instance-policy/client";import { defineAbilityForMember } from "@/features/space/member/ability";import type { SpaceDTO } from "@/features/space/types";import { isSpaceBrandingActive } from "@/features/space/utils";import { useAuthedUser } from "@/features/user/client";+import { useTranslation } from "@/i18n/client";+import { useSafeAction } from "@/lib/safe-action/client";import { defineAbilityForSpace } from "./ability";+import { updateSpaceHideAttributionAction } from "./actions";const SpaceContext = React.createContext<SpaceDTO | null>(null);@@ -72,3 +78,49 @@ export function SpaceProvider({</SpaceContext.Provider>);}++/**+ * The "remove attribution" toggle, shared by the general settings row and+ * the poll footer popover so the plan gate lives in one place: turning it+ * on in a free space opens the pay wall instead of calling the action.+ */+export function useHideAttributionToggle({+ hideAttribution,+ payWallTrigger,+}: {+ hideAttribution: boolean;+ payWallTrigger: PayWallTrigger;+}) {+ const isFree = useIsFree();+ const { t } = useTranslation();+ const updateHideAttribution = useSafeAction(updateSpaceHideAttributionAction);++ // Optimistic value shown until the post-action router refresh delivers+ // the updated space data; reverts automatically if the action fails.+ const [optimisticValue, setOptimisticValue] =+ React.useOptimistic(hideAttribution);++ const toggle = (newChecked: boolean) => {+ if (isFree && newChecked) {+ showPayWall(payWallTrigger);+ return;+ }++ React.startTransition(async () => {+ setOptimisticValue(newChecked);+ const result = await updateHideAttribution.executeAsync({+ hideAttribution: newChecked,+ });++ if (!result?.serverError && !result?.validationErrors) {+ toast.success(t("saved", { defaultValue: "Saved" }));+ }+ });+ };++ return {+ hideAttribution: optimisticValue,+ isExecuting: updateHideAttribution.isExecuting,+ toggle,+ };+}diff --git a/apps/web/src/features/space/components/remove-attribution-popover.tsx b/apps/web/src/features/space/components/remove-attribution-popover.tsxnew file mode 100644index 000000000..c880bcd0b--- /dev/null+++ b/apps/web/src/features/space/components/remove-attribution-popover.tsx@@ -0,0 +1,96 @@+"use client";++import { posthog } from "@rallly/posthog/client";+import { Button } from "@rallly/ui/button";+import { useDialog } from "@rallly/ui/dialog";+import { Field, FieldDescription, FieldLabel } from "@rallly/ui/field";+import { Popover, PopoverContent, PopoverTrigger } from "@rallly/ui/popover";+import { XIcon } from "lucide-react";+import { useIsFree } from "@/features/billing/client";+import { ProBadge } from "@/features/billing/components/pro-badge";+import { useHideAttributionToggle } from "@/features/space/client";+import { Trans, useTranslation } from "@/i18n/client";++/**+ * Dismiss control rendered inside the "Powered by" badge on the poll admin+ * page. Attribution is a space setting, so the popover says so and points+ * at where it lives; the switch is a convenience for Pro admins and the+ * upgrade button routes free admins to the pay wall.+ */+export function RemoveAttributionPopover({ pollId }: { pollId: string }) {+ const isFree = useIsFree();+ const { t } = useTranslation();+ // Dismissed before opening the pay wall so the dialog doesn't stack on it+ const popover = useDialog();+ const { isExecuting, toggle } = useHideAttributionToggle({+ // The badge is only rendered while attribution is shown+ hideAttribution: false,+ payWallTrigger: {+ from: "poll-footer",+ setting: "hide_attribution",+ pollId,+ },+ });++ return (+ <Popover {...popover.dialogProps}>+ <PopoverTrigger+ render={+ <Button+ variant="ghost"+ size="icon-xs"+ className="size-5 rounded-full text-muted-foreground hover:text-foreground"+ aria-label={t("removeAttribution", {+ defaultValue: "Remove attribution",+ })}+ />+ }+ onClick={() => {+ posthog?.capture("poll_admin:remove_attribution_click", {+ poll_id: pollId,+ });+ }}+ >+ <XIcon className="size-3" />+ </PopoverTrigger>+ <PopoverContent align="center" side="top" sideOffset={8}>+ <Field>+ <FieldLabel>+ <Trans+ i18nKey="removeAttributionSettingTitle"+ defaults="Remove attribution"+ />+ {isFree ? <ProBadge /> : null}+ </FieldLabel>+ <FieldDescription>+ <Trans+ i18nKey="removeAttributionSettingDescription"+ defaults='Hide "Powered by Rallly" on invite pages and participant emails.'+ />+ </FieldDescription>+ </Field>+ {isFree ? (+ <Button+ variant="primary"+ className="w-full"+ onClick={() => {+ popover.dismiss();+ toggle(true);+ }}+ >+ <Trans i18nKey="upgradeToPro" defaults="Upgrade to Pro" />+ </Button>+ ) : (+ <Button+ variant="primary"+ className="w-full"+ disabled={isExecuting}+ onClick={() => toggle(true)}+ >+ <Trans i18nKey="remove" defaults="Remove" />+ </Button>+ )}+ </PopoverContent>+ </Popover>+ );+}diff --git a/apps/web/src/features/space/loaders.ts b/apps/web/src/features/space/loaders.tsindex 3bafc9cdc..2fb5ca93c 100644--- a/apps/web/src/features/space/loaders.ts+++ b/apps/web/src/features/space/loaders.ts@@ -109,6 +109,26 @@ export const getActiveSpaceContentScope = cache(},);+/**+ * The active space for the signed-in user, or null when there is none: the+ * visitor is unauthenticated, a guest, or has no effective membership. For+ * routes that admit guests, where getActiveSpace's redirects would be wrong.+ * Bans still throw, as in getActiveSpace.+ */+export const loadOptionalActiveSpace = cache(async () => {+ const state = await getSessionState();++ if (state.status !== "authenticated" || state.session.user.isGuest) {+ return null;+ }++ if (state.session.user.banned) {+ throw new InvalidSessionError();+ }++ return getActiveSpaceForUser(state.session.user.id);+});+/*** Upcoming event count for the signed-in user's active space. Lives here* rather than in scheduled-event/loaders.ts because account-deletion (user)