Skip to content

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

💄 Use icon buttons in the poll header on mobile (#3544)

Luke Vella49ceee51fadb
diff --git a/apps/web/src/features/poll/components/manage-poll.tsx b/apps/web/src/features/poll/components/manage-poll.tsx
index 811a4f33f..be48da3d7 100644
--- a/apps/web/src/features/poll/components/manage-poll.tsx
+++ b/apps/web/src/features/poll/components/manage-poll.tsx
@@ -8,10 +8,10 @@ import {
DropdownMenuTrigger,
} from "@rallly/ui/dropdown-menu";
import {
- ChevronDownIcon,
CircleStopIcon,
CopyIcon,
DownloadIcon,
+ MoreHorizontalIcon,
PencilIcon,
PlayIcon,
TrashIcon,
@@ -27,7 +27,7 @@ import {
getOpenPollLimitRefusal,
showOpenPollLimit,
} from "@/features/poll/limit/client";
-import { Trans } from "@/i18n/client";
+import { Trans, useTranslation } from "@/i18n/client";
import { trpc } from "@/trpc/client";
import { DeletePollDialog } from "./manage-poll/delete-poll-dialog";
import { useCsvExporter } from "./manage-poll/use-csv-exporter";
@@ -80,6 +80,7 @@ const ManagePoll: React.FunctionComponent<{
disabled?: boolean;
}> = ({ disabled }) => {
const poll = usePoll();
+ const { t } = useTranslation();
const [showDeletePollDialog, setShowDeletePollDialog] = React.useState(false);
const duplicateDialog = useDialog();
@@ -94,12 +95,16 @@ const ManagePoll: React.FunctionComponent<{
<>
<DropdownMenu modal={false}>
<DropdownMenuTrigger
- render={<Button variant="ghost" disabled={disabled} />}
+ render={
+ <Button
+ variant="ghost"
+ size="icon"
+ aria-label={t("manage", { defaultValue: "Manage" })}
+ disabled={disabled}
+ />
+ }
>
- <span>
- <Trans i18nKey="manage" />
- </span>
- <ChevronDownIcon data-icon="inline-end" />
+ <MoreHorizontalIcon />
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
{canEdit ? (
diff --git a/apps/web/src/features/poll/components/poll-primary-actions.tsx b/apps/web/src/features/poll/components/poll-primary-actions.tsx
index 12b35bf54..249d5bdb3 100644
--- a/apps/web/src/features/poll/components/poll-primary-actions.tsx
+++ b/apps/web/src/features/poll/components/poll-primary-actions.tsx
@@ -3,45 +3,121 @@
import { posthog } from "@rallly/posthog/client";
import { Button } from "@rallly/ui/button";
import { useDialog } from "@rallly/ui/dialog";
-import { CalendarCheck2Icon } from "lucide-react";
+import { CalendarCheck2Icon, Share2Icon } from "lucide-react";
+import * as React from "react";
import { usePoll } from "@/features/poll/client";
import { FinalizePollDialog } from "@/features/poll/components/finalize-poll-dialog";
-import { ShareDialog } from "@/features/poll/components/share-dialog";
-import { Trans } from "@/i18n/client";
+import {
+ SharePollDialog,
+ useSharePollDialog,
+} from "@/features/poll/components/share-dialog";
+import { SHARE_POLL_FLASH_KEY } from "@/features/poll/constants";
+import { Trans, useTranslation } from "@/i18n/client";
+import { useFlash } from "@/lib/flash/client";
+
+type ActionBarProps = {
+ canFinalize: boolean;
+ onShare: () => void;
+ onFinalize: () => void;
+};
+
+/**
+ * Finalize is the call to action for as long as there is something to
+ * finalize; a new poll opens the share dialog on its own, so Share stays
+ * secondary here.
+ */
+function DesktopActionBar({
+ canFinalize,
+ onShare,
+ onFinalize,
+}: ActionBarProps) {
+ return (
+ <>
+ <Button variant={canFinalize ? "default" : "primary"} onClick={onShare}>
+ <Share2Icon data-icon="inline-start" />
+ <Trans i18nKey="share" defaults="Share" />
+ </Button>
+ {canFinalize ? (
+ <Button variant="primary" onClick={onFinalize}>
+ <CalendarCheck2Icon data-icon="inline-start" />
+ <Trans i18nKey="finalize" defaults="Finalize" />
+ </Button>
+ ) : null}
+ </>
+ );
+}
+
+function MobileActionBar({ canFinalize, onShare, onFinalize }: ActionBarProps) {
+ const { t } = useTranslation();
+ return (
+ <>
+ <Button
+ variant={canFinalize ? "default" : "primary"}
+ size="icon"
+ aria-label={t("share", { defaultValue: "Share" })}
+ onClick={onShare}
+ >
+ <Share2Icon />
+ </Button>
+ {canFinalize ? (
+ <Button
+ variant="primary"
+ size="icon"
+ aria-label={t("finalize", { defaultValue: "Finalize" })}
+ onClick={onFinalize}
+ >
+ <CalendarCheck2Icon />
+ </Button>
+ ) : null}
+ </>
+ );
+}
/**
- * The header's two actions. Finalize is the call to action for as long as
- * there is something to finalize; a new poll opens the share dialog on its
- * own, so Share stays secondary here.
+ * The header's share and finalize actions. Both bars render and CSS picks
+ * one, so the server markup is right for either screen size; the dialogs
+ * live outside the bars so each mounts once.
*/
export function PollPrimaryActions() {
const poll = usePoll();
+ const share = useSharePollDialog(poll.id);
const finalizeDialog = useDialog();
+ const sharePollFlash = useFlash(SHARE_POLL_FLASH_KEY);
const canFinalize = poll.status === "open" || poll.status === "closed";
+ // The create page flashes the new poll's id so the share dialog is the
+ // confirmation. The flash is consumed on read, so refresh and back don't
+ // reopen it. Keyed on the flash alone so a later poll id change can't
+ // replay it.
+ // biome-ignore lint/correctness/useExhaustiveDependencies: runs once per flash arrival
+ React.useEffect(() => {
+ if (sharePollFlash !== poll.id) return;
+ share.open("poll_created");
+ }, [sharePollFlash]);
+
+ const actionBarProps: ActionBarProps = {
+ canFinalize,
+ onShare: () => share.open("manual"),
+ onFinalize: () => {
+ posthog?.capture("poll_finalize:dialog_open");
+ finalizeDialog.trigger();
+ },
+ };
+
return (
<>
- <ShareDialog
+ <div className="contents sm:hidden">
+ <MobileActionBar {...actionBarProps} />
+ </div>
+ <div className="hidden sm:contents">
+ <DesktopActionBar {...actionBarProps} />
+ </div>
+ <SharePollDialog
+ {...share.dialog.dialogProps}
pollId={poll.id}
pollStatus={poll.status}
inviteLink={poll.inviteLink}
- variant={canFinalize ? "default" : "primary"}
/>
- {canFinalize ? (
- <Button
- variant="primary"
- {...finalizeDialog.triggerProps}
- onClick={() => {
- posthog?.capture("poll_finalize:dialog_open");
- finalizeDialog.trigger();
- }}
- >
- <CalendarCheck2Icon data-icon="inline-start" />
- <span className="sr-only sm:not-sr-only">
- <Trans i18nKey="finalize" defaults="Finalize" />
- </span>
- </Button>
- ) : null}
<FinalizePollDialog {...finalizeDialog.dialogProps} />
</>
);
diff --git a/apps/web/src/features/poll/components/share-dialog.tsx b/apps/web/src/features/poll/components/share-dialog.tsx
index ea04d727c..466a8a10f 100644
--- a/apps/web/src/features/poll/components/share-dialog.tsx
+++ b/apps/web/src/features/poll/components/share-dialog.tsx
@@ -1,7 +1,6 @@
"use client";
import { posthog } from "@rallly/posthog/client";
-import { Button } from "@rallly/ui/button";
import {
Dialog,
DialogContent,
@@ -11,15 +10,12 @@ import {
useDialog,
} from "@rallly/ui/dialog";
import { Separator } from "@rallly/ui/separator";
-import { Share2Icon } from "lucide-react";
-import React from "react";
+import type React from "react";
import { useIsFree } from "@/features/billing/client";
import { InviteByEmail } from "@/features/poll/components/invite-by-email";
import { InviteLinkRow } from "@/features/poll/components/invite-link-row";
-import { SHARE_POLL_FLASH_KEY } from "@/features/poll/constants";
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";
@@ -40,52 +36,6 @@ export function useSharePollDialog(pollId: string) {
return { dialog, open };
}
-export function ShareDialog({
- pollId,
- pollStatus,
- inviteLink,
- variant = "primary",
-}: {
- pollId: string;
- pollStatus: PollStatus;
- inviteLink: string;
- variant?: "primary" | "default";
-}) {
- const { dialog, open } = useSharePollDialog(pollId);
- const sharePollFlash = useFlash(SHARE_POLL_FLASH_KEY);
-
- // 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
- // reopen it. Keyed on the flash alone so a later poll id change can't
- // replay it.
- // biome-ignore lint/correctness/useExhaustiveDependencies: runs once per flash arrival
- React.useEffect(() => {
- if (sharePollFlash !== pollId) return;
- open("poll_created");
- }, [sharePollFlash]);
-
- return (
- <>
- <Button
- variant={variant}
- {...dialog.triggerProps}
- onClick={() => open("manual")}
- >
- <Share2Icon data-icon="inline-start" />
- <span className="sr-only sm:not-sr-only">
- <Trans i18nKey="share" defaults="Share" />
- </span>
- </Button>
- <SharePollDialog
- {...dialog.dialogProps}
- pollId={pollId}
- pollStatus={pollStatus}
- inviteLink={inviteLink}
- />
- </>
- );
-}
-
export function SharePollDialog({
pollId,
pollStatus,