Skip to content

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

✨ Allow hosts to copy participant edit links (#3225)

Luke Vellac0278ada49d4
diff --git a/apps/docs/guide/participant-guide.mdx b/apps/docs/guide/participant-guide.mdx
index 426b247b2..ad7378c06 100644
--- a/apps/docs/guide/participant-guide.mdx
+++ b/apps/docs/guide/participant-guide.mdx
@@ -22,7 +22,7 @@ description: "How to respond to a Rallly poll"
</Step>
<Step title="Enter your details">
- Enter your name and email address, then click **Submit**.
+ Enter your name and email address, then click **Save availability**.
<Tip>To ensure you don't lose the ability to edit your response, enter your email address to receive a confirmation email with a magic link that identifies you .</Tip>
@@ -50,13 +50,17 @@ description: "How to respond to a Rallly poll"
response. If your cookies have been deleted or you are using a different
device/browser, you may no longer be recognized as the user who created the response.
-In this case you should ask the administrator of the poll to either delete your
-response so that you can create a new one or to edit your response for you.
+In this case, ask the organizer of the poll to send you an edit link for your
+response. The organizer can copy it from the menu next to your name on the
+poll page, and opening it restores your access from any device or browser.
+Alternatively, the organizer can delete your response so that you can create a
+new one, or edit it for you.
</Accordion>
<Accordion title="How can I avoid losing access to my own response?">
If you enter your email address when you submit your response, you will
receive a confirmation email with a link that allows you to edit your response from
- anywhere.
+ anywhere. If you did not enter an email address, or no longer have the email,
+ the organizer can send you the same link.
</Accordion>
</AccordionGroup>
diff --git a/apps/docs/images/guide/voting-in-progress.png b/apps/docs/images/guide/voting-in-progress.png
index e27bba516..a6e3eaa14 100644
Binary files a/apps/docs/images/guide/voting-in-progress.png and b/apps/docs/images/guide/voting-in-progress.png differ
diff --git a/apps/docs/images/guide/voting-submitted.png b/apps/docs/images/guide/voting-submitted.png
index 3a269c175..ed5cb6c4c 100644
Binary files a/apps/docs/images/guide/voting-submitted.png and b/apps/docs/images/guide/voting-submitted.png differ
diff --git a/apps/docs/images/guide/voting-submitting.png b/apps/docs/images/guide/voting-submitting.png
index db2bafc91..211a20d92 100644
Binary files a/apps/docs/images/guide/voting-submitting.png and b/apps/docs/images/guide/voting-submitting.png differ
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index 1925b5dfe..e6be5e894 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -175,6 +175,7 @@
"copied": "Copied",
"copiedToClipboard": "Copied to clipboard",
"copy": "Copy",
+ "copyEditLink": "Copy edit link",
"copyLink": "Copy link",
"create": "Create",
"createAnAccount": "Create an account",
@@ -604,6 +605,8 @@
"paginationPage": "Page {currentPage, number} of {totalPages, number}",
"paginationPrevious": "Previous",
"participantCount": "{count, plural, =0 {No participants} one {1 participant} other {# participants}}",
+ "participantEditLinkCopied": "Edit link for {name} copied",
+ "participantEditLinkCopyFailed": "Couldn't copy the edit link. Try again.",
"participantNoteButton": "Read note from {name}",
"participants": "Participants",
"password": "Password",
diff --git a/apps/web/src/features/poll/components/desktop-poll.tsx b/apps/web/src/features/poll/components/desktop-poll.tsx
index 46a913b44..2787d27c5 100644
--- a/apps/web/src/features/poll/components/desktop-poll.tsx
+++ b/apps/web/src/features/poll/components/desktop-poll.tsx
@@ -353,6 +353,7 @@ const DesktopPoll: React.FunctionComponent = () => {
name: participant.name,
userId: participant.userId ?? undefined,
email: participant.email ?? undefined,
+ editUrl: participant.editUrl,
note: participant.note,
createdAt: participant.createdAt,
image: participant.image,
diff --git a/apps/web/src/features/poll/components/desktop-poll/participant-row.tsx b/apps/web/src/features/poll/components/desktop-poll/participant-row.tsx
index 94194275f..0fa0c984e 100644
--- a/apps/web/src/features/poll/components/desktop-poll/participant-row.tsx
+++ b/apps/web/src/features/poll/components/desktop-poll/participant-row.tsx
@@ -29,6 +29,7 @@ export interface ParticipantRowProps {
name: string;
userId?: string;
email?: string;
+ editUrl?: string | null;
note?: string | null;
createdAt: Date;
image?: string | null;
diff --git a/apps/web/src/features/poll/components/mobile-poll.tsx b/apps/web/src/features/poll/components/mobile-poll.tsx
index 7afb60f6b..f61285551 100644
--- a/apps/web/src/features/poll/components/mobile-poll.tsx
+++ b/apps/web/src/features/poll/components/mobile-poll.tsx
@@ -186,6 +186,7 @@ const MobilePoll: React.FunctionComponent = () => {
name: selectedParticipant.name,
userId: selectedParticipant.userId ?? undefined,
email: selectedParticipant.email ?? undefined,
+ editUrl: selectedParticipant.editUrl,
id: selectedParticipant.id,
}}
onEdit={() => {
diff --git a/apps/web/src/features/poll/components/mutations.ts b/apps/web/src/features/poll/components/mutations.ts
index a60909e8a..11f8e5949 100644
--- a/apps/web/src/features/poll/components/mutations.ts
+++ b/apps/web/src/features/poll/components/mutations.ts
@@ -43,7 +43,12 @@ export const useUpdateParticipantMutation = () => {
);
if (index !== -1) {
- newParticipants[index] = participant;
+ // The mutation returns the row without the host's edit link;
+ // the token behind it is unchanged, so the link is kept.
+ newParticipants[index] = {
+ ...participant,
+ editUrl: newParticipants[index].editUrl,
+ };
}
return newParticipants;
diff --git a/apps/web/src/features/poll/components/new-participant-modal.tsx b/apps/web/src/features/poll/components/new-participant-modal.tsx
index 1c2057d6b..f5d870323 100644
--- a/apps/web/src/features/poll/components/new-participant-modal.tsx
+++ b/apps/web/src/features/poll/components/new-participant-modal.tsx
@@ -310,7 +310,7 @@ export const NewParticipantForm = (props: NewParticipantModalProps) => {
<FormLabel>
{t("email")}
{!isEmailRequired
- ? ` (${t("optional", { defaultValue: "optional" })})`
+ ? ` ${t("optional", { defaultValue: "(optional)" })}`
: null}
</FormLabel>
<FormControl>
diff --git a/apps/web/src/features/poll/components/participant-dropdown.tsx b/apps/web/src/features/poll/components/participant-dropdown.tsx
index c42b1eab3..78be00f13 100644
--- a/apps/web/src/features/poll/components/participant-dropdown.tsx
+++ b/apps/web/src/features/poll/components/participant-dropdown.tsx
@@ -1,4 +1,5 @@
import { zodResolver } from "@hookform/resolvers/zod";
+import { posthog } from "@rallly/posthog/client";
import { Button } from "@rallly/ui/button";
import {
Dialog,
@@ -26,13 +27,15 @@ import {
FormMessage,
} from "@rallly/ui/form";
import { Input } from "@rallly/ui/input";
-import { PencilIcon, TagIcon, TrashIcon } from "lucide-react";
+import { toast } from "@rallly/ui/sonner";
+import { LinkIcon, PencilIcon, TagIcon, TrashIcon } from "lucide-react";
import React from "react";
import type { SubmitHandler } from "react-hook-form";
import { useForm } from "react-hook-form";
-import { useMount } from "react-use";
+import { useCopyToClipboard, useMount } from "react-use";
import * as z from "zod";
+import { usePoll } from "@/features/poll/client";
import {
useDeleteParticipantMutation,
useEditToken,
@@ -55,6 +58,8 @@ export const ParticipantDropdown = ({
userId?: string;
email?: string;
id: string;
+ // Present only in the host's list; its presence is the gate.
+ editUrl?: string | null;
};
align?: "start" | "end";
onEdit: () => void;
@@ -96,6 +101,12 @@ export const ParticipantDropdown = ({
<TagIcon />
<Trans i18nKey="changeName" defaults="Change name" />
</DropdownMenuItem>
+ {participant.editUrl ? (
+ <CopyEditLinkMenuItem
+ editUrl={participant.editUrl}
+ participantName={participant.name}
+ />
+ ) : null}
<DropdownMenuItem
variant="destructive"
onClick={() => setIsDeleteParticipantModalVisible(true)}
@@ -123,6 +134,54 @@ export const ParticipantDropdown = ({
);
};
+/**
+ * The per response edit link, for handing edit access to someone who
+ * responded without an email (or lost the confirmation email).
+ */
+const CopyEditLinkMenuItem = ({
+ editUrl,
+ participantName,
+}: {
+ editUrl: string;
+ participantName: 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("participantEditLinkCopyFailed", {
+ defaultValue: "Couldn't copy the edit link. Try again.",
+ }),
+ );
+ return;
+ }
+ if (state.value) {
+ toast(
+ t("participantEditLinkCopied", {
+ defaultValue: "Edit link for {name} copied",
+ name: participantName,
+ }),
+ );
+ posthog?.capture("poll_page:participant_edit_link_copy", {
+ poll_id: poll.id,
+ });
+ }
+ }, [state, participantName, poll.id, t]);
+
+ return (
+ <DropdownMenuItem onClick={() => copyToClipboard(editUrl)}>
+ <LinkIcon />
+ <Trans i18nKey="copyEditLink" defaults="Copy edit link" />
+ </DropdownMenuItem>
+ );
+};
+
const DeleteParticipantModal = ({
open,
onOpenChange,
diff --git a/apps/web/src/lib/auth-client.ts b/apps/web/src/lib/auth-client.ts
index 00411a9b8..babc59e40 100644
--- a/apps/web/src/lib/auth-client.ts
+++ b/apps/web/src/lib/auth-client.ts
@@ -9,6 +9,7 @@ import {
} from "better-auth/client/plugins";
import { createAuthClient } from "better-auth/react";
import type { Auth } from "@/lib/auth";
+import { clearBrowserQueryCache } from "@/lib/query-client";
export const authClient = createAuthClient({
baseURL: absoluteUrl("/api/better-auth"),
@@ -24,4 +25,5 @@ export const authClient = createAuthClient({
export async function signOut() {
await authClient.signOut();
posthog?.reset();
+ clearBrowserQueryCache();
}
diff --git a/apps/web/src/lib/query-client.ts b/apps/web/src/lib/query-client.ts
new file mode 100644
index 000000000..bdfbad35f
--- /dev/null
+++ b/apps/web/src/lib/query-client.ts
@@ -0,0 +1,17 @@
+import type { QueryClient } from "@tanstack/react-query";
+
+// The browser's one QueryClient, created by the tRPC provider. Held here so
+// sign-out can drop it without the provider having to watch for sign-out:
+// cached responses carry data the next person at this browser must not
+// see (host-only notes, un-hidden participants, response edit links).
+let browserQueryClient: QueryClient | undefined;
+
+export function registerBrowserQueryClient(client: QueryClient) {
+ if (typeof window !== "undefined") {
+ browserQueryClient = client;
+ }
+}
+
+export function clearBrowserQueryCache() {
+ browserQueryClient?.clear();
+}
diff --git a/apps/web/src/trpc/client/provider.tsx b/apps/web/src/trpc/client/provider.tsx
index 059773233..43bf7eba0 100644
--- a/apps/web/src/trpc/client/provider.tsx
+++ b/apps/web/src/trpc/client/provider.tsx
@@ -8,10 +8,11 @@ import {
QueryClientProvider,
} from "@tanstack/react-query";
import { httpBatchLink, TRPCClientError } from "@trpc/client";
-import { useState } from "react";
+import React from "react";
import superjson from "superjson";
import { useTranslation } from "@/i18n/client";
import { signOut } from "@/lib/auth-client";
+import { registerBrowserQueryClient } from "@/lib/query-client";
import { trpc } from "../client";
import type { AppRouter } from "../routers";
@@ -30,7 +31,7 @@ function isAbortError(error: TRPCClientError<AppRouter>) {
export function TRPCProvider(props: { children: React.ReactNode }) {
const { t } = useTranslation();
- const [queryClient] = useState(() => {
+ const [queryClient] = React.useState(() => {
function handleError(error: Error) {
if (!isTRPCClientError(error)) {
return;
@@ -140,7 +141,7 @@ export function TRPCProvider(props: { children: React.ReactNode }) {
}
}
- return new QueryClient({
+ const client = new QueryClient({
defaultOptions: {
queries: {
retry: false,
@@ -150,8 +151,12 @@ export function TRPCProvider(props: { children: React.ReactNode }) {
queryCache: new QueryCache({ onError: handleError }),
mutationCache: new MutationCache({ onError: handleError }),
});
+ // Sign-out refreshes the router but keeps this provider mounted, so
+ // signOut() clears the cache through this registration.
+ registerBrowserQueryClient(client);
+ return client;
});
- const [trpcClient] = useState(() =>
+ const [trpcClient] = React.useState(() =>
trpc.createClient({
links: [
httpBatchLink({
diff --git a/apps/web/src/trpc/routers/polls/participants.ts b/apps/web/src/trpc/routers/polls/participants.ts
index 27dfa2706..1a0b4b631 100644
--- a/apps/web/src/trpc/routers/polls/participants.ts
+++ b/apps/web/src/trpc/routers/polls/participants.ts
@@ -20,6 +20,7 @@ import {
attachParticipantToInvite,
findPendingPollInvite,
} from "@/features/poll/invite/mutations";
+import { getPollInvitePath } from "@/features/poll/invite/utils";
import { generateAccessToken } from "@/features/poll/utils";
import { AppError } from "@/lib/errors/app-error";
import { track } from "@/lib/posthog";
@@ -41,7 +42,8 @@ function createParticipantFullDTO(
votes: { optionId: string; type: VoteType }[];
},
) {
- // The token is the edit credential: it never leaves the server.
+ // The token is the edit credential: the list hands it back only to the
+ // host, as a ready made edit link.
const { votes, user, token: _token, ...rest } = participant;
return {
...rest,
@@ -172,12 +174,18 @@ export const participants = router({
// Response notes are visible to the host and their author only: strip
// them from every other payload rather than hiding them in the UI.
+ // The host also gets each response's edit link, the one its
+ // confirmation email carried, to hand to a respondent who left no
+ // email. Built from the same path so the two can never diverge.
const participants = rawParticipants.map((participant) => {
const dto = createParticipantFullDTO(participant);
+ const editUrl = isAdmin
+ ? absoluteUrl(getPollInvitePath({ pollId, token: participant.token }))
+ : null;
if (isAdmin || isOwn(participant)) {
- return dto;
+ return { ...dto, editUrl };
}
- return { ...dto, note: null };
+ return { ...dto, note: null, editUrl };
});
// Hide participants if the poll has hideParticipants enabled
diff --git a/apps/web/tests/vote-and-comment.spec.ts b/apps/web/tests/vote-and-comment.spec.ts
index 4c954cde9..fef3a70f9 100644
--- a/apps/web/tests/vote-and-comment.spec.ts
+++ b/apps/web/tests/vote-and-comment.spec.ts
@@ -12,7 +12,12 @@ test.describe(() => {
let pollId: string;
test.beforeAll(async ({ browser }) => {
- page = await browser.newPage();
+ // A context made here does not inherit the config's permissions, and
+ // the copy tests read the clipboard back.
+ const context = await browser.newContext({
+ permissions: ["clipboard-read"],
+ });
+ page = await context.newPage();
const newPollPage = new NewPollPage(page);
await newPollPage.goto();
@@ -74,4 +79,16 @@ test.describe(() => {
timeout: 10000,
});
});
+
+ // The host copies the same link the confirmation email carried, so a
+ // respondent who left no email can still be handed edit access.
+ test("host copies the participant's edit link", async () => {
+ await page.goto(`/poll/${pollId}`);
+ await page.getByTestId("participant-menu").click();
+ await page.getByRole("menuitem", { name: "Copy edit link" }).click();
+ await expect(page.getByText("Edit link for Anne copied")).toBeVisible();
+ expect(await page.evaluate("navigator.clipboard.readText()")).toBe(
+ editSubmissionUrl,
+ );
+ });
});
diff --git a/packages/screenshots/capture/participant-guide.spec.ts b/packages/screenshots/capture/participant-guide.spec.ts
new file mode 100644
index 000000000..d05074efa
--- /dev/null
+++ b/packages/screenshots/capture/participant-guide.spec.ts
@@ -0,0 +1,112 @@
+import path from "node:path";
+import { test } from "@playwright/test";
+import { prisma } from "@rallly/database";
+import dayjs from "dayjs";
+import timezone from "dayjs/plugin/timezone";
+import utc from "dayjs/plugin/utc";
+
+dayjs.extend(utc);
+dayjs.extend(timezone);
+
+// The browser context renders in this zone, so slots are built in it too:
+// the runner's own clock would shift every displayed time.
+const timeZone = "Europe/London";
+
+/**
+ * The three screenshots in docs/guide/participant-guide.mdx, taken as a
+ * guest walking through a response on the invite page. Written straight
+ * into the docs so a UI change is a re-run away from the guide.
+ */
+
+const pollId = "screenshot-participant-guide";
+
+const docsImage = (name: string) =>
+ path.join(__dirname, "../../../apps/docs/images/guide", `${name}.png`);
+
+test.use({
+ viewport: { width: 1182, height: 820 },
+ deviceScaleFactor: 2,
+ timezoneId: timeZone,
+});
+
+test.beforeAll(async () => {
+ await prisma.poll.delete({ where: { id: pollId } }).catch(() => {});
+
+ // Next month's second week, so the calendar header reads as one month.
+ const base = dayjs()
+ .tz(timeZone)
+ .add(1, "month")
+ .startOf("month")
+ .add(7, "day");
+ const slot = (
+ day: number,
+ hour: number,
+ minute: number,
+ duration: number,
+ ) => ({
+ startTime: base
+ .add(day, "day")
+ .hour(hour)
+ .minute(minute)
+ .second(0)
+ .toDate(),
+ duration,
+ });
+
+ await prisma.poll.create({
+ data: {
+ id: pollId,
+ title: "Monthly Meetup",
+ description: "Hey everyone, please choose the dates that work for you!",
+ location: "Joe's Coffee Shop",
+ userId: "user-1",
+ spaceId: "space-1",
+ status: "open",
+ timeZone,
+ options: {
+ create: [
+ slot(0, 13, 0, 60),
+ slot(2, 13, 30, 60),
+ slot(3, 15, 30, 60),
+ slot(4, 14, 0, 60),
+ slot(9, 12, 0, 60),
+ slot(10, 12, 0, 60),
+ ],
+ },
+ },
+ });
+});
+
+test.afterAll(async () => {
+ await prisma.poll.delete({ where: { id: pollId } }).catch(() => {});
+});
+
+test("participant guide", async ({ page }) => {
+ await page.goto(`/invite/${pollId}`);
+ await page.getByRole("heading", { name: "Monthly Meetup" }).waitFor();
+
+ const selectors = page.getByTestId("vote-selector");
+ await selectors.first().waitFor();
+ // yes, yes, no, if need be, no, yes
+ await selectors.nth(0).click();
+ await selectors.nth(1).click();
+ await selectors.nth(3).click();
+ await selectors.nth(3).click();
+ await selectors.nth(5).click();
+ await page.waitForLoadState("networkidle");
+ await page.screenshot({ path: docsImage("voting-in-progress") });
+
+ await page.getByRole("button", { name: "Continue" }).click();
+ const dialog = page.getByRole("dialog", { name: "New participant" });
+ await dialog.getByLabel("Name").fill("John Doe");
+ await dialog.getByLabel("Email").fill("[email protected]");
+ await page.screenshot({ path: docsImage("voting-submitting") });
+
+ await dialog.getByRole("button", { name: "Save availability" }).click();
+ await page.getByText("Your response has been saved").waitFor();
+ await page.getByRole("button", { name: "Back to poll" }).click();
+ await page.getByText("John Doe").waitFor();
+ await page.getByTestId("participant-menu").click();
+ await page.getByRole("menuitem", { name: "Edit votes" }).waitFor();
+ await page.screenshot({ path: docsImage("voting-submitted") });
+});