Skip to content

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

✨ Add success dialog when creating a poll (#2281)

Luke Vella5cfb82ce545e
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index eac18b41f..92085f20e 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -617,5 +617,7 @@
"timezoneInputPlaceholder": "Search timezone…",
"cityTime": "{city} Time",
"unmuteNotifications": "Unmute notifications",
- "muteNotifications": "Mute notifications"
+ "muteNotifications": "Mute notifications",
+ "creatingPoll": "Creating poll...",
+ "createPollPollCreated": "Poll created"
}
diff --git a/apps/web/src/components/create-poll.tsx b/apps/web/src/components/create-poll.tsx
index 4a83c2553..1ad2bad0b 100644
--- a/apps/web/src/components/create-poll.tsx
+++ b/apps/web/src/components/create-poll.tsx
@@ -1,4 +1,6 @@
"use client";
+import { usePostHog } from "@rallly/posthog/client";
+import { buttonVariants } from "@rallly/ui";
import { Button } from "@rallly/ui/button";
import {
Card,
@@ -7,13 +9,29 @@ import {
CardHeader,
CardTitle,
} from "@rallly/ui/card";
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from "@rallly/ui/dialog";
import { Form } from "@rallly/ui/form";
+import {
+ InputGroup,
+ InputGroupAddon,
+ InputGroupButton,
+ InputGroupInput,
+} from "@rallly/ui/input-group";
import { toast } from "@rallly/ui/sonner";
-import { useRouter } from "next/navigation";
-import type React from "react";
+import { shortUrl } from "@rallly/utils/absolute-url";
+import { CheckIcon, CopyIcon } from "lucide-react";
+import Link from "next/link";
+import React from "react";
import { useForm } from "react-hook-form";
import useFormPersist from "react-hook-form-persist";
-import { useUnmount } from "react-use";
+import { useCopyToClipboard, useUnmount } from "react-use";
import { PollSettingsForm } from "@/components/forms/poll-settings";
import { useUser } from "@/components/user-provider";
import { Trans, useTranslation } from "@/i18n/client";
@@ -37,9 +55,13 @@ export interface CreatePollPageProps {
}
export const CreatePoll: React.FunctionComponent = () => {
- const router = useRouter();
const { t } = useTranslation();
+ const posthog = usePostHog();
const { createGuestIfNeeded } = useUser();
+ const [createdPollId, setCreatedPollId] = React.useState<string | null>(null);
+ const [, copy] = useCopyToClipboard();
+ const [didCopy, setDidCopy] = React.useState(false);
+
const form = useForm<NewEventData>({
defaultValues: {
title: "",
@@ -85,7 +107,7 @@ export const CreatePoll: React.FunctionComponent = () => {
});
if (res.ok) {
- router.push(`/poll/${res.data.id}`);
+ setCreatedPollId(res.data.id);
} else {
toast.error(
t("inappropriateContent", {
@@ -135,10 +157,89 @@ export const CreatePoll: React.FunctionComponent = () => {
className="w-full"
variant="primary"
>
- <Trans i18nKey="createPoll" defaults="Create poll" />
+ {form.formState.isSubmitting ? (
+ <Trans i18nKey="creatingPoll" defaults="Creating poll..." />
+ ) : (
+ <Trans i18nKey="createPoll" defaults="Create poll" />
+ )}
</Button>
</div>
</form>
+ <Dialog open={!!createdPollId}>
+ <DialogContent showCloseButton={false}>
+ <DialogHeader>
+ <div className="flex flex-col items-center gap-4 text-center">
+ <div className="p-2">
+ <div className="inline-flex size-10 items-center justify-center rounded-full bg-green-500/10">
+ <CheckIcon className="size-4 text-green-500" />
+ </div>
+ </div>
+ <div>
+ <DialogTitle>
+ <Trans
+ i18nKey="createPollPollCreated"
+ defaults="Poll created"
+ />
+ </DialogTitle>
+ <DialogDescription>
+ <Trans
+ i18nKey="inviteParticipantsDescription"
+ defaults="Copy and share the invite link to start gathering responses from your participants."
+ />
+ </DialogDescription>
+ </div>
+ </div>
+ </DialogHeader>
+ <InputGroup className="w-full">
+ <InputGroupInput
+ className="text-center"
+ value={shortUrl(`/invite/${createdPollId}`)}
+ readOnly
+ />
+ <InputGroupAddon align="inline-end">
+ <InputGroupButton
+ variant="ghost"
+ size="icon-xs"
+ disabled={didCopy}
+ aria-label={
+ didCopy
+ ? t("copied", { defaultValue: "Copied" })
+ : t("copyLink", { defaultValue: "Copy link" })
+ }
+ onClick={() => {
+ copy(shortUrl(`/invite/${createdPollId}`));
+ setDidCopy(true);
+ setTimeout(() => setDidCopy(false), 2000);
+ posthog?.capture("poll_creation:invite_link_copy");
+ }}
+ >
+ {didCopy ? <CheckIcon /> : <CopyIcon />}
+ </InputGroupButton>
+ </InputGroupAddon>
+ </InputGroup>
+ <DialogFooter className="grid grid-cols-2 gap-2">
+ <Link
+ href={`/poll/${createdPollId}`}
+ className={buttonVariants({ variant: "primary" })}
+ onClick={() => {
+ posthog?.capture("poll_creation:manage_button_click");
+ }}
+ >
+ <Trans i18nKey="manage" defaults="Manage" />
+ </Link>
+
+ <Link
+ href={`/invite/${createdPollId}`}
+ className={buttonVariants()}
+ onClick={() => {
+ posthog?.capture("poll_creation:view_button_click");
+ }}
+ >
+ <Trans i18nKey="viewPoll" defaults="View poll" />
+ </Link>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
</Form>
);
};
diff --git a/apps/web/src/components/invite-dialog.tsx b/apps/web/src/components/invite-dialog.tsx
index ac7a950f6..a4a7d7934 100644
--- a/apps/web/src/components/invite-dialog.tsx
+++ b/apps/web/src/components/invite-dialog.tsx
@@ -14,7 +14,6 @@ import Link from "next/link";
import React from "react";
import { useCopyToClipboard } from "react-use";
-import { useParticipants } from "@/components/participants-provider";
import { usePoll } from "@/contexts/poll";
import { Trans } from "@/i18n/client";
@@ -51,8 +50,7 @@ export function CopyInviteLinkButton() {
}
export const InviteDialog = () => {
- const { participants } = useParticipants();
- const [isOpen, setIsOpen] = React.useState(participants.length === 0);
+ const [isOpen, setIsOpen] = React.useState(false);
const poll = usePoll();
return (
diff --git a/apps/web/tests/create-delete-poll.spec.ts b/apps/web/tests/create-delete-poll.spec.ts
index 072014ca5..73e892414 100644
--- a/apps/web/tests/create-delete-poll.spec.ts
+++ b/apps/web/tests/create-delete-poll.spec.ts
@@ -13,8 +13,9 @@ test.describe.serial(() => {
test("create a new poll", async () => {
const newPollPage = new NewPollPage(page);
-
- await newPollPage.createPollAndCloseDialog({ name: "Monthly Meetup" });
+ await newPollPage.goto();
+ const dialog = await newPollPage.create({ name: "Monthly Meetup" });
+ await dialog.goToPollPage();
await expect(page.getByTestId("poll-title")).toHaveText("Monthly Meetup");
});
diff --git a/apps/web/tests/edit-options.spec.ts b/apps/web/tests/edit-options.spec.ts
index a6ab172a4..c2ed20b41 100644
--- a/apps/web/tests/edit-options.spec.ts
+++ b/apps/web/tests/edit-options.spec.ts
@@ -11,9 +11,8 @@ test.describe("edit options", () => {
page = await browser.newPage();
const newPollPage = new NewPollPage(page);
await newPollPage.goto();
- const pollPage = await newPollPage.createPollAndCloseDialog({
- name: "Monthly Meetup",
- });
+ const dialog = await newPollPage.create({ name: "Monthly Meetup" });
+ const pollPage = await dialog.goToPollPage();
await pollPage.addParticipant("Mark");
editOptionsPage = await pollPage.editOptions();
});
diff --git a/apps/web/tests/guest-to-user-migration.spec.ts b/apps/web/tests/guest-to-user-migration.spec.ts
index 855c5ed42..22e9d9508 100644
--- a/apps/web/tests/guest-to-user-migration.spec.ts
+++ b/apps/web/tests/guest-to-user-migration.spec.ts
@@ -30,7 +30,9 @@ test.describe.serial(() => {
}) => {
// Step 1: Create a poll as guest
const newPollPage = new NewPollPage(page);
- await newPollPage.createPollAndCloseDialog({ name: "Monthly Meetup" });
+ await newPollPage.goto();
+ const dialog = await newPollPage.create({ name: "Monthly Meetup" });
+ await dialog.goToPollPage();
await expect(page.getByTestId("poll-title")).toHaveText("Monthly Meetup");
// Step 2: Navigate to registration
@@ -49,7 +51,9 @@ test.describe.serial(() => {
}) => {
// Step 1: Create a poll as guest
const newPollPage = new NewPollPage(page);
- await newPollPage.createPollAndCloseDialog({ name: "Board Meeting" });
+ await newPollPage.goto();
+ const dialog = await newPollPage.create({ name: "Board Meeting" });
+ await dialog.goToPollPage();
await expect(page.getByTestId("poll-title")).toHaveText("Board Meeting");
// Step 2: Navigate to registration
diff --git a/apps/web/tests/new-poll-page.ts b/apps/web/tests/new-poll-page.ts
index bc4d3ec21..2047ddefe 100644
--- a/apps/web/tests/new-poll-page.ts
+++ b/apps/web/tests/new-poll-page.ts
@@ -1,6 +1,20 @@
-import type { Page } from "@playwright/test";
+import type { Locator, Page } from "@playwright/test";
import { PollPage } from "tests/poll-page";
+export class CreatePollSuccessDialog {
+ constructor(private readonly page: Page) {}
+
+ get dialog(): Locator {
+ return this.page.getByRole("dialog");
+ }
+
+ async goToPollPage() {
+ await this.page.getByRole("link", { name: "Manage" }).click();
+ await this.page.waitForURL(/\/poll\/[^/]+/);
+ return new PollPage(this.page);
+ }
+}
+
export class NewPollPage {
constructor(public readonly page: Page) {}
@@ -8,34 +22,26 @@ export class NewPollPage {
await this.page.goto("/new");
}
- async createPollAndCloseDialog({ name }: { name: string }) {
- await this.goto();
- const pollPage = await this.createPoll({ name });
- await pollPage.closeDialog();
- return pollPage;
- }
- async createPoll({ name }: { name: string }) {
+ async create({ name }: { name: string }): Promise<CreatePollSuccessDialog> {
const page = this.page;
- await page.fill('[placeholder="Monthly Meetup"]', name);
- // click on label to focus on input
- await page.click('text="Location"');
- await page.keyboard.type("Online");
-
- await page.click('text="Description"');
-
- await page.keyboard.type("Hey everyone, what time can you meet?");
+ await page.getByLabel(/title|event/i).fill(name);
+ await page.getByLabel("Location").fill("Online");
+ await page
+ .getByLabel("Description")
+ .fill("Hey everyone, what time can you meet?");
- await page.click('[title="Next month"]');
+ await page.getByTitle("Next month").click();
- // Select a few days
- await page.click("text=/^5$/");
- await page.click("text=/^7$/");
- await page.click("text=/^10$/");
- await page.click("text=/^15$/");
+ await page.getByText("5", { exact: true }).first().click();
+ await page.getByText("7", { exact: true }).first().click();
+ await page.getByText("10", { exact: true }).first().click();
+ await page.getByText("15", { exact: true }).first().click();
- await page.click('text="Create Poll"');
+ await page.getByRole("button", { name: /create poll/i }).click();
- return new PollPage(page);
+ const successDialog = new CreatePollSuccessDialog(page);
+ await successDialog.dialog.waitFor({ state: "visible" });
+ return successDialog;
}
}
diff --git a/apps/web/tests/vote-and-comment.spec.ts b/apps/web/tests/vote-and-comment.spec.ts
index 4063a60fc..7316ec15e 100644
--- a/apps/web/tests/vote-and-comment.spec.ts
+++ b/apps/web/tests/vote-and-comment.spec.ts
@@ -1,6 +1,5 @@
import type { Page } from "@playwright/test";
import { expect, test } from "@playwright/test";
-import { prisma } from "@rallly/database";
import { captureOne } from "@rallly/test-helpers";
import { load } from "cheerio";
import type { PollPage } from "tests/poll-page";
@@ -14,13 +13,11 @@ test.describe(() => {
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
- await page.clock.install();
const newPollPage = new NewPollPage(page);
await newPollPage.goto();
- pollPage = await newPollPage.createPollAndCloseDialog({
- name: "Monthly Meetup",
- });
+ const dialog = await newPollPage.create({ name: "Monthly Meetup" });
+ pollPage = await dialog.goToPollPage();
// Extract the poll ID from the URL
const url = page.url();
@@ -29,46 +26,6 @@ test.describe(() => {
expect(pollId).not.toBe("");
});
- test("should record poll view", async () => {
- // Fast forward time to trigger view tracking
- await page.clock.fastForward(5000);
-
- let pollViews: Array<{
- id: string;
- pollId: string;
- ipAddress: string | null;
- userId: string | null;
- userAgent: string | null;
- viewedAt: Date;
- }> = [];
-
- // Retry until we find poll views or timeout
- await expect(async () => {
- // Query the database for poll views
- pollViews = await prisma.pollView.findMany({
- where: {
- pollId,
- },
- orderBy: {
- viewedAt: "desc",
- },
- });
-
- // This will throw if the condition is not met, causing a retry
- expect(pollViews.length).toBeGreaterThan(0);
- }).toPass({
- timeout: 5000, // 5 second timeout
- intervals: [100, 200, 500, 1000], // Retry intervals in milliseconds
- });
-
- // Now that we know we have at least one poll view, verify its properties
- const latestView = pollViews[0];
- expect(latestView.pollId).toBe(pollId);
- expect(latestView.ipAddress).toBeDefined();
- expect(latestView.userAgent).toBeDefined();
- expect(latestView.viewedAt).toBeDefined();
- });
-
test("should be able to comment", async () => {
await pollPage.addComment();
const comment = page.locator("data-testid=comment");
diff --git a/packages/tailwind-config/shared-styles.css b/packages/tailwind-config/shared-styles.css
index 275a805f3..f51e64863 100644
--- a/packages/tailwind-config/shared-styles.css
+++ b/packages/tailwind-config/shared-styles.css
@@ -36,7 +36,7 @@
--action-bar-foreground: var(--color-gray-100);
--muted: var(--color-gray-100);
- --muted-foreground: var(--color-gray-600);
+ --muted-foreground: var(--color-gray-500);
--muted-border: var(--color-gray-200);
--popover: var(--color-white);
diff --git a/packages/ui/src/dialog.tsx b/packages/ui/src/dialog.tsx
index d193009c4..89796c364 100644
--- a/packages/ui/src/dialog.tsx
+++ b/packages/ui/src/dialog.tsx
@@ -102,13 +102,7 @@ function DialogContent({
}
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
- return (
- <div
- data-slot="dialog-header"
- className={cn("flex flex-col gap-2 sm:text-left", className)}
- {...props}
- />
- );
+ return <div data-slot="dialog-header" className={cn(className)} {...props} />;
}
function DialogFooter({ className, ...props }: React.ComponentProps<"div">) {
@@ -144,7 +138,7 @@ function DialogDescription({
return (
<DialogPrimitive.Description
data-slot="dialog-description"
- className={cn("text-muted-foreground text-sm", className)}
+ className={cn("mt-2 text-muted-foreground text-sm", className)}
{...props}
/>
);