Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
✨ Let hosts remove a pending invite from the Share dialog (#3180)
Luke Vellaf58b281b3d73
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.jsonindex d0be31037..571933c89 100644--- a/apps/web/public/locales/en/app.json+++ b/apps/web/public/locales/en/app.json@@ -778,11 +778,13 @@"shareDialogGuestPrompt": "Create an account to invite people by email. Your invites and their responses stay attached to your account instead of this browser.","shareDialogInvalidEmail": "Enter a single valid email address","shareDialogInvitedCount": "{count, plural, one {# invited} other {# invited}}",+ "shareDialogInviteRemoved": "Invite for {email} removed","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",+ "shareDialogRemoveInvite": "Remove invite","shareDialogSendFailed": "Couldn't send to {email}. Try again.","shareDialogSendInvite": "Send invite","showParticipantVotes": "Show participant votes",diff --git a/apps/web/src/features/poll/components/invite-by-email.tsx b/apps/web/src/features/poll/components/invite-by-email.tsxindex d46605378..8499e7555 100644--- a/apps/web/src/features/poll/components/invite-by-email.tsx+++ b/apps/web/src/features/poll/components/invite-by-email.tsx@@ -309,6 +309,7 @@ export function InviteByEmail({ invites }: { invites: PollInviteListItem[] }) {key={row.id}email={row.email}status={row.status}+ inviteId={row.inviteUrl ? row.id : undefined}inviteUrl={row.inviteUrl}/>))}diff --git a/apps/web/src/features/poll/components/invitee-list.tsx b/apps/web/src/features/poll/components/invitee-list.tsxindex a2aef0580..42c6e7a71 100644--- a/apps/web/src/features/poll/components/invitee-list.tsx+++ b/apps/web/src/features/poll/components/invitee-list.tsx@@ -10,13 +10,20 @@ import {DropdownMenuTrigger,} from "@rallly/ui/dropdown-menu";import { toast } from "@rallly/ui/sonner";-import { LinkIcon, MailIcon, MoreHorizontalIcon } from "lucide-react";+import {+ LinkIcon,+ MailIcon,+ MoreHorizontalIcon,+ Trash2Icon,+} from "lucide-react";import React from "react";import { useCopyToClipboard } from "react-use";import { Spinner } from "@/components/spinner";import { usePoll } from "@/features/poll/client";+import { revokePollInviteAction } from "@/features/poll/invite/actions";import type { PollInviteStatus } from "@/features/poll/invite/utils";import { Trans, useTranslation } from "@/i18n/client";+import { useSafeAction } from "@/lib/safe-action/client";export type InviteeRowStatus = PollInviteStatus | "sending";@@ -57,13 +64,16 @@ 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.+ * this rather than the generic invite link. Removing is offered only while+ * the invite is pending: a converted one belongs to the response.*/function InviteeRowMenu({+ inviteId,email,status,inviteUrl,}: {+ inviteId: string;email: string;status: PollInviteStatus;inviteUrl: string;@@ -72,6 +82,32 @@ function InviteeRowMenu({const { t } = useTranslation();const [state, copyToClipboard] = useCopyToClipboard();+ // The success handler refreshes the route, which is what drops the row.+ const revoke = useSafeAction(revokePollInviteAction, {+ onSuccess: ({ data }) => {+ if (!data) return;+ if (data.ok) {+ toast(+ t("shareDialogInviteRemoved", {+ defaultValue: "Invite for {email} removed",+ email,+ }),+ );+ return;+ }+ toast.error(+ data.reason === "alreadyResponded"+ ? t("shareDialogAlreadyResponded", {+ defaultValue: "{email} has already responded",+ email,+ })+ : t("actionErrorNotFound", {+ defaultValue: "The resource was not found",+ }),+ );+ },+ });+// 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(() => {@@ -123,19 +159,31 @@ function InviteeRowMenu({defaults="Copy personal link"/></DropdownMenuItem>+ {status !== "responded" ? (+ <DropdownMenuItem+ variant="destructive"+ disabled={revoke.isPending}+ onClick={() => revoke.execute({ pollId: poll.id, inviteId })}+ >+ <Trash2Icon />+ <Trans i18nKey="shareDialogRemoveInvite" defaults="Remove invite" />+ </DropdownMenuItem>+ ) : null}</DropdownMenuContent></DropdownMenu>);}export function InviteeRow({+ inviteId,email,status,inviteUrl,}: {email: string;status: InviteeRowStatus;- // Absent while the invite is still sending and on preview rows.+ // Both absent while the invite is still sending and on preview rows.+ inviteId?: string;inviteUrl?: string;}) {return (@@ -148,8 +196,13 @@ 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} />+ {status !== "sending" && inviteId && inviteUrl ? (+ <InviteeRowMenu+ inviteId={inviteId}+ email={email}+ status={status}+ inviteUrl={inviteUrl}+ />) : null}</li>);diff --git a/apps/web/src/features/poll/invite/actions.ts b/apps/web/src/features/poll/invite/actions.tsindex be0ce5b75..0d7c06488 100644--- a/apps/web/src/features/poll/invite/actions.ts+++ b/apps/web/src/features/poll/invite/actions.ts@@ -3,10 +3,12 @@import { hasPollAdminAccess } from "@/features/poll/data";import {recordPollInviteOpen,+ revokePollInvite,sendPollInvite,} from "@/features/poll/invite/mutations";import {recordPollInviteOpenSchema,+ revokePollInviteSchema,sendPollInviteSchema,} from "@/features/poll/invite/schema";import { AppError } from "@/lib/errors/app-error";@@ -54,6 +56,38 @@ export const sendPollInviteAction = authActionClientreturn result;});+export const revokePollInviteAction = authActionClient+ .metadata({ actionName: "revoke_poll_invite" })+ .inputSchema(revokePollInviteSchema)+ .action(async ({ ctx, parsedInput }) => {+ const { pollId, inviteId } = parsedInput;++ if (!(await hasPollAdminAccess(pollId, ctx.user.id))) {+ throw new AppError({ code: "NOT_FOUND", message: "Poll not found" });+ }++ const result = await revokePollInvite({+ pollId,+ inviteId,+ userId: ctx.user.id,+ });++ track(+ { id: ctx.user.id, isGuest: false },+ {+ event: "poll_share:invite_revoke",+ properties: {+ poll_id: pollId,+ ok: result.ok,+ reason: result.ok ? undefined : result.reason,+ },+ groups: { poll: pollId },+ },+ );++ return result;+ });+// Public: invitees are not users, and the token from the emailed link is the// credential. The mutation ignores tokens it does not recognise.export const recordPollInviteOpenAction = actionClientdiff --git a/apps/web/src/features/poll/invite/mutations.ts b/apps/web/src/features/poll/invite/mutations.tsindex 489c6c0c9..e71a77035 100644--- a/apps/web/src/features/poll/invite/mutations.ts+++ b/apps/web/src/features/poll/invite/mutations.ts@@ -316,3 +316,61 @@ export async function recordPollInviteOpen({return true;});}++export type RevokePollInviteResult =+ | { ok: true }+ | { ok: false; reason: "notFound" | "alreadyResponded" };++/**+ * Removes a pending invite from the host's list. The row is kept and+ * stamped rather than deleted so its token stops resolving and a later+ * re-invite reactivates it with a fresh token. A converted invite belongs+ * to the response, so it is refused here; the host removes the response+ * instead. The claim on `revokedAt IS NULL` serialises concurrent removes+ * so the activity event is written once.+ */+export async function revokePollInvite({+ pollId,+ inviteId,+ userId,+}: {+ pollId: string;+ inviteId: string;+ userId: string;+}): Promise<RevokePollInviteResult> {+ return prisma.$transaction(async (tx) => {+ const invite = await tx.pollInvite.findFirst({+ where: { id: inviteId, pollId, revokedAt: null },+ select: { id: true, email: true, participantId: true },+ });++ if (!invite) {+ return { ok: false, reason: "notFound" };+ }++ if (invite.participantId) {+ return { ok: false, reason: "alreadyResponded" };+ }++ const { count } = await tx.pollInvite.updateMany({+ where: { id: invite.id, revokedAt: null, participantId: null },+ data: { revokedAt: new Date() },+ });++ if (count === 0) {+ return { ok: false, reason: "notFound" };+ }++ await recordPollActivities(tx, [+ {+ pollId,+ type: "invite_revoked",+ userId,+ inviteId: invite.id,+ payload: { email: invite.email },+ },+ ]);++ return { ok: true };+ });+}diff --git a/apps/web/src/features/poll/invite/schema.ts b/apps/web/src/features/poll/invite/schema.tsindex 51f4a020a..7bfa2fee5 100644--- a/apps/web/src/features/poll/invite/schema.ts+++ b/apps/web/src/features/poll/invite/schema.ts@@ -11,3 +11,8 @@ export const recordPollInviteOpenSchema = z.object({pollId: z.string().min(1),token: z.string().min(1),});++export const revokePollInviteSchema = z.object({+ pollId: z.string().min(1),+ inviteId: z.string().min(1),+});diff --git a/apps/web/tests/email-invites.spec.ts b/apps/web/tests/email-invites.spec.tsindex baec21de5..9c3171359 100644--- a/apps/web/tests/email-invites.spec.ts+++ b/apps/web/tests/email-invites.spec.ts@@ -202,6 +202,28 @@ test.describe("Email invites", () => {await expect(page).toHaveURL(/\/poll\/[^/?]+$/);await expect(dialog).toBeVisible();+ // Removing a pending invite drops the row and stops its token; sending+ // to the same address again reactivates it.+ await row.getByRole("button", { name: `Options for ${INVITEE}` }).click();+ await page.getByRole("menuitem", { name: "Remove invite" }).click();+ await expect(page.getByText(`Invite for ${INVITEE} removed`)).toBeVisible();+ await expect(row).toBeHidden();+ await expect(dialog.getByText("No one invited yet")).toBeVisible();+ const revoked = await prisma.pollInvite.findFirstOrThrow({+ where: { email: INVITEE, poll: { title: `${POLL_TITLE} Clean URL` } },+ select: { id: true, revokedAt: true },+ });+ expect(revoked.revokedAt).not.toBeNull();+ expect(+ await prisma.pollActivity.count({+ where: { inviteId: revoked.id, type: "invite_revoked" },+ }),+ ).toBe(1);++ await field.fill(INVITEE);+ await field.press("Enter");+ await expect(row.getByText("Sent")).toBeVisible();+await page.reload();await expect(page.getByRole("button", { name: "Share" })).toBeVisible();await expect(dialog).toBeHidden();diff --git a/packages/database/prisma/models/poll.prisma b/packages/database/prisma/models/poll.prismaindex a15c90ae9..54049c2f8 100644--- a/packages/database/prisma/models/poll.prisma+++ b/packages/database/prisma/models/poll.prisma@@ -104,10 +104,10 @@ model PollInvite {openedAt DateTime? @map("opened_at")remindedAt DateTime? @map("reminded_at")- /// Revocation is always explicit: set on host revoke and on close/schedule, never as a side effect. Deleting a response (by anyone) clears participantId instead, reverting the invite to pending with its token intact. Never cleared by reopen; cleared only by re-inviting (reactivation)+ /// Revocation is always explicit: set when the host removes a pending invite, never as a side effect of close, schedule or reopen. Deleting a response clears participantId instead, reverting the invite to pending with its token intact. Cleared only by re-inviting (reactivation), which also rotates the tokenrevokedAt DateTime? @map("revoked_at")- /// Conversion join, merges invite history into the response timeline. Set when the invitee responds via their token, or when a generic link response's email matches a pending invite (citext) — responding always consumes the invite+ /// Conversion join, merges invite history into the response timeline. Set only when the invitee responds via their token: a typed email is unverified, so a generic link response never claims an inviteparticipantId String? @unique @map("participant_id")createdAt DateTime @default(now()) @map("created_at")