Skip to content

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

✨ Let hosts copy an invitee's personal link from the Share dialog (#3178)

Luke Vella3011b1adef72
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index c3693fa68..d0be31037 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -397,6 +397,7 @@
"invalidSessionLabel": "Session",
"invalidSessionTitle": "Your session is no longer valid",
"inviteCanceledSuccess": "Invite canceled successfully",
+ "inviteeRowOptions": "Options for {email}",
"inviteFailed": "Failed to send invitation",
"inviteLink": "Invite link",
"inviteLinkCopied": "Invite link copied",
@@ -770,6 +771,8 @@
"share": "Share",
"shareDialogAlreadyInvited": "{email} is already invited",
"shareDialogAlreadyResponded": "{email} has already responded",
+ "shareDialogCopyFailed": "Couldn't copy the link. Try again.",
+ "shareDialogCopyPersonalLink": "Copy personal link",
"shareDialogDailyLimit": "You've reached today's limit of 100 invites",
"shareDialogDescription": "Share the invite link, or invite people by email.",
"shareDialogGuestPrompt": "Create an account to invite people by email. Your invites and their responses stay attached to your account instead of this browser.",
@@ -778,6 +781,7 @@
"shareDialogInviteSent": "Invite sent to {email}",
"shareDialogNoInvitesDescription": "Enter an address above to send the first invite.",
"shareDialogNoInvitesTitle": "No one invited yet",
+ "shareDialogPersonalLinkCopied": "Personal link for {email} copied",
"shareDialogPollClosed": "Reopen the poll to send invites",
"shareDialogSendFailed": "Couldn't send to {email}. Try again.",
"shareDialogSendInvite": "Send invite",
diff --git a/apps/web/src/features/poll/components/invite-by-email.tsx b/apps/web/src/features/poll/components/invite-by-email.tsx
index 4a700f0a5..d46605378 100644
--- a/apps/web/src/features/poll/components/invite-by-email.tsx
+++ b/apps/web/src/features/poll/components/invite-by-email.tsx
@@ -38,6 +38,7 @@ type Row = {
id: string;
email: string;
status: InviteeRowStatus;
+ inviteUrl?: string;
};
// Same rule as the server, so a client accepted address is never refused
@@ -308,6 +309,7 @@ export function InviteByEmail({ invites }: { invites: PollInviteListItem[] }) {
key={row.id}
email={row.email}
status={row.status}
+ inviteUrl={row.inviteUrl}
/>
))}
</ul>
diff --git a/apps/web/src/features/poll/components/invitee-list.tsx b/apps/web/src/features/poll/components/invitee-list.tsx
index e51192741..a2aef0580 100644
--- a/apps/web/src/features/poll/components/invitee-list.tsx
+++ b/apps/web/src/features/poll/components/invitee-list.tsx
@@ -1,10 +1,22 @@
"use client";
+import { posthog } from "@rallly/posthog/client";
import { cn } from "@rallly/ui";
-import { MailIcon } from "lucide-react";
+import { Button } from "@rallly/ui/button";
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuTrigger,
+} from "@rallly/ui/dropdown-menu";
+import { toast } from "@rallly/ui/sonner";
+import { LinkIcon, MailIcon, MoreHorizontalIcon } from "lucide-react";
+import React from "react";
+import { useCopyToClipboard } from "react-use";
import { Spinner } from "@/components/spinner";
+import { usePoll } from "@/features/poll/client";
import type { PollInviteStatus } from "@/features/poll/invite/utils";
-import { Trans } from "@/i18n/client";
+import { Trans, useTranslation } from "@/i18n/client";
export type InviteeRowStatus = PollInviteStatus | "sending";
@@ -42,12 +54,89 @@ export function InviteeStatusPill({ status }: { status: InviteeRowStatus }) {
);
}
+/**
+ * The per invitee link is the only thing that joins a response to its
+ * invite, so a host who reaches someone through another channel copies
+ * this rather than the generic invite link.
+ */
+function InviteeRowMenu({
+ email,
+ status,
+ inviteUrl,
+}: {
+ email: string;
+ status: PollInviteStatus;
+ inviteUrl: string;
+}) {
+ const poll = usePoll();
+ const { t } = useTranslation();
+ const [state, copyToClipboard] = useCopyToClipboard();
+
+ // react-use records a failed copy as `error` and a successful one as
+ // `value`; the toast only claims success in the second case.
+ React.useEffect(() => {
+ if (state.error) {
+ console.error(`Unable to copy value: ${state.error.message}`);
+ toast.error(
+ t("shareDialogCopyFailed", {
+ defaultValue: "Couldn't copy the link. Try again.",
+ }),
+ );
+ return;
+ }
+ if (state.value) {
+ toast(
+ t("shareDialogPersonalLinkCopied", {
+ defaultValue: "Personal link for {email} copied",
+ email,
+ }),
+ );
+ posthog?.capture("poll_share:invitee_link_copy", {
+ poll_id: poll.id,
+ status,
+ });
+ }
+ }, [state, email, status, poll.id, t]);
+
+ return (
+ <DropdownMenu>
+ <DropdownMenuTrigger
+ render={
+ <Button
+ aria-label={t("inviteeRowOptions", {
+ defaultValue: "Options for {email}",
+ email,
+ })}
+ variant="ghost"
+ size="icon"
+ className="shrink-0"
+ />
+ }
+ >
+ <MoreHorizontalIcon className="text-muted-foreground" />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ <DropdownMenuItem onClick={() => copyToClipboard(inviteUrl)}>
+ <LinkIcon />
+ <Trans
+ i18nKey="shareDialogCopyPersonalLink"
+ defaults="Copy personal link"
+ />
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ );
+}
+
export function InviteeRow({
email,
status,
+ inviteUrl,
}: {
email: string;
status: InviteeRowStatus;
+ // Absent while the invite is still sending and on preview rows.
+ inviteUrl?: string;
}) {
return (
<li className="flex h-11 items-center gap-2.5 rounded-lg px-1.5 hover:bg-accent has-[:focus-visible]:bg-accent">
@@ -59,6 +148,9 @@ export function InviteeRow({
</span>
<span className="min-w-0 flex-1 truncate text-sm">{email}</span>
<InviteeStatusPill status={status} />
+ {status !== "sending" && inviteUrl ? (
+ <InviteeRowMenu email={email} status={status} inviteUrl={inviteUrl} />
+ ) : null}
</li>
);
}
diff --git a/apps/web/src/features/poll/invite/data.ts b/apps/web/src/features/poll/invite/data.ts
index 68249a00c..7dc1024f1 100644
--- a/apps/web/src/features/poll/invite/data.ts
+++ b/apps/web/src/features/poll/invite/data.ts
@@ -13,6 +13,7 @@ export async function listPollInvites({ pollId }: { pollId: string }) {
select: {
id: true,
email: true,
+ token: true,
openedAt: true,
participantId: true,
createdAt: true,
diff --git a/apps/web/src/features/poll/invite/loaders.ts b/apps/web/src/features/poll/invite/loaders.ts
index dc46cb106..163a76f1b 100644
--- a/apps/web/src/features/poll/invite/loaders.ts
+++ b/apps/web/src/features/poll/invite/loaders.ts
@@ -1,10 +1,14 @@
import "server-only";
+import { absoluteUrl } from "@rallly/utils/absolute-url";
import { cache } from "react";
import { hasPollAdminAccess } from "@/features/poll/data";
import { listPollInvites } from "@/features/poll/invite/data";
import type { PollInviteListItem } from "@/features/poll/invite/types";
-import { derivePollInviteStatus } from "@/features/poll/invite/utils";
+import {
+ derivePollInviteStatus,
+ getPollInvitePath,
+} from "@/features/poll/invite/utils";
import { getCurrentUser } from "@/features/user/loaders";
/**
@@ -26,6 +30,9 @@ export const loadPollInvites = cache(
id: invite.id,
email: invite.email,
status: derivePollInviteStatus(invite),
+ inviteUrl: absoluteUrl(
+ getPollInvitePath({ pollId, token: invite.token }),
+ ),
}));
},
);
diff --git a/apps/web/src/features/poll/invite/mutations.ts b/apps/web/src/features/poll/invite/mutations.ts
index f67ad66ea..489c6c0c9 100644
--- a/apps/web/src/features/poll/invite/mutations.ts
+++ b/apps/web/src/features/poll/invite/mutations.ts
@@ -9,6 +9,7 @@ import { getInstanceBranding, getSpaceBranding } from "@/emails/branding";
import { resolveSpaceTier } from "@/features/billing/utils";
import { recordPollActivities } from "@/features/poll/activity/mutations";
import { MAX_POLL_INVITES_PER_DAY } from "@/features/poll/invite/constants";
+import { getPollInvitePath } from "@/features/poll/invite/utils";
const logger = createLogger("poll/invite/mutations");
@@ -189,7 +190,7 @@ export async function sendPollInvite({
props: {
hostName: sender.name,
pollTitle: poll.title,
- inviteUrl: absoluteUrl(`/invite/${pollId}?invite=${token}`),
+ inviteUrl: absoluteUrl(getPollInvitePath({ pollId, token })),
},
});
} catch (error) {
diff --git a/apps/web/src/features/poll/invite/types.ts b/apps/web/src/features/poll/invite/types.ts
index c0011da68..27472572f 100644
--- a/apps/web/src/features/poll/invite/types.ts
+++ b/apps/web/src/features/poll/invite/types.ts
@@ -4,4 +4,5 @@ export type PollInviteListItem = {
id: string;
email: string;
status: PollInviteStatus;
+ inviteUrl: string;
};
diff --git a/apps/web/src/features/poll/invite/utils.test.ts b/apps/web/src/features/poll/invite/utils.test.ts
index 4994e9711..eee465b46 100644
--- a/apps/web/src/features/poll/invite/utils.test.ts
+++ b/apps/web/src/features/poll/invite/utils.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
-import { derivePollInviteStatus } from "./utils";
+import { derivePollInviteStatus, getPollInvitePath } from "./utils";
describe("derivePollInviteStatus", () => {
it("is sent when nothing has happened", () => {
@@ -32,3 +32,11 @@ describe("derivePollInviteStatus", () => {
).toBe("responded");
});
});
+
+describe("getPollInvitePath", () => {
+ it("builds the per invitee path the email and the host copy share", () => {
+ expect(getPollInvitePath({ pollId: "poll1", token: "AbC123" })).toBe(
+ "/invite/poll1?invite=AbC123",
+ );
+ });
+});
diff --git a/apps/web/src/features/poll/invite/utils.ts b/apps/web/src/features/poll/invite/utils.ts
index 8084eda30..78af89901 100644
--- a/apps/web/src/features/poll/invite/utils.ts
+++ b/apps/web/src/features/poll/invite/utils.ts
@@ -17,3 +17,17 @@ export function derivePollInviteStatus(invite: {
}
return "sent";
}
+
+/**
+ * The per invitee link, relative. Shared by the email and the host's copy
+ * action so the two can never point at different places.
+ */
+export function getPollInvitePath({
+ pollId,
+ token,
+}: {
+ pollId: string;
+ token: string;
+}) {
+ return `/invite/${pollId}?invite=${token}`;
+}
diff --git a/apps/web/tests/email-invites.spec.ts b/apps/web/tests/email-invites.spec.ts
index 3f34fb8f2..baec21de5 100644
--- a/apps/web/tests/email-invites.spec.ts
+++ b/apps/web/tests/email-invites.spec.ts
@@ -93,6 +93,20 @@ test.describe("Email invites", () => {
// Replies reach the host, not the From address.
expect(email.ReplyTo.map((address) => address.Address)).toEqual([PRO_HOST]);
+ // The row menu copies the same personal link the email carried, so a
+ // host reaching the invitee another way keeps the response attributed.
+ const emailedUrl = email.HTML.match(
+ /href="([^"]*\/invite\/[^"]*invite=[^"]*)"/,
+ )?.[1];
+ await row.getByRole("button", { name: `Options for ${INVITEE}` }).click();
+ await page.getByRole("menuitem", { name: "Copy personal link" }).click();
+ await expect(
+ page.getByText(`Personal link for ${INVITEE} copied`),
+ ).toBeVisible();
+ expect(await page.evaluate("navigator.clipboard.readText()")).toBe(
+ emailedUrl,
+ );
+
// Same address again is refused without sending.
await field.fill(INVITEE);
await field.press("Enter");
@@ -106,13 +120,10 @@ test.describe("Email invites", () => {
// Opening the emailed link records the open once: a second visit
// neither moves the timestamp nor adds another activity event.
- const inviteUrl = email.HTML.match(
- /href="([^"]*\/invite\/[^"]*invite=[^"]*)"/,
- )?.[1];
- expect(inviteUrl).toBeTruthy();
+ expect(emailedUrl).toBeTruthy();
const browser = page.context().browser();
expect(browser).toBeTruthy();
- const guest = await openAsGuest(browser as Browser, inviteUrl as string);
+ const guest = await openAsGuest(browser as Browser, emailedUrl as string);
const invite = await prisma.pollInvite.findFirstOrThrow({
where: { email: INVITEE, poll: { title: POLL_TITLE } },
select: { id: true },
@@ -132,7 +143,9 @@ test.describe("Email invites", () => {
});
await guest.guestPage.reload();
- await expect(guest.guestPage.getByText(POLL_TITLE)).toBeVisible();
+ await expect(
+ guest.guestPage.getByRole("heading", { name: POLL_TITLE }),
+ ).toBeVisible();
const openedRow = (await reopenShareDialog(page))
.getByRole("listitem")