Skip to content

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

✨ Show success state with create poll CTA after new participant submits (#2734)

Luke Vella91004834a642
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index 439dacd3f..77c5e81e9 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -435,6 +435,11 @@
"new": "New",
"newEventType": "New Event Type",
"newParticipant": "New participant",
+ "newParticipantDialogBackToPoll": "Back to poll",
+ "newParticipantDialogCreatePoll": "Create your own poll",
+ "newParticipantDialogCreatePollPrompt": "Need to schedule something yourself?",
+ "newParticipantDialogSuccessDescription": "The organizer can now see your availability.",
+ "newParticipantDialogSuccessTitle": "Your response has been saved",
"newParticipantFormDescription": "Fill in the form below to submit your votes.",
"newPassword": "New Password",
"newPoll": "New Poll",
diff --git a/apps/web/src/features/poll/components/new-participant-modal.tsx b/apps/web/src/features/poll/components/new-participant-modal.tsx
index 9491b0310..ac778ddcc 100644
--- a/apps/web/src/features/poll/components/new-participant-modal.tsx
+++ b/apps/web/src/features/poll/components/new-participant-modal.tsx
@@ -1,8 +1,14 @@
import { zodResolver } from "@hookform/resolvers/zod";
import type { VoteType } from "@rallly/database";
-import { cn } from "@rallly/ui";
+import { posthog } from "@rallly/posthog/client";
+import { buttonVariants, cn } from "@rallly/ui";
import { Badge } from "@rallly/ui/badge";
import { Button } from "@rallly/ui/button";
+import {
+ DialogDescription,
+ DialogHeader,
+ DialogTitle,
+} from "@rallly/ui/dialog";
import {
Form,
FormControl,
@@ -14,13 +20,15 @@ import {
import { Input } from "@rallly/ui/input";
import { Label } from "@rallly/ui/label";
import { TRPCClientError } from "@trpc/client";
+import { CircleCheckIcon } from "lucide-react";
+import Link from "next/link";
import { useForm } from "react-hook-form";
import * as z from "zod";
import { usePoll } from "@/features/poll/client";
import { useAddParticipantMutation } from "@/features/poll/components/mutations";
import VoteIcon from "@/features/poll/components/vote-icon";
import { useUser } from "@/features/user/client";
-import { useTranslation } from "@/i18n/client";
+import { Trans, useTranslation } from "@/i18n/client";
import { useDateTimeConfig } from "@/lib/datetime/client";
const requiredEmailSchema = z.object({
@@ -110,91 +118,168 @@ export const NewParticipantForm = (props: NewParticipantModalProps) => {
const { setError, formState, handleSubmit } = form;
const addParticipant = useAddParticipantMutation();
+ if (formState.isSubmitSuccessful) {
+ return (
+ <>
+ <div className="flex flex-col items-center gap-4 py-4 text-center">
+ <CircleCheckIcon
+ aria-hidden="true"
+ className="size-10 text-green-500"
+ />
+ <DialogHeader>
+ <DialogTitle>
+ <Trans
+ i18nKey="newParticipantDialogSuccessTitle"
+ defaults="Your response has been saved"
+ />
+ </DialogTitle>
+ <DialogDescription>
+ <Trans
+ i18nKey="newParticipantDialogSuccessDescription"
+ defaults="The organizer can now see your availability."
+ />
+ </DialogDescription>
+ </DialogHeader>
+ </div>
+ <Button className="w-full" onClick={props.onCancel}>
+ <Trans
+ i18nKey="newParticipantDialogBackToPoll"
+ defaults="Back to poll"
+ />
+ </Button>
+ <div className="flex flex-col items-center text-center">
+ <p className="text-muted-foreground text-sm">
+ <Trans
+ i18nKey="newParticipantDialogCreatePollPrompt"
+ defaults="Need to schedule something yourself?"
+ />
+ </p>
+ <Link
+ href="/new"
+ className={buttonVariants({ variant: "link" })}
+ onClick={() => {
+ posthog?.capture(
+ "new_participant_dialog:create_poll_button_click",
+ {
+ pollId: poll.id,
+ spaceId: poll.spaceId,
+ tier: poll.space?.tier,
+ $groups: {
+ poll: poll.id,
+ ...(poll.spaceId ? { space: poll.spaceId } : {}),
+ },
+ },
+ );
+ }}
+ >
+ <Trans
+ i18nKey="newParticipantDialogCreatePoll"
+ defaults="Create your own poll"
+ />
+ </Link>
+ </div>
+ </>
+ );
+ }
+
return (
- <Form {...form}>
- <form
- onSubmit={handleSubmit(async (data) => {
- try {
- await createGuestIfNeeded();
- const newParticipant = await addParticipant.mutateAsync({
- name: data.name,
- votes: props.votes,
- email: data.email,
- pollId: poll.id,
- timeZone,
- });
- props.onSubmit?.(newParticipant);
- } catch (error) {
- if (error instanceof TRPCClientError) {
- setError("root", {
- message: error.message,
+ <>
+ <DialogHeader>
+ <DialogTitle>
+ <Trans i18nKey="newParticipant" defaults="New participant" />
+ </DialogTitle>
+ <DialogDescription>
+ <Trans
+ i18nKey="newParticipantFormDescription"
+ defaults="Fill in the form below to submit your votes."
+ />
+ </DialogDescription>
+ </DialogHeader>
+ <Form {...form}>
+ <form
+ onSubmit={handleSubmit(async (data) => {
+ try {
+ await createGuestIfNeeded();
+ const newParticipant = await addParticipant.mutateAsync({
+ name: data.name,
+ votes: props.votes,
+ email: data.email,
+ pollId: poll.id,
+ timeZone,
});
+ props.onSubmit?.(newParticipant);
+ } catch (error) {
+ if (error instanceof TRPCClientError) {
+ setError("root", {
+ message: error.message,
+ });
+ }
}
- }
- })}
- className="space-y-4"
- >
- <FormField
- control={form.control}
- name="name"
- render={({ field }) => (
- <FormItem>
- <FormLabel>{t("name")}</FormLabel>
- <FormControl>
- <Input
- className="w-full"
- data-1p-ignore="true"
- autoFocus={true}
- disabled={formState.isSubmitting}
- placeholder={t("namePlaceholder")}
- {...field}
- />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- <FormField
- control={form.control}
- name="email"
- render={({ field }) => (
- <FormItem>
- <FormLabel>
- {t("email")}
- {!isEmailRequired ? ` (${t("optional")})` : null}
- </FormLabel>
- <FormControl>
- <Input
- className="w-full"
- disabled={formState.isSubmitting}
- placeholder={t("emailPlaceholder")}
- {...field}
- />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
+ })}
+ className="space-y-4"
+ >
+ <FormField
+ control={form.control}
+ name="name"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>{t("name")}</FormLabel>
+ <FormControl>
+ <Input
+ className="w-full"
+ data-1p-ignore="true"
+ autoFocus={true}
+ disabled={formState.isSubmitting}
+ placeholder={t("namePlaceholder")}
+ {...field}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="email"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>
+ {t("email")}
+ {!isEmailRequired ? ` (${t("optional")})` : null}
+ </FormLabel>
+ <FormControl>
+ <Input
+ className="w-full"
+ disabled={formState.isSubmitting}
+ placeholder={t("emailPlaceholder")}
+ {...field}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
- <div className="flex flex-col gap-2">
- <Label>{t("response")}</Label>
- <VoteSummary votes={props.votes} />
- </div>
+ <div className="flex flex-col gap-2">
+ <Label>{t("response")}</Label>
+ <VoteSummary votes={props.votes} />
+ </div>
- {formState.errors.root?.message ? (
- <FormMessage>{formState.errors.root.message}</FormMessage>
- ) : null}
- <div className="mt-6 flex gap-2">
- <Button onClick={props.onCancel}>{t("cancel")}</Button>
- <Button
- type="submit"
- variant="primary"
- loading={formState.isSubmitting}
- >
- {t("submit")}
- </Button>
- </div>
- </form>
- </Form>
+ {formState.errors.root?.message ? (
+ <FormMessage>{formState.errors.root.message}</FormMessage>
+ ) : null}
+ <div className="mt-6 flex gap-2">
+ <Button onClick={props.onCancel}>{t("cancel")}</Button>
+ <Button
+ type="submit"
+ variant="primary"
+ loading={formState.isSubmitting}
+ >
+ {t("submit")}
+ </Button>
+ </div>
+ </form>
+ </Form>
+ </>
);
};
diff --git a/apps/web/src/features/poll/components/voting-form.tsx b/apps/web/src/features/poll/components/voting-form.tsx
index 849657e69..89051bae0 100644
--- a/apps/web/src/features/poll/components/voting-form.tsx
+++ b/apps/web/src/features/poll/components/voting-form.tsx
@@ -1,11 +1,6 @@
import { zodResolver } from "@hookform/resolvers/zod";
-import {
- Dialog,
- DialogContent,
- DialogDescription,
- DialogHeader,
- DialogTitle,
-} from "@rallly/ui/dialog";
+import { posthog } from "@rallly/posthog/client";
+import { Dialog, DialogContent } from "@rallly/ui/dialog";
import React from "react";
import { FormProvider, useForm, useFormContext } from "react-hook-form";
import * as z from "zod";
@@ -17,7 +12,6 @@ import {
} from "@/features/poll/components/mutations";
import { NewParticipantForm } from "@/features/poll/components/new-participant-modal";
import { useParticipants } from "@/features/poll/components/participants-provider";
-import { Trans } from "@/i18n/client";
const formSchema = z.object({
mode: z.enum(["new", "edit", "view"]),
@@ -78,7 +72,7 @@ export const useVotingForm = () => {
};
export const VotingForm = ({ children }: React.PropsWithChildren) => {
- const { id: pollId, options } = usePoll();
+ const { id: pollId, options, spaceId, space } = usePoll();
const updateParticipant = useUpdateParticipantMutation();
const token = useEditToken();
const { participants } = useParticipants();
@@ -144,14 +138,6 @@ export const VotingForm = ({ children }: React.PropsWithChildren) => {
onOpenChange={setIsNewParticipantModalOpen}
>
<DialogContent size="sm">
- <DialogHeader>
- <DialogTitle>
- <Trans i18nKey="newParticipant" />
- </DialogTitle>
- <DialogDescription>
- <Trans i18nKey="newParticipantFormDescription" />
- </DialogDescription>
- </DialogHeader>
<NewParticipantForm
votes={normalizeVotes(optionIds, form.watch("votes"))}
onSubmit={(newParticipant) => {
@@ -162,7 +148,15 @@ export const VotingForm = ({ children }: React.PropsWithChildren) => {
optionId: option.id,
})),
});
- setIsNewParticipantModalOpen(false);
+ posthog?.capture("new_participant_dialog:success_view", {
+ pollId,
+ spaceId,
+ tier: space?.tier,
+ $groups: {
+ poll: pollId,
+ ...(spaceId ? { space: spaceId } : {}),
+ },
+ });
}}
onCancel={() => setIsNewParticipantModalOpen(false)}
/>
diff --git a/apps/web/tests/invite-page.ts b/apps/web/tests/invite-page.ts
index aab10aa2d..75c0ebf8c 100644
--- a/apps/web/tests/invite-page.ts
+++ b/apps/web/tests/invite-page.ts
@@ -1,4 +1,5 @@
import type { Page } from "@playwright/test";
+import { expect } from "@playwright/test";
export class InvitePage {
constructor(public readonly page: Page) {}
@@ -16,5 +17,11 @@ export class InvitePage {
}
await page.click("text='Submit'");
+
+ await expect(page.getByText("Your response has been saved")).toBeVisible();
+ await expect(
+ page.getByRole("link", { name: "Create your own poll" }),
+ ).toHaveAttribute("href", "/new");
+ await page.click("button >> text='Back to poll'");
}
}
diff --git a/apps/web/tests/poll-page.ts b/apps/web/tests/poll-page.ts
index c9e2d72df..4f35fda8f 100644
--- a/apps/web/tests/poll-page.ts
+++ b/apps/web/tests/poll-page.ts
@@ -1,4 +1,5 @@
import type { Page } from "@playwright/test";
+import { expect } from "@playwright/test";
import { EditOptionsPage } from "./edit-options-page";
import { InvitePage } from "./invite-page";
@@ -74,6 +75,9 @@ export class PollPage {
}
await page.click("text='Submit'");
+
+ await expect(page.getByText("Your response has been saved")).toBeVisible();
+ await page.click("button >> text='Back to poll'");
}
async gotoInvitePage() {
diff --git a/packages/ui/src/dialog.tsx b/packages/ui/src/dialog.tsx
index f4b898a78..0fe428587 100644
--- a/packages/ui/src/dialog.tsx
+++ b/packages/ui/src/dialog.tsx
@@ -137,7 +137,7 @@ function DialogDescription({
<DialogPrimitive.Description
data-slot="dialog-description"
className={cn(
- "mt-0.5 text-muted-foreground text-sm leading-normal",
+ "mt-0.5 text-pretty text-muted-foreground text-sm leading-normal",
className,
)}
{...props}
diff --git a/packages/ui/src/lib/utils.ts b/packages/ui/src/lib/utils.ts
index 73803b0ce..0b170cd6a 100644
--- a/packages/ui/src/lib/utils.ts
+++ b/packages/ui/src/lib/utils.ts
@@ -1,6 +1,15 @@
import type { ClassValue } from "clsx";
import clsx from "clsx";
-import { twMerge } from "tailwind-merge";
+import { extendTailwindMerge } from "tailwind-merge";
+
+// tailwind-merge v1 predates the text-wrap utilities and misclassifies them
+// as text colors, so `cn("text-pretty text-muted-foreground")` would drop
+// `text-pretty`. Remove this once tailwind-merge is upgraded to v2+.
+const twMerge = extendTailwindMerge({
+ classGroups: {
+ "text-wrap": [{ text: ["wrap", "nowrap", "balance", "pretty"] }],
+ },
+});
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));