Skip to content

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

📈 Track who hosts notify at finalize, by vote (#3434)

Luke Vellabd48290cadba
diff --git a/apps/web/src/features/poll/components/finalize-poll-dialog.tsx b/apps/web/src/features/poll/components/finalize-poll-dialog.tsx
index 302136250..5ac44dbe8 100644
--- a/apps/web/src/features/poll/components/finalize-poll-dialog.tsx
+++ b/apps/web/src/features/poll/components/finalize-poll-dialog.tsx
@@ -1,5 +1,6 @@
"use client";
+import { posthog } from "@rallly/posthog/client";
import { cn } from "@rallly/ui";
import { Button } from "@rallly/ui/button";
import { Checkbox } from "@rallly/ui/checkbox";
@@ -318,9 +319,14 @@ function VoteShortcut({
aria-label={label}
aria-pressed={pressed}
className="inline-flex h-7 items-center gap-1.5 rounded-full border border-input border-dashed pr-3 pl-2 text-muted-foreground text-sm outline-none transition-colors hover:border-solid hover:bg-foreground/3 hover:text-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-pressed:border-foreground/15 aria-pressed:border-solid aria-pressed:bg-foreground/6 aria-pressed:text-foreground aria-pressed:hover:border-foreground/25 aria-pressed:hover:bg-foreground/10"
- onClick={() =>
- onChange(toggleIds({ selectedIds, ids, checked: !pressed }))
- }
+ onClick={() => {
+ posthog?.capture("poll_finalize:vote_shortcut_click", {
+ vote_type: voteType === "ifNeedBe" ? "if_need_be" : voteType,
+ selected: !pressed,
+ count: ids.length,
+ });
+ onChange(toggleIds({ selectedIds, ids, checked: !pressed }));
+ }}
>
<VoteIcon type={voteType} />
<span className="tabular-nums">{ids.length}</span>
@@ -380,9 +386,12 @@ function NotifyStep({
checked={allSelected}
indeterminate={!allSelected && someSelected}
disabled={notifiableIds.length === 0}
- onCheckedChange={(checked) =>
- onChange(new Set(checked ? notifiableIds : []))
- }
+ onCheckedChange={(checked) => {
+ posthog?.capture("poll_finalize:select_all_click", {
+ selected: checked,
+ });
+ onChange(new Set(checked ? notifiableIds : []));
+ }}
/>
<Label htmlFor="notify-all" className="text-sm">
<Trans
diff --git a/apps/web/src/features/poll/utils.test.ts b/apps/web/src/features/poll/utils.test.ts
index 4c178b2fb..2f4c74457 100644
--- a/apps/web/src/features/poll/utils.test.ts
+++ b/apps/web/src/features/poll/utils.test.ts
@@ -5,6 +5,7 @@ import {
getFinalizePlanGate,
maskParticipantsForViewer,
rankOptionsByPopularity,
+ summarizeNotifySelection,
toAvailabilitySpans,
} from "./utils";
@@ -308,3 +309,93 @@ describe("getFinalizePlanGate", () => {
).toBeNull();
});
});
+
+describe("summarizeNotifySelection", () => {
+ const voter = (
+ id: string,
+ type: "yes" | "ifNeedBe" | "no" | null,
+ email: string | null = `${id}@example.com`,
+ ) => ({
+ id,
+ email,
+ votes: type ? [{ optionId: "opt-1", type }] : [],
+ });
+
+ const participants = [
+ voter("a", "yes"),
+ voter("b", "yes"),
+ voter("c", "ifNeedBe"),
+ voter("d", "no"),
+ voter("e", null),
+ voter("f", "yes", null),
+ ];
+
+ it("counts eligible and selected participants by vote", () => {
+ expect(
+ summarizeNotifySelection({
+ participants,
+ optionId: "opt-1",
+ notifyParticipantIds: ["a", "c"],
+ }),
+ ).toEqual({
+ notify_eligible_yes: 2,
+ notify_eligible_if_need_be: 1,
+ notify_eligible_no: 1,
+ notify_eligible_no_response: 1,
+ notify_selected_yes: 1,
+ notify_selected_if_need_be: 1,
+ notify_selected_no: 0,
+ notify_selected_no_response: 0,
+ notify_selection_changed: true,
+ });
+ });
+
+ it("reports an untouched selection when everyone with an email is selected", () => {
+ const summary = summarizeNotifySelection({
+ participants,
+ optionId: "opt-1",
+ notifyParticipantIds: ["a", "b", "c", "d", "e"],
+ });
+ expect(summary.notify_selection_changed).toBe(false);
+ });
+
+ it("ignores participants without an email even when selected", () => {
+ const summary = summarizeNotifySelection({
+ participants,
+ optionId: "opt-1",
+ notifyParticipantIds: ["a", "b", "c", "d", "e", "f"],
+ });
+ expect(summary.notify_selected_yes).toBe(2);
+ expect(summary.notify_selection_changed).toBe(false);
+ });
+
+ it("counts participants sharing an address under their own vote", () => {
+ const summary = summarizeNotifySelection({
+ participants: [
+ voter("h", "yes", "[email protected]"),
+ voter("i", "no", "[email protected]"),
+ ],
+ optionId: "opt-1",
+ notifyParticipantIds: ["h"],
+ });
+ expect(summary.notify_selected_yes).toBe(1);
+ expect(summary.notify_selected_no).toBe(0);
+ expect(summary.notify_selection_changed).toBe(true);
+ });
+
+ it("buckets votes on other options as no response", () => {
+ const summary = summarizeNotifySelection({
+ participants: [
+ {
+ id: "g",
+ email: "[email protected]",
+ votes: [{ optionId: "opt-2", type: "yes" as const }],
+ },
+ ],
+ optionId: "opt-1",
+ notifyParticipantIds: ["g"],
+ });
+ expect(summary.notify_eligible_no_response).toBe(1);
+ expect(summary.notify_selected_no_response).toBe(1);
+ });
+});
diff --git a/apps/web/src/features/poll/utils.ts b/apps/web/src/features/poll/utils.ts
index d9c45a253..df1ccd4b9 100644
--- a/apps/web/src/features/poll/utils.ts
+++ b/apps/web/src/features/poll/utils.ts
@@ -188,6 +188,71 @@ export function rankOptionsByPopularity<T extends { id: string }>({
});
}
+const notifyBuckets = {
+ yes: "yes",
+ ifNeedBe: "if_need_be",
+ no: "no",
+} as const;
+
+type NotifyBucket =
+ | (typeof notifyBuckets)[keyof typeof notifyBuckets]
+ | "no_response";
+
+export type NotifySelectionSummary = Record<
+ `notify_eligible_${NotifyBucket}` | `notify_selected_${NotifyBucket}`,
+ number
+> & { notify_selection_changed: boolean };
+
+/**
+ * Who a host could have notified at finalize and who they selected, by vote
+ * on the chosen option, so the default selection can be judged from data.
+ * Only participants with an email can be notified. This measures the host's
+ * choice per participant, not delivery: participants sharing an address get
+ * one email, but each is counted under their own vote.
+ */
+export function summarizeNotifySelection({
+ participants,
+ optionId,
+ notifyParticipantIds,
+}: {
+ participants: {
+ id: string;
+ email: string | null;
+ votes: { optionId: string; type: VoteType }[];
+ }[];
+ optionId: string;
+ notifyParticipantIds: string[];
+}): NotifySelectionSummary {
+ const notifyIds = new Set(notifyParticipantIds);
+ const summary: NotifySelectionSummary = {
+ notify_eligible_yes: 0,
+ notify_eligible_if_need_be: 0,
+ notify_eligible_no: 0,
+ notify_eligible_no_response: 0,
+ notify_selected_yes: 0,
+ notify_selected_if_need_be: 0,
+ notify_selected_no: 0,
+ notify_selected_no_response: 0,
+ notify_selection_changed: false,
+ };
+ let eligible = 0;
+ let selected = 0;
+ for (const participant of participants) {
+ if (!participant.email) continue;
+ const vote = participant.votes.find((v) => v.optionId === optionId)?.type;
+ const bucket: NotifyBucket = vote ? notifyBuckets[vote] : "no_response";
+ summary[`notify_eligible_${bucket}`]++;
+ eligible++;
+ if (notifyIds.has(participant.id)) {
+ summary[`notify_selected_${bucket}`]++;
+ selected++;
+ }
+ }
+ // The dialog starts with everyone who has an email selected.
+ summary.notify_selection_changed = selected !== eligible;
+ return summary;
+}
+
export type FinalizePlanGate = "conferencing";
/**
diff --git a/apps/web/src/trpc/routers/polls.ts b/apps/web/src/trpc/routers/polls.ts
index 52586d894..ff56a4f44 100644
--- a/apps/web/src/trpc/routers/polls.ts
+++ b/apps/web/src/trpc/routers/polls.ts
@@ -36,7 +36,10 @@ import {
hasPollAdminAccess,
} from "@/features/poll/data";
import { MAX_POLL_DESCRIPTION_LENGTH } from "@/features/poll/schema";
-import { getFinalizePlanGate } from "@/features/poll/utils";
+import {
+ getFinalizePlanGate,
+ summarizeNotifySelection,
+} from "@/features/poll/utils";
import { formatEventDateTime } from "@/features/scheduled-event/utils";
import { getActiveSpaceForUser } from "@/features/space/data";
import type { SpaceTier } from "@/features/space/schema";
@@ -1455,6 +1458,11 @@ export const polls = router({
(Date.now() - poll.createdAt.getTime()) / 86_400_000,
),
participant_count: poll.participants.length,
+ ...summarizeNotifySelection({
+ participants: poll.participants,
+ optionId: input.optionId,
+ notifyParticipantIds: input.notifyParticipantIds,
+ }),
},
groups: {
poll: poll.id,