Skip to content

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

💄 Reframe comments as a legacy opt-in setting (#2819)

Luke Vella3d2ecb2c582b
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index 2a36cb559..13549e01a 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -132,6 +132,10 @@
"commandMenuSearchPlaceholder": "Type a command or search...",
"commentPlaceholder": "Leave a comment on this poll (visible to everyone)",
"comments": "Comments",
+ "commentsSettingDescription": "Let participants post public comments on the poll.",
+ "commentsSettingLegacyBadge": "Legacy",
+ "commentsSettingPhaseOutHint": "Comments are being phased out. Participants can include a note with their response instead.",
+ "commentsSettingTitle": "Comments",
"common_language": "Language",
"configuredByEnvironmentVariable": "This setting has been configured by environment variable.",
"confirm": "Confirm",
@@ -220,8 +224,6 @@
"descriptionPlaceholder": "Hey everyone, please choose the dates that work for you!",
"descriptionTooLong": "Description must be at most {count} characters",
"developer": "Developer",
- "disableCommentsDescription": "Remove the option to leave comments on the poll.",
- "disableCommentsTitle": "Disable comments",
"disabled": "Disabled",
"disconnectCalendar": "Disconnect calendar",
"disconnectingCalendar": "Disconnecting calendar...",
diff --git a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-settings/page.tsx b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-settings/page.tsx
index 24a8458c9..68ff95832 100644
--- a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-settings/page.tsx
+++ b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-settings/page.tsx
@@ -28,7 +28,7 @@ const Page = () => {
defaultValues: {
hideParticipants: poll.hideParticipants,
hideScores: poll.hideScores,
- disableComments: poll.disableComments,
+ enableComments: !poll.disableComments,
requireParticipantEmail: poll.requireParticipantEmail,
},
});
@@ -36,11 +36,11 @@ const Page = () => {
return (
<Form {...form}>
<form
- onSubmit={form.handleSubmit(async (data) => {
- //submit
+ onSubmit={form.handleSubmit(async ({ enableComments, ...data }) => {
const res = await update.mutateAsync({
pollId: poll.id,
...data,
+ disableComments: !enableComments,
});
if (res.ok) {
redirectBackToPoll();
diff --git a/apps/web/src/features/poll/components/create-poll.tsx b/apps/web/src/features/poll/components/create-poll.tsx
index a6ccf3a85..4682d1d2a 100644
--- a/apps/web/src/features/poll/components/create-poll.tsx
+++ b/apps/web/src/features/poll/components/create-poll.tsx
@@ -72,7 +72,7 @@ export const CreatePoll: React.FunctionComponent = () => {
options: [],
hideScores: false,
hideParticipants: false,
- disableComments: true,
+ enableComments: false,
duration: 60,
lockTimeZone: false,
allDay: false,
@@ -107,7 +107,7 @@ export const CreatePoll: React.FunctionComponent = () => {
? formData?.timeZone || getBrowserTimeZone()
: null,
hideParticipants: formData?.hideParticipants,
- disableComments: formData?.disableComments,
+ disableComments: !formData?.enableComments,
hideScores: formData?.hideScores,
requireParticipantEmail: formData?.requireParticipantEmail,
options: required(formData?.options).map((option) => ({
diff --git a/apps/web/src/features/poll/components/forms/poll-settings.test.tsx b/apps/web/src/features/poll/components/forms/poll-settings.test.tsx
new file mode 100644
index 000000000..703df088a
--- /dev/null
+++ b/apps/web/src/features/poll/components/forms/poll-settings.test.tsx
@@ -0,0 +1,63 @@
+import { Form } from "@rallly/ui/form";
+import userEvent from "@testing-library/user-event";
+import { useForm } from "react-hook-form";
+import { describe, expect, it, vi } from "vitest";
+import { PollSettingsForm } from "@/features/poll/components/forms/poll-settings";
+import type { PollSettingsFormData } from "@/features/poll/components/forms/types";
+import { render, screen } from "@/test/test-utils";
+
+vi.mock("@rallly/posthog/client", () => ({
+ posthog: { capture: vi.fn() },
+}));
+
+vi.mock("@/features/billing/client", () => ({
+ useIsFree: () => false,
+ showPayWall: vi.fn(),
+}));
+
+function TestForm({ enableComments = false }: { enableComments?: boolean }) {
+ const form = useForm<PollSettingsFormData>({
+ defaultValues: {
+ enableComments,
+ requireParticipantEmail: false,
+ hideParticipants: false,
+ hideScores: false,
+ },
+ });
+ return (
+ <Form {...form}>
+ <PollSettingsForm />
+ </Form>
+ );
+}
+
+describe("PollSettingsForm comments setting", () => {
+ it("shows comments off by default with a legacy badge and no hint", () => {
+ render(<TestForm />);
+ const commentsSwitch = screen.getByRole("switch", { name: /comments/i });
+ expect(commentsSwitch).not.toBeChecked();
+ expect(screen.getByText("Legacy")).toBeInTheDocument();
+ expect(
+ screen.queryByText(/comments are being phased out/i),
+ ).not.toBeInTheDocument();
+ });
+
+ it("reveals the phase out hint when comments are switched on", async () => {
+ const user = userEvent.setup();
+ render(<TestForm />);
+ const commentsSwitch = screen.getByRole("switch", { name: /comments/i });
+ await user.click(commentsSwitch);
+ expect(commentsSwitch).toBeChecked();
+ expect(
+ screen.getByText(/participants can include a note with their response/i),
+ ).toBeInTheDocument();
+ });
+
+ it("shows the hint immediately for polls that already have comments enabled", () => {
+ render(<TestForm enableComments={true} />);
+ expect(screen.getByRole("switch", { name: /comments/i })).toBeChecked();
+ expect(
+ screen.getByText(/comments are being phased out/i),
+ ).toBeInTheDocument();
+ });
+});
diff --git a/apps/web/src/features/poll/components/forms/poll-settings.tsx b/apps/web/src/features/poll/components/forms/poll-settings.tsx
index 568a86321..3dd374987 100644
--- a/apps/web/src/features/poll/components/forms/poll-settings.tsx
+++ b/apps/web/src/features/poll/components/forms/poll-settings.tsx
@@ -1,4 +1,5 @@
import { posthog } from "@rallly/posthog/client";
+import { Badge } from "@rallly/ui/badge";
import {
Card,
CardContent,
@@ -8,7 +9,13 @@ import {
} from "@rallly/ui/card";
import { FormField } from "@rallly/ui/form";
import { Switch } from "@rallly/ui/switch";
-import { AtSignIcon, EyeIcon, MessageCircleIcon, VoteIcon } from "lucide-react";
+import {
+ AtSignIcon,
+ EyeIcon,
+ InfoIcon,
+ MessageCircleIcon,
+ VoteIcon,
+} from "lucide-react";
import React from "react";
import { useFormContext } from "react-hook-form";
import { showPayWall, useIsFree } from "@/features/billing/client";
@@ -66,11 +73,6 @@ const PollSetting = ({
showPayWall({ from: "poll-settings", setting: name });
} else {
field.onChange(checked);
- if (name === "disableComments") {
- posthog?.capture("poll_settings:comments_toggle_click", {
- enabled: !checked,
- });
- }
}
}}
/>
@@ -80,6 +82,73 @@ const PollSetting = ({
);
};
+const CommentsSetting = () => {
+ const form = useFormContext<PollSettingsFormData>();
+ const titleId = React.useId();
+ const descriptionId = React.useId();
+ const hintId = React.useId();
+
+ return (
+ <FormField
+ control={form.control}
+ name="enableComments"
+ render={({ field }) => (
+ // biome-ignore lint/a11y/noLabelWithoutControl: switch is rendered inside
+ <label className="flex cursor-pointer select-none items-start gap-x-3 rounded-xl border bg-card p-3 hover:bg-card-accent">
+ <MessageCircleIcon className="size-4 shrink-0 translate-y-0.5 text-muted-foreground" />
+ <div className="grow">
+ <div
+ id={titleId}
+ className="flex items-center gap-x-2 font-medium text-sm"
+ >
+ <Trans i18nKey="commentsSettingTitle" defaults="Comments" />
+ <Badge size="sm">
+ <Trans i18nKey="commentsSettingLegacyBadge" defaults="Legacy" />
+ </Badge>
+ </div>
+ <div
+ id={descriptionId}
+ className="mt-1 text-muted-foreground text-xs"
+ >
+ <Trans
+ i18nKey="commentsSettingDescription"
+ defaults="Let participants post public comments on the poll."
+ />
+ </div>
+ {field.value ? (
+ <div
+ id={hintId}
+ className="mt-2 flex items-start gap-x-1.5 text-muted-foreground text-xs"
+ >
+ <InfoIcon className="size-3.5 shrink-0 translate-y-px" />
+ <span>
+ <Trans
+ i18nKey="commentsSettingPhaseOutHint"
+ defaults="Comments are being phased out. Participants can include a note with their response instead."
+ />
+ </span>
+ </div>
+ ) : null}
+ </div>
+ <Switch
+ aria-labelledby={titleId}
+ aria-describedby={
+ field.value ? `${descriptionId} ${hintId}` : descriptionId
+ }
+ checked={!!field.value}
+ onCheckedChange={(checked) => {
+ field.onChange(checked);
+ posthog?.capture("poll_settings:comments_toggle_click", {
+ enabled: checked,
+ });
+ }}
+ />
+ </label>
+ )}
+ />
+ );
+};
+
export const PollSettingsForm = ({ children }: React.PropsWithChildren) => {
return (
<Card>
@@ -102,22 +171,6 @@ export const PollSettingsForm = ({ children }: React.PropsWithChildren) => {
</CardHeader>
<CardContent>
<div className="grid gap-2.5">
- <PollSetting
- name="disableComments"
- icon={MessageCircleIcon}
- title={
- <Trans
- i18nKey="disableCommentsTitle"
- defaults="Disable comments"
- />
- }
- description={
- <Trans
- i18nKey="disableCommentsDescription"
- defaults="Remove the option to leave comments on the poll."
- />
- }
- />
<PollSetting
name="requireParticipantEmail"
icon={AtSignIcon}
@@ -164,6 +217,7 @@ export const PollSettingsForm = ({ children }: React.PropsWithChildren) => {
/>
}
/>
+ <CommentsSetting />
</div>
</CardContent>
{children}
diff --git a/apps/web/src/features/poll/components/forms/types.ts b/apps/web/src/features/poll/components/forms/types.ts
index 9cf4608f3..7b82fe874 100644
--- a/apps/web/src/features/poll/components/forms/types.ts
+++ b/apps/web/src/features/poll/components/forms/types.ts
@@ -20,7 +20,7 @@ export type PollSettingsFormData = {
requireParticipantEmail: boolean;
hideParticipants: boolean;
hideScores: boolean;
- disableComments: boolean;
+ enableComments: boolean;
};
export type NewEventData = PollDetailsData &
diff --git a/apps/web/src/test/setup.ts b/apps/web/src/test/setup.ts
index a634e98ac..ee43eec05 100644
--- a/apps/web/src/test/setup.ts
+++ b/apps/web/src/test/setup.ts
@@ -2,6 +2,22 @@ import "@testing-library/jest-dom/vitest";
import "@/lib/dayjs";
import { vi } from "vitest";
+// jsdom has no PointerEvent; Base UI references it in pointer handlers
+if (!window.PointerEvent) {
+ class PointerEventPolyfill extends MouseEvent {
+ pointerId: number;
+ pointerType: string;
+ constructor(type: string, params: PointerEventInit = {}) {
+ super(type, params);
+ this.pointerId = params.pointerId ?? 0;
+ this.pointerType = params.pointerType ?? "";
+ }
+ }
+ window.PointerEvent =
+ PointerEventPolyfill as unknown as typeof window.PointerEvent;
+ globalThis.PointerEvent = window.PointerEvent;
+}
+
// Mock next-themes to avoid SSR issues
vi.mock("next-themes", () => ({
useTheme: () => ({
diff --git a/apps/web/tests/new-poll-page.ts b/apps/web/tests/new-poll-page.ts
index 3b160aa2d..d5704319d 100644
--- a/apps/web/tests/new-poll-page.ts
+++ b/apps/web/tests/new-poll-page.ts
@@ -52,8 +52,8 @@ export class NewPollPage {
await page.getByText("15", { exact: true }).first().click();
if (enableComments) {
- // Comments are off by default; turn the "Disable comments" setting off
- await page.getByRole("switch", { name: /disable comments/i }).click();
+ // Comments are off by default; opt in to the legacy comments setting
+ await page.getByRole("switch", { name: /comments/i }).click();
}
await page.getByRole("button", { name: /create poll/i }).click();