Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
✨ Tell each participant how they voted in the finalize email (#3437)
Luke Vella091c4c41b16c
diff --git a/apps/web/src/features/scheduled-event/data.ts b/apps/web/src/features/scheduled-event/data.tsindex 9510885ef..ee6df08e0 100644--- a/apps/web/src/features/scheduled-event/data.ts+++ b/apps/web/src/features/scheduled-event/data.ts@@ -568,6 +568,7 @@ export function getInviteEmailData({ uid }: { uid: string }) {inviteeEmail: true,inviteeLocale: true,inviteeTimeZone: true,+ status: true,scheduledEvent: {select: {id: true,diff --git a/apps/web/src/features/scheduled-event/mutations.ts b/apps/web/src/features/scheduled-event/mutations.tsindex 3021206a1..224caac98 100644--- a/apps/web/src/features/scheduled-event/mutations.ts+++ b/apps/web/src/features/scheduled-event/mutations.ts@@ -94,6 +94,15 @@ export async function cancelRsvp({ inviteUid }: { inviteUid: string }) {const failWith = (message: string) => () => new QueuedEmailFailed({ message });+// The invitee's vote on the booked option, recorded on the invite when the+// poll was finalized. Pending means they never voted on it.+const voteByInviteStatus = {+ accepted: "yes",+ tentative: "ifNeedBe",+ declined: "no",+ pending: undefined,+} as const satisfies Record<ScheduledEventInviteStatus, string | undefined>;+/*** The queue handler for `scheduled_event_invite`: tells one invitee their* event is booked, built from the invite (the subject, by uid) and its event@@ -191,6 +200,7 @@ export const sendScheduledEventInviteEmail = Effect.fn(: undefined,date,time,+ vote: voteByInviteStatus[invite.status],},}),catch: (cause) =>diff --git a/apps/web/src/trpc/routers/polls.ts b/apps/web/src/trpc/routers/polls.tsindex ff56a4f44..8149e4eb1 100644--- a/apps/web/src/trpc/routers/polls.ts+++ b/apps/web/src/trpc/routers/polls.ts@@ -1275,14 +1275,20 @@ export const polls = router({// A poll can have several participants sharing an email; an event holds at// most one invite per email, so collapse them, keeping the most committal- // response (accepted > tentative > declined) so a stale "no" duplicate- // can't bury an "accepted".+ // response (accepted > tentative > declined > pending) so a stale "no"+ // duplicate can't bury an "accepted". No vote on the option is pending,+ // not declined: the invitee never answered.const inviteStatusByVote = {yes: "accepted",ifNeedBe: "tentative",no: "declined",} as const;- const inviteStatusRank = { accepted: 0, tentative: 1, declined: 2 };+ const inviteStatusRank = {+ accepted: 0,+ tentative: 1,+ declined: 2,+ pending: 3,+ };const invitesByEmail = new Map<string,{@@ -1291,7 +1297,7 @@ export const polls = router({inviteeEmail: string;inviteeTimeZone: string | null | undefined;inviteeLocale: string | null;- status: (typeof inviteStatusByVote)[keyof typeof inviteStatusByVote];+ status: keyof typeof inviteStatusRank;}>();// An address is emailed when any participant behind it was selected.@@ -1303,10 +1309,8 @@ export const polls = router({);for (const p of poll.participants) {if (!p.email) continue;- const status =- inviteStatusByVote[- p.votes.find((v) => v.optionId === input.optionId)?.type ?? "no"- ];+ const vote = p.votes.find((v) => v.optionId === input.optionId)?.type;+ const status = vote ? inviteStatusByVote[vote] : "pending";const key = p.email.trim().toLowerCase();const existing = invitesByEmail.get(key);if (diff --git a/packages/emails/locales/en/emails.json b/packages/emails/locales/en/emails.jsonindex b766e20a4..004ad440c 100644--- a/packages/emails/locales/en/emails.json+++ b/packages/emails/locales/en/emails.json@@ -42,6 +42,9 @@"finalizeParticipant_heading": "Final date booked!","finalizeParticipant_preview": "Final date booked!","finalizeParticipant_subject": "Date booked for {title}",+ "finalizeParticipant_voteIfNeedBe": "You voted <b>If need be</b> for this date.",+ "finalizeParticipant_voteNo": "You voted <b>No</b> for this date.",+ "finalizeParticipant_voteYes": "You voted <b>Yes</b> for this date.","license_key_activationSteps": "Follow these <a>instructions</a> to activate your license on your Rallly Self-Hosted instance.","license_key_content": "Your purchase has been confirmed and your license key has been generated.","license_key_heading": "License confirmation",diff --git a/packages/emails/src/templates/finalized-participant.test.tsx b/packages/emails/src/templates/finalized-participant.test.tsxnew file mode 100644index 000000000..79c91bccc--- /dev/null+++ b/packages/emails/src/templates/finalized-participant.test.tsx@@ -0,0 +1,37 @@+import { render } from "@react-email/render";+import { describe, expect, it } from "vitest";+import { previewChrome } from "../components/preview-chrome";+import FinalizeParticipantEmail from "./finalized-participant";++const baseProps = {+ title: "Team Meeting",+ hostName: "Jane Doe",+ pollUrl: "https://rallly.co/invite/abc",+ date: "Friday, 12 June 2026",+ time: "6:00 PM to 7:00 PM BST",+ chrome: previewChrome,+};++// Text only: styled components put inline styles on every tag.+async function renderText(props: { vote?: "yes" | "ifNeedBe" | "no" } = {}) {+ const html = await render(+ await FinalizeParticipantEmail({ ...baseProps, ...props }),+ );+ return html.replace(/<[^>]+>/g, "");+}++describe("FinalizeParticipantEmail", () => {+ it.each([+ ["yes", "Yes"],+ ["ifNeedBe", "If need be"],+ ["no", "No"],+ ] as const)("states a %s vote on the booked date", async (vote, label) => {+ const text = await renderText({ vote });+ expect(text).toContain(`You voted ${label} for this date.`);+ });++ it("omits the vote line when the invitee didn't vote", async () => {+ const text = await renderText();+ expect(text).not.toContain("You voted");+ });+});diff --git a/packages/emails/src/templates/finalized-participant.tsx b/packages/emails/src/templates/finalized-participant.tsxindex b7909c770..a6705f170 100644--- a/packages/emails/src/templates/finalized-participant.tsx+++ b/packages/emails/src/templates/finalized-participant.tsx@@ -28,6 +28,8 @@ type FinalizeParticipantEmailProps = {pollUrl: string;location?: string;conferencing?: EmailConferencing;+ /** Their vote on the booked date; omitted when they didn't vote on it. */+ vote?: "yes" | "ifNeedBe" | "no";};async function FinalizeParticipantEmail({@@ -38,6 +40,7 @@ async function FinalizeParticipantEmail({time,location,conferencing,+ vote,locale = "en",chrome,}: FinalizeParticipantEmailProps) {@@ -84,6 +87,42 @@ async function FinalizeParticipantEmail({baseUrl={chrome.baseUrl}locale={locale}/>+ {vote === "yes" ? (+ <Text>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="finalizeParticipant_voteYes"+ defaults="You voted <b>Yes</b> for this date."+ components={{ b: <Strong /> }}+ />+ </Text>+ ) : null}+ {vote === "ifNeedBe" ? (+ <Text>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="finalizeParticipant_voteIfNeedBe"+ defaults="You voted <b>If need be</b> for this date."+ components={{ b: <Strong /> }}+ />+ </Text>+ ) : null}+ {vote === "no" ? (+ <Text>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="finalizeParticipant_voteNo"+ defaults="You voted <b>No</b> for this date."+ components={{ b: <Strong /> }}+ />+ </Text>+ ) : null}<Text>{t("finalizeParticipant_content2", {defaultValue:@@ -118,6 +157,7 @@ FinalizeParticipantEmail.PreviewProps = {provider: "meet",url: "https://meet.google.com/oce-zdyd-aoq",},+ vote: "no",locale: "en",chrome: previewChrome,} as FinalizeParticipantEmailProps;