Skip to content

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

💄 Add response and share actions to the desktop poll empty state (#3421)

Luke Vella51dc7bdf50d7
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index ba4ecdb8b..889eea663 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -35,6 +35,7 @@
"addLicenseKey": "Add license key",
"addLocation": "Add location",
"addParticipant": "Add participant",
+ "addResponse": "Add response",
"address": "Address",
"addressPlaceholder": "123 Main Street",
"addSeats": "{count, plural, one {Add # seat} other {Add # seats}}",
@@ -293,6 +294,8 @@
"description": "Description",
"descriptionPlaceholder": "Hey everyone, please choose the dates that work for you!",
"descriptionTooLong": "Description must be at most {count} characters",
+ "desktopPollEmptyStateAddDescription": "Click <b>+</b> to add a response",
+ "desktopPollEmptyStateDescription": "Click <b>+</b> to add a response or <b>Share</b> to invite participants",
"details": "Details",
"developer": "Developer",
"disabled": "Disabled",
@@ -621,10 +624,10 @@
"noOpenPolls": "No open polls",
"noOpenPollsDescription": "Polls close automatically once all of their dates have passed. You have {count, plural, one {1 closed poll} other {# closed polls}}.",
"noOptionsDescription": "The organizer hasn't added any options yet.",
- "noParticipants": "No participants",
"noParticipantsDescription": "Click <b>Share</b> to invite participants",
"noPolls": "No polls",
"noPollsDescription": "Get started by creating a new poll.",
+ "noResponses": "No responses",
"noSeatsAvailableAlertBillingDescription": "Increase the number of seats in this space from the <a>billing page</a>.",
"noSeatsAvailableAlertSelfHostedDescription": "You will need to <a>upgrade</a> to increase the number of seats in this space.",
"noSpaces": "No spaces found",
diff --git a/apps/web/src/features/poll/components/desktop-poll.tsx b/apps/web/src/features/poll/components/desktop-poll.tsx
index 14f78e018..c62f0a179 100644
--- a/apps/web/src/features/poll/components/desktop-poll.tsx
+++ b/apps/web/src/features/poll/components/desktop-poll.tsx
@@ -4,12 +4,14 @@ import { cn } from "@rallly/ui";
import { Badge } from "@rallly/ui/badge";
import { Button } from "@rallly/ui/button";
import { Card, CardHeader, CardTitle } from "@rallly/ui/card";
+import { useDialog } from "@rallly/ui/dialog";
import { Tooltip, TooltipContent, TooltipTrigger } from "@rallly/ui/tooltip";
import {
ArrowLeftIcon,
ArrowRightIcon,
ExpandIcon,
PlusIcon,
+ Share2Icon,
ShrinkIcon,
Users2Icon,
} from "lucide-react";
@@ -21,6 +23,7 @@ import { TimesShownIn } from "@/components/clock";
import {
EmptyState,
EmptyStateDescription,
+ EmptyStateFooter,
EmptyStateIcon,
EmptyStateTitle,
} from "@/components/empty-state";
@@ -29,7 +32,9 @@ import {
useParticipants,
usePermissions,
usePoll,
+ useRole,
} from "@/features/poll/client";
+import { SharePollDialog } from "@/features/poll/components/share-dialog";
import { useVisibleParticipants } from "@/features/poll/components/visibility";
import { VotingFooter } from "@/features/poll/components/voting-footer";
import { useVotingForm } from "@/features/poll/components/voting-form";
@@ -193,6 +198,74 @@ function TableControls({
);
}
+function DesktopPollEmptyState() {
+ const poll = usePoll();
+ const role = useRole();
+ const { canAddNewParticipant } = usePermissions();
+ const votingForm = useVotingForm();
+ const shareDialog = useDialog();
+ const canShare = role === "admin";
+
+ return (
+ <EmptyState className="p-16">
+ <EmptyStateIcon>
+ <Users2Icon />
+ </EmptyStateIcon>
+ <EmptyStateTitle>
+ <Trans i18nKey="noResponses" defaults="No responses" />
+ </EmptyStateTitle>
+ {canAddNewParticipant || canShare ? (
+ <EmptyStateDescription>
+ {canAddNewParticipant && canShare ? (
+ <Trans
+ i18nKey="desktopPollEmptyStateDescription"
+ components={{ b: <strong className="font-semibold" /> }}
+ defaults="Click <b>+</b> to add a response or <b>Share</b> to invite participants"
+ />
+ ) : canAddNewParticipant ? (
+ <Trans
+ i18nKey="desktopPollEmptyStateAddDescription"
+ components={{ b: <strong className="font-semibold" /> }}
+ defaults="Click <b>+</b> to add a response"
+ />
+ ) : (
+ <Trans
+ i18nKey="noParticipantsDescription"
+ components={{ b: <strong className="font-semibold" /> }}
+ defaults="Click <b>Share</b> to invite participants"
+ />
+ )}
+ </EmptyStateDescription>
+ ) : null}
+ {canAddNewParticipant || canShare ? (
+ <EmptyStateFooter className="flex gap-2">
+ {canAddNewParticipant ? (
+ <Button onClick={() => votingForm.newParticipant()}>
+ <PlusIcon data-icon="inline-start" />
+ <Trans i18nKey="addResponse" defaults="Add response" />
+ </Button>
+ ) : null}
+ {canShare ? (
+ <>
+ <Button {...shareDialog.triggerProps}>
+ <Share2Icon data-icon="inline-start" />
+ <Trans i18nKey="share" defaults="Share" />
+ </Button>
+ <SharePollDialog
+ {...shareDialog.dialogProps}
+ pollId={poll.id}
+ pollStatus={poll.status}
+ inviteLink={poll.inviteLink}
+ source="empty_state"
+ />
+ </>
+ ) : null}
+ </EmptyStateFooter>
+ ) : null}
+ </EmptyState>
+ );
+}
+
const DesktopPoll: React.FunctionComponent = () => {
const poll = usePoll();
@@ -388,24 +461,7 @@ const DesktopPoll: React.FunctionComponent = () => {
</ScrollContainer>
</div>
) : (
- <EmptyState className="p-16">
- <EmptyStateIcon>
- <Users2Icon />
- </EmptyStateIcon>
- <EmptyStateTitle>
- <Trans
- i18nKey="noParticipants"
- defaults="No participants"
- />
- </EmptyStateTitle>
- <EmptyStateDescription>
- <Trans
- i18nKey="noParticipantsDescription"
- components={{ b: <strong className="font-semibold" /> }}
- defaults="Click <b>Share</b> to invite participants"
- />
- </EmptyStateDescription>
- </EmptyState>
+ <DesktopPollEmptyState />
)}
{mode === "new" ? (
<div className="border-t p-3">
diff --git a/apps/web/src/features/poll/components/share-dialog.tsx b/apps/web/src/features/poll/components/share-dialog.tsx
index 2a0e2a70f..4b1125483 100644
--- a/apps/web/src/features/poll/components/share-dialog.tsx
+++ b/apps/web/src/features/poll/components/share-dialog.tsx
@@ -21,6 +21,8 @@ import type { PollStatus } from "@/features/poll/schema";
import { Trans } from "@/i18n/client";
import { useFlash } from "@/lib/flash/client";
+type ShareSource = "poll_created" | "manual" | "empty_state";
+
export function ShareDialog({
pollId,
pollStatus,
@@ -31,10 +33,8 @@ export function ShareDialog({
inviteLink: string;
}) {
const dialog = useDialog();
- const isFree = useIsFree();
- const isOpen = dialog.dialogProps.open;
const sharePollFlash = useFlash(SHARE_POLL_FLASH_KEY);
- const openSource = React.useRef<"poll_created" | "manual">("manual");
+ const [source, setSource] = React.useState<ShareSource>("manual");
// The create page flashes the new poll's id so this dialog is the
// confirmation. The flash is consumed on read, so refresh and back don't
@@ -43,46 +43,79 @@ export function ShareDialog({
// biome-ignore lint/correctness/useExhaustiveDependencies: runs once per flash arrival
React.useEffect(() => {
if (sharePollFlash !== pollId) return;
- openSource.current = "poll_created";
+ setSource("poll_created");
dialog.trigger();
}, [sharePollFlash]);
- React.useEffect(() => {
- if (!isOpen) return;
- posthog?.capture("poll_share:dialog_open", {
- poll_id: pollId,
- tier: isFree ? "free" : "pro",
- source: openSource.current,
- });
- openSource.current = "manual";
- }, [isOpen, pollId, isFree]);
-
return (
<>
- <Button variant="primary" {...dialog.triggerProps}>
+ <Button
+ variant="primary"
+ {...dialog.triggerProps}
+ onClick={() => {
+ setSource("manual");
+ dialog.trigger();
+ }}
+ >
<Share2Icon data-icon="inline-start" />
<span className="sr-only sm:not-sr-only">
<Trans i18nKey="share" defaults="Share" />
</span>
</Button>
- <Dialog {...dialog.dialogProps}>
- <DialogContent size="lg" data-testid="invite-participant-dialog">
- <DialogHeader>
- <DialogTitle>
- <Trans i18nKey="share" defaults="Share" />
- </DialogTitle>
- <DialogDescription>
- <Trans
- i18nKey="shareDialogDescription"
- defaults="Share the invite link, or invite people by email."
- />
- </DialogDescription>
- </DialogHeader>
- <InviteLinkRow pollId={pollId} inviteLink={inviteLink} />
- <Separator />
- <InviteByEmail pollId={pollId} pollStatus={pollStatus} />
- </DialogContent>
- </Dialog>
+ <SharePollDialog
+ {...dialog.dialogProps}
+ pollId={pollId}
+ pollStatus={pollStatus}
+ inviteLink={inviteLink}
+ source={source}
+ />
</>
);
}
+
+export function SharePollDialog({
+ pollId,
+ pollStatus,
+ inviteLink,
+ source,
+ ...dialogProps
+}: React.ComponentProps<typeof Dialog> & {
+ pollId: string;
+ pollStatus: PollStatus;
+ inviteLink: string;
+ source: ShareSource;
+}) {
+ const isFree = useIsFree();
+ const isOpen = dialogProps.open;
+
+ // biome-ignore lint/correctness/useExhaustiveDependencies: capture once per open
+ React.useEffect(() => {
+ if (!isOpen) return;
+ posthog?.capture("poll_share:dialog_open", {
+ poll_id: pollId,
+ tier: isFree ? "free" : "pro",
+ source,
+ });
+ }, [isOpen]);
+
+ return (
+ <Dialog {...dialogProps}>
+ <DialogContent size="lg" data-testid="invite-participant-dialog">
+ <DialogHeader>
+ <DialogTitle>
+ <Trans i18nKey="share" defaults="Share" />
+ </DialogTitle>
+ <DialogDescription>
+ <Trans
+ i18nKey="shareDialogDescription"
+ defaults="Share the invite link, or invite people by email."
+ />
+ </DialogDescription>
+ </DialogHeader>
+ <InviteLinkRow pollId={pollId} inviteLink={inviteLink} />
+ <Separator />
+ <InviteByEmail pollId={pollId} pollStatus={pollStatus} />
+ </DialogContent>
+ </Dialog>
+ );
+}
diff --git a/apps/web/tests/email-invites.spec.ts b/apps/web/tests/email-invites.spec.ts
index 6c69a36db..dbdfce97e 100644
--- a/apps/web/tests/email-invites.spec.ts
+++ b/apps/web/tests/email-invites.spec.ts
@@ -87,7 +87,7 @@ async function deleteResponse(page: Page, name: string) {
async function reopenShareDialog(page: Page) {
await page.reload();
- await page.getByRole("button", { name: "Share" }).click();
+ await page.getByRole("button", { name: "Share" }).first().click();
return page.getByRole("dialog", { name: "Share" });
}
@@ -321,7 +321,9 @@ test.describe("Email invites", () => {
await expect(row.getByText("Sent")).toBeVisible();
await page.reload();
- await expect(page.getByRole("button", { name: "Share" })).toBeVisible();
+ await expect(
+ page.getByRole("button", { name: "Share" }).first(),
+ ).toBeVisible();
await expect(dialog).toBeHidden();
});
diff --git a/apps/web/tests/poll-page.ts b/apps/web/tests/poll-page.ts
index b8c6de9b4..8bcb5c140 100644
--- a/apps/web/tests/poll-page.ts
+++ b/apps/web/tests/poll-page.ts
@@ -27,7 +27,7 @@ export class PollPage {
async openShareDialog() {
const dialog = this.page.getByRole("dialog", { name: "Share" });
if (!(await dialog.isVisible())) {
- await this.page.getByRole("button", { name: "Share" }).click();
+ await this.page.getByRole("button", { name: "Share" }).first().click();
}
await expect(dialog).toBeVisible();
return dialog;