Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
✨ Build out the poll admin overview, responses, dates and activity pages (#3409)
Luke Vella3b4ef94e3fd1
diff --git a/apps/web/biome.json b/apps/web/biome.jsonindex 97d2ef478..1d6d52899 100644--- a/apps/web/biome.json+++ b/apps/web/biome.json@@ -474,7 +474,6 @@{"includes": ["src/features/billing/components/pay-wall-dialog.tsx",- "src/features/poll/components/manage-poll.tsx","src/lib/auth.ts","src/lib/feature-flags/config.ts","src/lib/safe-action/server.ts"diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.jsonindex 448bb5828..86815d41f 100644--- a/apps/web/public/locales/en/app.json+++ b/apps/web/public/locales/en/app.json@@ -708,21 +708,66 @@"planRenewsOn": "Renews on {date}","planResumedToast": "Your plan will renew","poll": "Poll",+ "pollActivityInviteOpened": "<b>{email}</b> opened their invite",+ "pollActivityInviteReminded": "Reminder sent to <b>{email}</b>",+ "pollActivityInviteRevoked": "Invite to <b>{email}</b> revoked",+ "pollActivityInviteSent": "Invite sent to <b>{email}</b>",+ "pollActivityInvitesRevokedBulk": "{count, plural, one {1 invite revoked} other {# invites revoked}}",+ "pollActivityOptionAdded": "Date added",+ "pollActivityOptionDeleted": "Date removed",+ "pollActivityPageEmptyDescription": "Activity on this poll will show up here.",+ "pollActivityPollClosed": "Poll closed",+ "pollActivityPollClosedAuto": "Poll closed automatically",+ "pollActivityPollCreated": "Poll created",+ "pollActivityPollDeleted": "Poll deleted",+ "pollActivityPollReopened": "Poll reopened",+ "pollActivityPollScheduled": "Poll scheduled",+ "pollActivityPollUpdated": "Poll details updated",+ "pollActivityResponseCreated": "<b>{name}</b> responded",+ "pollActivityResponseDeleted": "Response from <b>{name}</b> deleted",+ "pollActivityResponseUpdated": "<b>{name}</b> updated their response",+ "pollAdminMenu": "Poll options","pollAutoClosedBadge": "Automatically closed","pollAutoClosedDescription": "This poll was closed automatically because all of its dates have passed. No more responses are being accepted.","pollAutoClosedTooltip": "This poll was closed automatically because all of its dates have passed. You can reopen it at any time.","pollClosed": "Poll closed","pollClosedDescription": "No more responses are being accepted.",+ "pollDatesListEmpty": "No dates","pollDeleted": "Poll deleted","pollDeletedDescription": "It may have been deleted by its creator or removed after a period of inactivity.","pollDeletedTitle": "This poll has been deleted","pollDeleteError": "Failed to delete poll","pollNotificationsDescription": "Get notified by email when there is activity on your polls",+ "pollOptionsListOption": "Option",+ "pollOptionsListValue": "Value",+ "pollOverviewNoActivity": "No activity yet",+ "pollOverviewNoPopularDates": "Popular dates will show up here once participants vote.",+ "pollOverviewNoResponses": "No responses yet",+ "pollOverviewNoResponsesDescription": "Responses will show up here once participants vote.",+ "pollOverviewNoVotes": "No votes yet",+ "pollOverviewPopularDates": "Most popular dates",+ "pollOverviewRecentActivity": "Recent activity",+ "pollOverviewRecentResponses": "Recent responses",+ "pollOverviewViewAll": "View all","pollRemovedDescription": "It violated our terms of use and is no longer available.","pollRemovedTitle": "This poll has been removed","pollRemovedWarningDescription": "Treat the message that sent you here as suspicious. Do not call phone numbers, follow links, or send money or personal details in response to it.","pollRemovedWarningTitle": "Weren't expecting this link?","pollReopened": "Poll reopened",+ "pollResponseActions": "Actions for {name}",+ "pollResponseActionsDeleteClosed": "Reopen the poll to delete responses",+ "pollResponseDeleted": "Response from {name} deleted",+ "pollResponseDetailActivity": "Activity",+ "pollResponseDetailAvailability": "Availability",+ "pollResponseDetailNoEmail": "No email provided",+ "pollResponseDetailNote": "Note",+ "pollResponseDetailNotFound": "This response no longer exists",+ "pollResponseDetailNoVote": "No answer",+ "pollResponseDetailSelect": "Select a response to see its details",+ "pollResponsesListActions": "Actions",+ "pollResponsesListEmpty": "No responses",+ "pollResponsesListEmptyDescription": "Responses will show up here once participants vote.",+ "pollResponsesListNote": "Note","polls": "Polls","pollScheduled": "Poll scheduled","pollsListActions": "Actions",@@ -1005,6 +1050,7 @@"viewClosedPolls": "View closed polls","viewInvites": "View invites","viewResults": "View results",+ "voteBarLabel": "{yes} yes, {ifNeedBe} if need be, out of {total, plural, one {1 response} other {# responses}}","voteOptionsLockedDescription": "Locked: participants have already answered \"if need be\".","voteOptionsSettingDescription": "The answers participants can give for each option.","voteOptionsSettingTitle": "Vote options",diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/activity/page.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/activity/page.tsxindex ed22960a0..ecdc80353 100644--- a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/activity/page.tsx+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/activity/page.tsx@@ -1,4 +1,13 @@-import { loadPoll } from "@/features/poll/loaders";+import { ActivityIcon } from "lucide-react";+import {+ EmptyState,+ EmptyStateDescription,+ EmptyStateIcon,+ EmptyStateTitle,+} from "@/components/empty-state";+import { PollActivityList } from "@/features/activity/components/poll-activity-list";+import { loadPoll, loadPollActivity } from "@/features/poll/loaders";+import { Trans } from "@/i18n/client";export default async function Page({params,@@ -6,6 +15,33 @@ export default async function Page({params: Promise<{ pollId: string }>;}) {const { pollId } = await params;- await loadPoll(pollId);- return null;+ const [poll, activity] = await Promise.all([+ loadPoll(pollId),+ loadPollActivity(pollId),+ ]);++ if (activity.length === 0) {+ return (+ <EmptyState className="h-96">+ <EmptyStateIcon>+ <ActivityIcon />+ </EmptyStateIcon>+ <EmptyStateTitle>+ <Trans i18nKey="pollOverviewNoActivity" defaults="No activity yet" />+ </EmptyStateTitle>+ <EmptyStateDescription>+ <Trans+ i18nKey="pollActivityPageEmptyDescription"+ defaults="Activity on this poll will show up here."+ />+ </EmptyStateDescription>+ </EmptyState>+ );+ }++ return (+ <div className="px-7.5 pt-4 pb-8">+ <PollActivityList activity={activity} timeZone={poll.timeZone} />+ </div>+ );}diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/components/overview-section.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/components/overview-section.tsxnew file mode 100644index 000000000..46c986513--- /dev/null+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/components/overview-section.tsx@@ -0,0 +1,41 @@+import { buttonVariants, cn } from "@rallly/ui";+import { Badge } from "@rallly/ui/badge";+import { Link } from "@/components/link";+import { Trans } from "@/i18n/client";++export function OverviewSection({+ title,+ viewAllHref,+ count,+ children,+}: React.PropsWithChildren<{+ title: React.ReactNode;+ viewAllHref?: string;+ count?: number;+}>) {+ return (+ <section className="space-y-2">+ <div className="flex h-9 items-center justify-between gap-4">+ <h2 className="font-medium text-sm">{title}</h2>+ {viewAllHref ? (+ <Link+ href={viewAllHref}+ className={cn(+ buttonVariants({ variant: "ghost", size: "sm" }),+ // Inset the badge by the same gap it has above and below+ count !== undefined && "pr-1 pl-2.5",+ )}+ >+ <Trans i18nKey="pollOverviewViewAll" defaults="View all" />+ {count !== undefined ? (+ <Badge size="sm" className="tabular-nums">+ {count}+ </Badge>+ ) : null}+ </Link>+ ) : null}+ </div>+ {children}+ </section>+ );+}diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/dates/page.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/dates/page.tsxindex ed22960a0..16b1fdaaa 100644--- a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/dates/page.tsx+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/dates/page.tsx@@ -1,4 +1,5 @@-import { loadPoll } from "@/features/poll/loaders";+import { PollDatesList } from "@/features/poll/components/poll-dates-list";+import { loadPoll, loadPollResults } from "@/features/poll/loaders";export default async function Page({params,@@ -6,6 +7,16 @@ export default async function Page({params: Promise<{ pollId: string }>;}) {const { pollId } = await params;- await loadPoll(pollId);- return null;+ const [poll, results] = await Promise.all([+ loadPoll(pollId),+ loadPollResults(pollId),+ ]);+ return (+ <PollDatesList+ kind={results.kind}+ options={results.options}+ participantCount={results.participantCount}+ timeZone={poll.timeZone}+ />+ );}diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/layout.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/layout.tsxindex 53f8dfeff..9ceeb373e 100644--- a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/layout.tsx+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/layout.tsx@@ -5,13 +5,19 @@ import { notFound } from "next/navigation";import { Suspense } from "react";import { Link } from "@/components/link";import {- PageContainer,- PageContent,- PageHeader,- PageHeaderContent,- PageTitle,-} from "@/components/page-layout";-import { loadPoll } from "@/features/poll/loaders";+ ListView,+ ListViewActions,+ ListViewContent,+ ListViewHeader,+ ListViewTitle,+ ListViewTitleBar,+ ListViewToolbar,+} from "@/components/list-view";+import { PollProvider } from "@/features/poll/client";+import { PollAdminMenu } from "@/features/poll/components/poll-admin-menu";+import { LegacyPollContextProvider } from "@/features/poll/components/poll-context-provider";+import { ShareDialog } from "@/features/poll/components/share-dialog";+import { loadAdminPoll, loadPoll } from "@/features/poll/loaders";import { Trans } from "@/i18n/client";import { isFeatureEnabled } from "@/lib/feature-flags/server";import { PollDetailSheet } from "./poll-detail-sheet";@@ -27,6 +33,35 @@ async function PollPageTitle({return poll.title;}+async function PollHeaderActions({+ params,+}: {+ params: Promise<{ pollId: string }>;+}) {+ const { pollId } = await params;+ await loadPoll(pollId);+ // The schedule dialog and CSV export read the whole poll, votes included,+ // from the poll context the legacy admin page provides.+ const { poll, participants, comments } = await loadAdminPoll(pollId);+ return (+ <PollProvider+ poll={poll}+ participants={participants}+ comments={comments}+ viewerRole="admin"+ >+ <LegacyPollContextProvider>+ <PollAdminMenu />+ <ShareDialog+ pollId={poll.id}+ pollStatus={poll.status}+ inviteLink={poll.inviteLink}+ />+ </LegacyPollContextProvider>+ </PollProvider>+ );+}+export default function Layout({children,params,@@ -39,9 +74,9 @@ export default function Layout({}return (- <PageContainer>- <PageHeader>- <PageHeaderContent className="flex items-center gap-2">+ <ListView>+ <ListViewHeader>+ <ListViewTitleBar className="md:pl-4"><Linkhref="/polls"className={buttonVariants({ variant: "ghost", size: "icon" })}@@ -51,18 +86,23 @@ export default function Layout({<Trans i18nKey="back" defaults="Back" /></span></Link>- <PageTitle>+ <ListViewTitle><Suspense fallback={<Skeleton className="h-5 w-40" />}><PollPageTitle params={params} /></Suspense>- </PageTitle>- </PageHeaderContent>- </PageHeader>- <PageContent>- <PollShellTabs />- <div className="mt-4 lg:mt-6">{children}</div>- </PageContent>+ </ListViewTitle>+ <ListViewActions>+ <Suspense>+ <PollHeaderActions params={params} />+ </Suspense>+ </ListViewActions>+ </ListViewTitleBar>+ <ListViewToolbar>+ <PollShellTabs />+ </ListViewToolbar>+ </ListViewHeader>+ <ListViewContent>{children}</ListViewContent><PollDetailSheet />- </PageContainer>+ </ListView>);}diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/page.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/page.tsxindex ed22960a0..76497c8b6 100644--- a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/page.tsx+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/page.tsx@@ -1,4 +1,22 @@-import { loadPoll } from "@/features/poll/loaders";+import { ActivityIcon, CalendarIcon, InboxIcon } from "lucide-react";+import {+ EmptyState,+ EmptyStateDescription,+ EmptyStateIcon,+ EmptyStateTitle,+} from "@/components/empty-state";+import { PollActivityList } from "@/features/activity/components/poll-activity-list";+import { PollResponsesList } from "@/features/poll/components/poll-responses-list";+import { PollTopDates } from "@/features/poll/components/poll-top-dates";+import {+ loadPoll,+ loadPollActivity,+ loadPollParticipants,+ loadPollResults,+ loadPollTopOptions,+} from "@/features/poll/loaders";+import { Trans } from "@/i18n/client";+import { OverviewSection } from "./components/overview-section";export default async function Page({params,@@ -6,6 +24,120 @@ export default async function Page({params: Promise<{ pollId: string }>;}) {const { pollId } = await params;- await loadPoll(pollId);- return null;+ const [poll, participants, results, topOptions, activity] = await Promise.all(+ [+ loadPoll(pollId),+ loadPollParticipants(pollId),+ loadPollResults(pollId),+ loadPollTopOptions(pollId, 3),+ loadPollActivity(pollId, 5),+ ],+ );++ return (+ <div className="space-y-8 px-7.5 pt-4 pb-8">+ <OverviewSection+ title={+ <Trans+ i18nKey="pollOverviewPopularDates"+ defaults="Most popular dates"+ />+ }+ viewAllHref={`/polls/${pollId}/dates`}+ count={results.options.length}+ >+ {topOptions.options.length > 0 ? (+ <PollTopDates+ options={topOptions.options}+ participantCount={topOptions.participantCount}+ timeZone={poll.timeZone}+ className="-mx-3.5"+ />+ ) : (+ <EmptyState className="py-10">+ <EmptyStateIcon>+ <CalendarIcon />+ </EmptyStateIcon>+ <EmptyStateTitle>+ <Trans i18nKey="pollOverviewNoVotes" defaults="No votes yet" />+ </EmptyStateTitle>+ <EmptyStateDescription>+ <Trans+ i18nKey="pollOverviewNoPopularDates"+ defaults="Popular dates will show up here once participants vote."+ />+ </EmptyStateDescription>+ </EmptyState>+ )}+ </OverviewSection>+ <OverviewSection+ title={+ <Trans+ i18nKey="pollOverviewRecentResponses"+ defaults="Recent responses"+ />+ }+ viewAllHref={+ participants.length > 0 ? `/polls/${pollId}/responses` : undefined+ }+ count={participants.length}+ >+ {participants.length > 0 ? (+ <PollResponsesList+ pollId={pollId}+ participants={participants.slice(0, 5)}+ pollOpen={poll.status === "open"}+ className="-mx-4 px-0 py-0"+ />+ ) : (+ <EmptyState className="py-10">+ <EmptyStateIcon>+ <InboxIcon />+ </EmptyStateIcon>+ <EmptyStateTitle>+ <Trans+ i18nKey="pollOverviewNoResponses"+ defaults="No responses yet"+ />+ </EmptyStateTitle>+ <EmptyStateDescription>+ <Trans+ i18nKey="pollOverviewNoResponsesDescription"+ defaults="Responses will show up here once participants vote."+ />+ </EmptyStateDescription>+ </EmptyState>+ )}+ </OverviewSection>+ <OverviewSection+ title={+ <Trans+ i18nKey="pollOverviewRecentActivity"+ defaults="Recent activity"+ />+ }+ viewAllHref={`/polls/${pollId}/activity`}+ >+ {activity.length > 0 ? (+ <PollActivityList+ activity={activity}+ timeZone={poll.timeZone}+ className="pt-2"+ />+ ) : (+ <EmptyState className="py-10">+ <EmptyStateIcon>+ <ActivityIcon />+ </EmptyStateIcon>+ <EmptyStateTitle>+ <Trans+ i18nKey="pollOverviewNoActivity"+ defaults="No activity yet"+ />+ </EmptyStateTitle>+ </EmptyState>+ )}+ </OverviewSection>+ </div>+ );}diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/poll-shell-tabs.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/poll-shell-tabs.tsxindex 72dcaef53..c63d4069d 100644--- a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/poll-shell-tabs.tsx+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/poll-shell-tabs.tsx@@ -1,8 +1,8 @@"use client";-import { cn } from "@rallly/ui";import { usePathname } from "next/navigation";import { Link } from "@/components/link";+import { pillVariants } from "@/components/pill-variants";import { Trans } from "@/i18n/client";export function PollShellTabs() {@@ -29,7 +29,7 @@ export function PollShellTabs() {];return (- <nav className="flex space-x-4 border-b border-b-border">+ <nav className="flex items-center gap-1">{tabs.map((tab) => {const isActive = pathname === tab.href;return (@@ -37,12 +37,7 @@ export function PollShellTabs() {key={tab.href}href={tab.href}aria-current={isActive ? "page" : undefined}- className={cn(- "-mb-px inline-flex h-9 items-center whitespace-nowrap border-b-2 px-1 pt-1 pb-1 font-medium text-sm transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",- isActive- ? "border-foreground text-foreground"- : "border-transparent text-muted-foreground hover:border-accent-border hover:text-accent-foreground",- )}+ className={pillVariants({ selected: isActive })}>{tab.label}</Link>diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/responses/page.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/responses/page.tsxindex ed22960a0..6939dac00 100644--- a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/responses/page.tsx+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/responses/page.tsx@@ -1,11 +1,141 @@-import { loadPoll } from "@/features/poll/loaders";+import { cn } from "@rallly/ui";+import { MousePointerClickIcon, SearchXIcon } from "lucide-react";+import {+ EmptyState,+ EmptyStateIcon,+ EmptyStateTitle,+} from "@/components/empty-state";+import { PollActivityList } from "@/features/activity/components/poll-activity-list";+import {+ PollResponseDetail,+ PollResponseDetailCard,+} from "@/features/poll/components/poll-response-detail";+import { PollResponsesList } from "@/features/poll/components/poll-responses-list";+import {+ loadOptionalPollResponse,+ loadPoll,+ loadPollParticipants,+ loadPollResponseActivity,+ loadPollResults,+} from "@/features/poll/loaders";+import { Trans } from "@/i18n/client";++async function ResponseDetail({+ pollId,+ responseId,+}: {+ pollId: string;+ responseId: string;+}) {+ const [poll, response, results, activity] = await Promise.all([+ loadPoll(pollId),+ loadOptionalPollResponse(pollId, responseId),+ loadPollResults(pollId),+ loadPollResponseActivity(pollId, responseId),+ ]);++ if (!response) {+ return (+ <PollResponseDetailCard className="flex items-center justify-center">+ <EmptyState>+ <EmptyStateIcon>+ <SearchXIcon />+ </EmptyStateIcon>+ <EmptyStateTitle>+ <Trans+ i18nKey="pollResponseDetailNotFound"+ defaults="This response no longer exists"+ />+ </EmptyStateTitle>+ </EmptyState>+ </PollResponseDetailCard>+ );+ }++ return (+ <PollResponseDetail+ pollId={pollId}+ pollOpen={poll.status === "open"}+ kind={results.kind}+ timeZone={poll.timeZone}+ response={response}+ options={results.options}+ activity={+ <PollActivityList activity={activity} timeZone={poll.timeZone} />+ }+ />+ );+}export default async function Page({params,+ searchParams,}: {params: Promise<{ pollId: string }>;+ searchParams: Promise<{ responseId?: string | string[] }>;}) {- const { pollId } = await params;- await loadPoll(pollId);- return null;+ const [{ pollId }, { responseId: rawResponseId }] = await Promise.all([+ params,+ searchParams,+ ]);+ const responseId =+ typeof rawResponseId === "string" ? rawResponseId : undefined;+ const [poll, participants] = await Promise.all([+ loadPoll(pollId),+ loadPollParticipants(pollId),+ ]);++ if (participants.length === 0) {+ return (+ <PollResponsesList+ pollId={pollId}+ participants={participants}+ pollOpen={poll.status === "open"}+ />+ );+ }++ // Below md one pane shows at a time: the list, or the selected response.+ return (+ <div className="flex h-full min-h-0">+ <div+ className={cn(+ "min-h-0 w-full overflow-y-auto md:w-80 md:shrink-0 lg:w-96",+ responseId ? "hidden md:block" : "block",+ )}+ >+ <PollResponsesList+ pollId={pollId}+ participants={participants}+ pollOpen={poll.status === "open"}+ selectedId={responseId}+ compact+ />+ </div>+ <div+ className={cn(+ "min-h-0 min-w-0 flex-1",+ responseId ? "block" : "hidden md:block",+ )}+ >+ {responseId ? (+ <ResponseDetail pollId={pollId} responseId={responseId} />+ ) : (+ <PollResponseDetailCard className="flex items-center justify-center">+ <EmptyState>+ <EmptyStateIcon>+ <MousePointerClickIcon />+ </EmptyStateIcon>+ <EmptyStateTitle>+ <Trans+ i18nKey="pollResponseDetailSelect"+ defaults="Select a response to see its details"+ />+ </EmptyStateTitle>+ </EmptyState>+ </PollResponseDetailCard>+ )}+ </div>+ </div>+ );}diff --git a/apps/web/src/components/data-list.tsx b/apps/web/src/components/data-list.tsxindex 09f52f14b..dfbd14c4f 100644--- a/apps/web/src/components/data-list.tsx+++ b/apps/web/src/components/data-list.tsx@@ -16,7 +16,7 @@ type DataListGroup = { id: string; label: React.ReactNode };function DataListRow<TData>({ row }: { row: Row<TData> }) {return (- <li className="relative col-span-full grid h-12 grid-cols-subgrid items-center rounded-lg pr-3 pl-4 hover:bg-accent/60 has-[a:focus-visible]:bg-accent/60">+ <li className="relative col-span-full grid h-12 grid-cols-subgrid items-center rounded-lg pr-3 pl-4 hover:bg-accent/60 has-[a:focus-visible]:bg-accent/60 has-[a[aria-current=page]]:bg-accent">{row.getVisibleCells().map((cell) => (<divkey={cell.id}diff --git a/apps/web/src/components/filter-pills.tsx b/apps/web/src/components/filter-pills.tsxindex a61c69f2f..f906f95b7 100644--- a/apps/web/src/components/filter-pills.tsx+++ b/apps/web/src/components/filter-pills.tsx@@ -1,9 +1,9 @@"use client";-import { cn } from "@rallly/ui";import { useRouter, useSearchParams } from "next/navigation";import React from "react";import { Link } from "@/components/link";+import { pillVariants } from "@/components/pill-variants";/*** A single-select filter kept in a URL search param. Each option is a link,@@ -55,12 +55,7 @@ export function FilterPills<T extends string>({});}}aria-current={selected ? "page" : undefined}- className={cn(- "inline-flex h-9 shrink-0 items-center gap-2 whitespace-nowrap rounded-full px-3.5 text-sm ring-1 ring-transparent ring-inset transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",- selected- ? "bg-white text-sidebar-accent-foreground ring-button-outline dark:bg-muted"- : "text-muted-foreground hover:bg-white dark:hover:bg-muted",- )}+ className={pillVariants({ selected })}>{option.label}</Link>diff --git a/apps/web/src/components/pill-variants.ts b/apps/web/src/components/pill-variants.tsnew file mode 100644index 000000000..ef6dd7d52--- /dev/null+++ b/apps/web/src/components/pill-variants.ts@@ -0,0 +1,17 @@+import { cva } from "class-variance-authority";++export const pillVariants = cva(+ "inline-flex h-9 shrink-0 items-center gap-2 whitespace-nowrap rounded-full px-3.5 text-sm ring-1 ring-inset transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",+ {+ variants: {+ selected: {+ true: "bg-white text-sidebar-accent-foreground ring-button-outline dark:bg-muted",+ false:+ "text-muted-foreground ring-transparent hover:bg-white dark:hover:bg-muted",+ },+ },+ defaultVariants: {+ selected: false,+ },+ },+);diff --git a/apps/web/src/features/activity/components/poll-activity-list.tsx b/apps/web/src/features/activity/components/poll-activity-list.tsxnew file mode 100644index 000000000..402baa007--- /dev/null+++ b/apps/web/src/features/activity/components/poll-activity-list.tsx@@ -0,0 +1,317 @@+"use client";++import { cn } from "@rallly/ui";+import type { LucideIcon } from "lucide-react";+import {+ BellIcon,+ CalendarCheckIcon,+ CalendarMinusIcon,+ CalendarPlusIcon,+ CircleStopIcon,+ MailIcon,+ MailOpenIcon,+ MailXIcon,+ PencilIcon,+ PlayIcon,+ PlusIcon,+ TrashIcon,+ UserMinusIcon,+ UserPenIcon,+ UserPlusIcon,+} from "lucide-react";+import type { PollActivityEvent } from "@/features/activity/schema";+import {+ EventDate,+ EventTimeRange,+} from "@/features/scheduled-event/components/event-date-time";+import { Trans } from "@/i18n/client";+import { Time } from "@/lib/datetime/time";++type ActivityRow = {+ id: string;+ createdAt: Date;+ event: PollActivityEvent;+};++const iconByType: Record<PollActivityEvent["type"], LucideIcon> = {+ poll_created: PlusIcon,+ poll_updated: PencilIcon,+ poll_closed: CircleStopIcon,+ poll_reopened: PlayIcon,+ poll_deleted: TrashIcon,+ poll_scheduled: CalendarCheckIcon,+ invite_sent: MailIcon,+ invite_opened: MailOpenIcon,+ invite_reminded: BellIcon,+ invite_revoked: MailXIcon,+ invites_revoked_bulk: MailXIcon,+ response_created: UserPlusIcon,+ response_updated: UserPenIcon,+ response_deleted: UserMinusIcon,+ option_added: CalendarPlusIcon,+ option_deleted: CalendarMinusIcon,+};++// Tints group events by what they did to the poll. Colour only reinforces+// the icon and the sentence; neither depends on it.+const toneClassName = {+ added: "bg-lime-500/10 text-lime-600 dark:text-lime-400",+ changed: "bg-cyan-500/10 text-cyan-600 dark:text-cyan-400",+ removed: "bg-rose-500/10 text-rose-600 dark:text-rose-400",+ closed: "bg-amber-500/10 text-amber-600 dark:text-amber-400",+ milestone: "bg-violet-500/10 text-violet-600 dark:text-violet-400",+ invite: "bg-sky-500/10 text-sky-600 dark:text-sky-400",+};++const toneByType: Record<+ PollActivityEvent["type"],+ keyof typeof toneClassName+> = {+ poll_created: "milestone",+ poll_updated: "changed",+ poll_closed: "closed",+ poll_reopened: "added",+ poll_deleted: "removed",+ poll_scheduled: "milestone",+ invite_sent: "invite",+ invite_opened: "invite",+ invite_reminded: "invite",+ invite_revoked: "removed",+ invites_revoked_bulk: "removed",+ response_created: "added",+ response_updated: "changed",+ response_deleted: "removed",+ option_added: "added",+ option_deleted: "removed",+};++function OptionChip({+ start,+ duration,+ timeZone,+}: {+ start: string;+ duration: number;+ timeZone: string | null;+}) {+ const allDay = duration === 0;+ const startDate = new Date(start);+ return (+ <span className="inline-flex items-center gap-1.5 rounded-md bg-muted px-1.5 py-0.5 font-medium">+ <EventDate+ value={startDate}+ allDay={allDay}+ timeZone={timeZone}+ preset="date"+ />+ {allDay ? null : (+ <EventTimeRange+ start={startDate}+ end={new Date(startDate.getTime() + duration * 60_000)}+ allDay={false}+ timeZone={timeZone}+ className="text-muted-foreground"+ />+ )}+ </span>+ );+}++function ActivityDescription({+ event,+ timeZone,+}: {+ event: PollActivityEvent;+ timeZone: string | null;+}) {+ const b = <b className="font-medium" />;+ switch (event.type) {+ case "poll_created":+ return (+ <Trans i18nKey="pollActivityPollCreated" defaults="Poll created" />+ );+ case "poll_updated":+ return (+ <Trans+ i18nKey="pollActivityPollUpdated"+ defaults="Poll details updated"+ />+ );+ case "poll_closed":+ return event.payload.reason === "auto" ? (+ <Trans+ i18nKey="pollActivityPollClosedAuto"+ defaults="Poll closed automatically"+ />+ ) : (+ <Trans i18nKey="pollActivityPollClosed" defaults="Poll closed" />+ );+ case "poll_reopened":+ return (+ <Trans i18nKey="pollActivityPollReopened" defaults="Poll reopened" />+ );+ case "poll_deleted":+ return (+ <Trans i18nKey="pollActivityPollDeleted" defaults="Poll deleted" />+ );+ case "poll_scheduled":+ return (+ <>+ <Trans+ i18nKey="pollActivityPollScheduled"+ defaults="Poll scheduled"+ />{" "}+ <OptionChip+ start={event.payload.start}+ duration={event.payload.duration}+ timeZone={timeZone}+ />+ </>+ );+ case "invite_sent":+ return (+ <Trans+ i18nKey="pollActivityInviteSent"+ defaults="Invite sent to <b>{email}</b>"+ values={{ email: event.payload.email }}+ components={{ b }}+ />+ );+ case "invite_opened":+ return (+ <Trans+ i18nKey="pollActivityInviteOpened"+ defaults="<b>{email}</b> opened their invite"+ values={{ email: event.payload.email }}+ components={{ b }}+ />+ );+ case "invite_reminded":+ return (+ <Trans+ i18nKey="pollActivityInviteReminded"+ defaults="Reminder sent to <b>{email}</b>"+ values={{ email: event.payload.email }}+ components={{ b }}+ />+ );+ case "invite_revoked":+ return (+ <Trans+ i18nKey="pollActivityInviteRevoked"+ defaults="Invite to <b>{email}</b> revoked"+ values={{ email: event.payload.email }}+ components={{ b }}+ />+ );+ case "invites_revoked_bulk":+ return (+ <Trans+ i18nKey="pollActivityInvitesRevokedBulk"+ defaults="{count, plural, one {1 invite revoked} other {# invites revoked}}"+ values={{ count: event.payload.count }}+ />+ );+ case "response_created":+ return (+ <Trans+ i18nKey="pollActivityResponseCreated"+ defaults="<b>{name}</b> responded"+ values={{ name: event.payload.name }}+ components={{ b }}+ />+ );+ case "response_updated":+ return (+ <Trans+ i18nKey="pollActivityResponseUpdated"+ defaults="<b>{name}</b> updated their response"+ values={{ name: event.payload.name }}+ components={{ b }}+ />+ );+ case "response_deleted":+ return (+ <Trans+ i18nKey="pollActivityResponseDeleted"+ defaults="Response from <b>{name}</b> deleted"+ values={{ name: event.payload.name }}+ components={{ b }}+ />+ );+ case "option_added":+ return (+ <>+ <Trans i18nKey="pollActivityOptionAdded" defaults="Date added" />{" "}+ <OptionChip+ start={event.payload.start}+ duration={event.payload.duration}+ timeZone={timeZone}+ />+ </>+ );+ case "option_deleted":+ return (+ <>+ <Trans i18nKey="pollActivityOptionDeleted" defaults="Date removed" />{" "}+ <OptionChip+ start={event.payload.start}+ duration={event.payload.duration}+ timeZone={timeZone}+ />+ </>+ );+ }+}++export function PollActivityList({+ activity,+ timeZone,+ className,+}: {+ activity: ActivityRow[];+ timeZone: string | null;+ className?: string;+}) {+ return (+ <ol className={cn("flex flex-col", className)}>+ {activity.map(({ id, createdAt, event }) => {+ const Icon = iconByType[event.type];+ const note =+ event.type === "response_created" ? event.payload.note : undefined;+ return (+ <li key={id} className="group relative flex gap-3 pb-6 last:pb-0">+ {/* The rail joining this event's icon to the next one */}+ <div+ aria-hidden+ className="absolute top-9 bottom-1 left-4 w-px -translate-x-1/2 bg-border group-last:hidden"+ />+ <div+ className={cn(+ "flex size-8 shrink-0 items-center justify-center rounded-full",+ toneClassName[toneByType[event.type]],+ )}+ >+ <Icon aria-hidden className="size-4" />+ </div>+ <div className="min-w-0 flex-1 space-y-1 pt-1.5">+ <p className="text-sm leading-5">+ <ActivityDescription event={event} timeZone={timeZone} />+ </p>+ <Time+ value={createdAt}+ preset="datetime"+ className="block text-muted-foreground text-xs"+ />+ {note ? (+ <p className="mt-2 whitespace-pre-wrap rounded-lg border bg-card px-3 py-2 text-sm">+ {note}+ </p>+ ) : null}+ </div>+ </li>+ );+ })}+ </ol>+ );+}diff --git a/apps/web/src/features/activity/data.ts b/apps/web/src/features/activity/data.tsindex 242ae230c..b94413ba2 100644--- a/apps/web/src/features/activity/data.ts+++ b/apps/web/src/features/activity/data.ts@@ -5,22 +5,27 @@ import type { AuthorizedSpaceId } from "@/features/space/types";import { parsePollActivity } from "./schema";/**- * Latest activity for a poll, newest first. Rows whose type or payload this+ * Latest activity for a poll, newest first; every row when no limit is+ * given. Rows whose type or payload this* version of the vocabulary can't interpret are skipped rather than failing* the feed.*/export async function listPollActivity({pollId,spaceId,+ participantId,limit,}: {pollId: string;spaceId: AuthorizedSpaceId;- limit: number;+ /** Only the events about this response. */+ participantId?: string;+ limit?: number;}) {const rows = await prisma.pollActivity.findMany({where: {pollId,+ ...(participantId && { participantId }),poll: {spaceId,deleted: false,diff --git a/apps/web/src/features/activity/schema.test.ts b/apps/web/src/features/activity/schema.test.tsindex 3725a147e..bdcf7bcea 100644--- a/apps/web/src/features/activity/schema.test.ts+++ b/apps/web/src/features/activity/schema.test.ts@@ -29,6 +29,27 @@ describe("pollActivitySchema", () => {expect(result.success).toBe(false);});+ it("reads a response note when present and tolerates rows without one", () => {+ const withNote = parsePollActivity({+ ...emptyRefs,+ type: "response_created",+ participantId: "p1",+ payload: { name: "Jessie Smith", note: "Mornings work best" },+ });+ const withoutNote = parsePollActivity({+ ...emptyRefs,+ type: "response_created",+ participantId: "p1",+ payload: { name: "Jessie Smith" },+ });++ expect(withNote?.payload).toEqual({+ name: "Jessie Smith",+ note: "Mornings work best",+ });+ expect(withoutNote?.payload).toEqual({ name: "Jessie Smith" });+ });+it("requires the subject ref of a response event", () => {const result = pollActivitySchema.safeParse({type: "response_created",diff --git a/apps/web/src/features/activity/schema.ts b/apps/web/src/features/activity/schema.tsindex 49687a105..4cea060bb 100644--- a/apps/web/src/features/activity/schema.ts+++ b/apps/web/src/features/activity/schema.ts@@ -102,7 +102,9 @@ export const pollActivitySchema = z.discriminatedUnion("type", [type: z.literal("response_created"),...actor,participantId: z.string(),- payload: z.object({ name: z.string() }),+ // A response's note is set once, when it's created, so the snapshot+ // stays accurate. Rows written before the note was recorded lack it.+ payload: z.object({ name: z.string(), note: z.string().optional() }),}),z.object({type: z.literal("response_updated"),diff --git a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/duplicate-dialog.tsx b/apps/web/src/features/poll/components/duplicate-dialog.tsxsimilarity index 96%rename from apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/duplicate-dialog.tsxrename to apps/web/src/features/poll/components/duplicate-dialog.tsxindex 17bff7db5..b857510d2 100644--- a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/duplicate-dialog.tsx+++ b/apps/web/src/features/poll/components/duplicate-dialog.tsx@@ -11,9 +11,9 @@ import {DialogTitle,} from "@rallly/ui/dialog";import { useRouter } from "next/navigation";+import { DuplicateForm } from "@/features/poll/components/duplicate-form";import { Trans } from "@/i18n/client";import { trpc } from "@/trpc/client";-import { DuplicateForm } from "./duplicate-form";const formName = "duplicate-form";export function DuplicateDialog({diff --git a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/duplicate-form.tsx b/apps/web/src/features/poll/components/duplicate-form.tsxsimilarity index 100%rename from apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/duplicate-form.tsxrename to apps/web/src/features/poll/components/duplicate-form.tsxdiff --git a/apps/web/src/features/poll/components/invite-by-email.tsx b/apps/web/src/features/poll/components/invite-by-email.tsxindex 38e5282f7..c8eef0c36 100644--- a/apps/web/src/features/poll/components/invite-by-email.tsx+++ b/apps/web/src/features/poll/components/invite-by-email.tsx@@ -27,7 +27,6 @@ import { RegisterLink } from "@/components/register-link";import { Spinner } from "@/components/spinner";import { showPayWall, useIsFree } from "@/features/billing/client";import { ProBadge } from "@/features/billing/components/pro-badge";-import { usePoll } from "@/features/poll/client";import type { InviteeRowStatus } from "@/features/poll/components/invitee-list";import {InviteeListPreview,@@ -35,6 +34,7 @@ import {} from "@/features/poll/components/invitee-list";import { sendPollInviteAction } from "@/features/poll/invite/actions";import { sendPollInviteSchema } from "@/features/poll/invite/schema";+import type { PollStatus } from "@/features/poll/schema";import { useUser } from "@/features/user/client";import { Trans, useTranslation } from "@/i18n/client";import { trpc } from "@/trpc/client";@@ -55,19 +55,24 @@ type InviteFormValues = { email: string };* page views never open it. The send action's success refetches it, which is* what replaces an optimistic "Sending" row with the real one.*/-export function InviteByEmail() {- const poll = usePoll();+export function InviteByEmail({+ pollId,+ pollStatus,+}: {+ pollId: string;+ pollStatus: PollStatus;+}) {const { user } = useUser();const isFree = useIsFree();const { t } = useTranslation();const isGuest = !user || user.isGuest;const invitesQuery = trpc.polls.invites.list.useQuery(- { pollId: poll.id },+ { pollId: pollId },{ enabled: !isGuest },);const invites = invitesQuery.data ?? [];- const isOpen = poll.status === "open";+ const isOpen = pollStatus === "open";const form = useForm<InviteFormValues>({resolver: zodResolver(inviteFormSchema),@@ -189,7 +194,7 @@ export function InviteByEmail() {const onValid = ({ email: address }: InviteFormValues) => {if (isFree) {- showPayWall({ from: "invite-dialog", pollId: poll.id });+ showPayWall({ from: "invite-dialog", pollId: pollId });return;}if (rows.some((row) => row.email.toLowerCase() === address)) {@@ -205,7 +210,7 @@ export function InviteByEmail() {setSending((prev) => [address, ...prev]);form.reset();form.setFocus("email");- sendInvite.mutate({ pollId: poll.id, email: address });+ sendInvite.mutate({ pollId, email: address });};return (diff --git a/apps/web/src/features/poll/components/invite-link-row.tsx b/apps/web/src/features/poll/components/invite-link-row.tsxindex 1b9c1b46e..5eeaf0314 100644--- a/apps/web/src/features/poll/components/invite-link-row.tsx+++ b/apps/web/src/features/poll/components/invite-link-row.tsx@@ -5,15 +5,19 @@ import { Button } from "@rallly/ui/button";import { CheckIcon, CopyIcon, LinkIcon } from "lucide-react";import React from "react";import { useCopyToClipboard } from "react-use";-import { usePoll } from "@/features/poll/client";import { Trans, useTranslation } from "@/i18n/client";/*** The invite link with its copy action. The URL is shown because hosts have* learned to look for something that looks like a link.*/-export function InviteLinkRow({ inviteLink }: { inviteLink: string }) {- const poll = usePoll();+export function InviteLinkRow({+ pollId,+ inviteLink,+}: {+ pollId: string;+ inviteLink: string;+}) {const { t } = useTranslation();const [didCopy, setDidCopy] = React.useState(false);const [state, copyToClipboard] = useCopyToClipboard();@@ -27,9 +31,9 @@ export function InviteLinkRow({ inviteLink }: { inviteLink: string }) {}if (state.value) {setDidCopy(true);- posthog?.capture("poll_share:invite_link_copy", { poll_id: poll.id });+ posthog?.capture("poll_share:invite_link_copy", { poll_id: pollId });}- }, [state, poll.id]);+ }, [state, pollId]);React.useEffect(() => {if (!didCopy) return;diff --git a/apps/web/src/features/poll/components/manage-poll.tsx b/apps/web/src/features/poll/components/manage-poll.tsxindex e35b8e510..40a46325c 100644--- a/apps/web/src/features/poll/components/manage-poll.tsx+++ b/apps/web/src/features/poll/components/manage-poll.tsx@@ -21,11 +21,11 @@ import {} from "lucide-react";import { useRouter } from "next/navigation";import * as React from "react";-import { DuplicateDialog } from "@/app/[locale]/(optional-space)/poll/[urlId]/duplicate-dialog";import { Link } from "@/components/link";import { showPayWall, useIsFree } from "@/features/billing/client";import { ProBadge } from "@/features/billing/components/pro-badge";import { usePoll } from "@/features/poll/client";+import { DuplicateDialog } from "@/features/poll/components/duplicate-dialog";import { SchedulePollDialog } from "@/features/poll/components/manage-poll/schedule-poll-dialog";import { Trans } from "@/i18n/client";import { trpc } from "@/trpc/client";diff --git a/apps/web/src/features/poll/components/poll-admin-menu.tsx b/apps/web/src/features/poll/components/poll-admin-menu.tsxnew file mode 100644index 000000000..2c62ac102--- /dev/null+++ b/apps/web/src/features/poll/components/poll-admin-menu.tsx@@ -0,0 +1,147 @@+"use client";++import { Button } from "@rallly/ui/button";+import { useDialog } from "@rallly/ui/dialog";+import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuSeparator,+ DropdownMenuTrigger,+} from "@rallly/ui/dropdown-menu";+import {+ CalendarCheck2Icon,+ CircleStopIcon,+ CopyIcon,+ DownloadIcon,+ MoreHorizontalIcon,+ PlayIcon,+ TrashIcon,+} from "lucide-react";+import { useRouter } from "next/navigation";+import { showPayWall, useIsFree } from "@/features/billing/client";+import { ProBadge } from "@/features/billing/components/pro-badge";+import { usePoll } from "@/features/poll/client";+import { DuplicateDialog } from "@/features/poll/components/duplicate-dialog";+import { DeletePollDialog } from "@/features/poll/components/manage-poll/delete-poll-dialog";+import { SchedulePollDialog } from "@/features/poll/components/manage-poll/schedule-poll-dialog";+import { useCsvExporter } from "@/features/poll/components/manage-poll/use-csv-exporter";+import { Trans, useTranslation } from "@/i18n/client";+import { trpc } from "@/trpc/client";++/**+ * The poll admin header's overflow menu. Reads the poll from the legacy+ * poll context because the schedule dialog and CSV export need every+ * response's votes.+ */+export function PollAdminMenu() {+ const poll = usePoll();+ const { t } = useTranslation();+ const router = useRouter();+ const isFree = useIsFree();+ const { exportToCsv } = useCsvExporter();+ const scheduleDialog = useDialog();+ const duplicateDialog = useDialog();+ const deleteDialog = useDialog();+ // These pages are server rendered, so a status change shows once they are+ // fetched again.+ const reopenPoll = trpc.polls.reopen.useMutation({+ onSuccess: () => router.refresh(),+ });+ const closePoll = trpc.polls.close.useMutation({+ onSuccess: () => router.refresh(),+ });++ const canSchedule = poll.status === "open" || poll.status === "closed";++ return (+ <>+ <DropdownMenu modal={false}>+ <DropdownMenuTrigger+ render={+ <Button+ variant="ghost"+ size="icon"+ aria-label={t("pollAdminMenu", { defaultValue: "Poll options" })}+ />+ }+ >+ <MoreHorizontalIcon />+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end">+ <DropdownMenuItem onClick={exportToCsv}>+ <DownloadIcon />+ <Trans i18nKey="exportToCsv" defaults="Export to CSV" />+ </DropdownMenuItem>+ {canSchedule ? (+ <DropdownMenuItem+ onClick={() => {+ if (isFree) {+ showPayWall({+ from: "manage-poll",+ action: "schedule",+ pollId: poll.id,+ });+ } else {+ scheduleDialog.trigger();+ }+ }}+ >+ <CalendarCheck2Icon />+ <Trans i18nKey="schedulePoll" defaults="Schedule" />+ {isFree ? <ProBadge /> : null}+ </DropdownMenuItem>+ ) : null}+ <DropdownMenuItem+ onClick={() => {+ if (isFree) {+ showPayWall({+ from: "manage-poll",+ action: "duplicate",+ pollId: poll.id,+ });+ } else {+ duplicateDialog.trigger();+ }+ }}+ >+ <CopyIcon />+ <Trans i18nKey="duplicate" defaults="Duplicate" />+ {isFree ? <ProBadge /> : null}+ </DropdownMenuItem>+ {poll.status === "open" ? (+ <DropdownMenuItem+ onClick={() => closePoll.mutate({ pollId: poll.id })}+ >+ <CircleStopIcon />+ <Trans i18nKey="closePoll" defaults="Close" />+ </DropdownMenuItem>+ ) : null}+ {poll.status === "closed" ? (+ <DropdownMenuItem+ onClick={() => reopenPoll.mutate({ pollId: poll.id })}+ >+ <PlayIcon />+ <Trans i18nKey="reopenPoll" defaults="Reopen poll" />+ </DropdownMenuItem>+ ) : null}+ <DropdownMenuSeparator />+ <DropdownMenuItem+ variant="destructive"+ onClick={() => deleteDialog.trigger()}+ >+ <TrashIcon />+ <Trans i18nKey="delete" />+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ <SchedulePollDialog {...scheduleDialog.dialogProps} />+ <DuplicateDialog+ pollId={poll.id}+ pollTitle={poll.title}+ {...duplicateDialog.dialogProps}+ />+ <DeletePollDialog urlId={poll.id} {...deleteDialog.dialogProps} />+ </>+ );+}diff --git a/apps/web/src/features/poll/components/poll-dates-list.tsx b/apps/web/src/features/poll/components/poll-dates-list.tsxnew file mode 100644index 000000000..d1f6bdd1b--- /dev/null+++ b/apps/web/src/features/poll/components/poll-dates-list.tsx@@ -0,0 +1,70 @@+"use client";++import { CalendarIcon } from "lucide-react";+import React from "react";+import {+ EmptyState,+ EmptyStateIcon,+ EmptyStateTitle,+} from "@/components/empty-state";+import { PollOptionsList } from "@/features/poll/components/poll-options-list";+import { VoteBar } from "@/features/poll/components/vote-bar";+import type { VoteType } from "@/features/poll/constants";+import { Trans } from "@/i18n/client";++type DateRow = {+ id: string;+ startTime: Date;+ duration: number;+ votes: { type: VoteType; count: number }[];+};++export function PollDatesList({+ kind,+ options,+ participantCount,+ timeZone,+}: {+ kind: "date" | "time";+ options: DateRow[];+ participantCount: number;+ timeZone: string | null;+}) {+ const renderValue = React.useCallback(+ (option: DateRow) => {+ const count = (type: VoteType) =>+ option.votes.find((vote) => vote.type === type)?.count ?? 0;+ return (+ <VoteBar+ className="w-16"+ yes={count("yes")}+ ifNeedBe={count("ifNeedBe")}+ total={participantCount}+ />+ );+ },+ [participantCount],+ );++ if (options.length === 0) {+ return (+ <EmptyState className="h-96">+ <EmptyStateIcon>+ <CalendarIcon />+ </EmptyStateIcon>+ <EmptyStateTitle>+ <Trans i18nKey="pollDatesListEmpty" defaults="No dates" />+ </EmptyStateTitle>+ </EmptyState>+ );+ }++ return (+ <PollOptionsList+ kind={kind}+ options={options}+ timeZone={timeZone}+ renderValue={renderValue}+ />+ );+}diff --git a/apps/web/src/features/poll/components/poll-layout.tsx b/apps/web/src/features/poll/components/poll-layout.tsxindex b34f03f94..b7133d0ca 100644--- a/apps/web/src/features/poll/components/poll-layout.tsx+++ b/apps/web/src/features/poll/components/poll-layout.tsx@@ -19,11 +19,16 @@ import { ShareDialog } from "@/features/poll/components/share-dialog";import { Trans } from "@/i18n/client";const AdminControls = () => {+ const poll = usePoll();return (<div className="flex items-center gap-x-2"><NotificationToggle /><ManagePoll />- <ShareDialog />+ <ShareDialog+ pollId={poll.id}+ pollStatus={poll.status}+ inviteLink={poll.inviteLink}+ /></div>);};diff --git a/apps/web/src/features/poll/components/poll-options-list.tsx b/apps/web/src/features/poll/components/poll-options-list.tsxnew file mode 100644index 000000000..0fde6228c--- /dev/null+++ b/apps/web/src/features/poll/components/poll-options-list.tsx@@ -0,0 +1,143 @@+"use client";++import { cn } from "@rallly/ui";+import {+ createColumnHelper,+ getCoreRowModel,+ useReactTable,+} from "@tanstack/react-table";+import React from "react";+import { DataList } from "@/components/data-list";+import { EventTimeRange } from "@/features/scheduled-event/components/event-date-time";+import { Trans } from "@/i18n/client";+import { CalendarDate } from "@/lib/datetime/calendar-date";+import { useDateTimeConfig } from "@/lib/datetime/client";+import {+ calendarDateToUTCMidnight,+ getCalendarDate,+} from "@/lib/datetime/utils";+import { getBrowserTimeZone } from "@/lib/utils/date-time-utils";++type OptionRow = {+ id: string;+ startTime: Date;+ duration: number;+};++/**+ * A poll's options as a list: grouped by day for a time poll, one row per+ * day for a date poll. `renderValue` fills the trailing column.+ */+export function PollOptionsList<TRow extends OptionRow>({+ kind,+ options,+ timeZone,+ renderValue,+ className,+}: {+ kind: "date" | "time";+ options: TRow[];+ timeZone: string | null;+ renderValue: (option: TRow) => React.ReactNode;+ className?: string;+}) {+ const viewerTimeZone = useDateTimeConfig().timeZone ?? getBrowserTimeZone();++ // All-day and floating options are stored as UTC wall time, so their day+ // is read in UTC; fixed times fall on the viewer's day.+ const dayKey = React.useCallback(+ (option: TRow) =>+ getCalendarDate(+ option.startTime,+ option.duration === 0 || timeZone === null ? "UTC" : viewerTimeZone,+ ),+ [timeZone, viewerTimeZone],+ );++ const columns = React.useMemo(() => {+ const columnHelper = createColumnHelper<TRow>();+ return [+ columnHelper.display({+ id: "option",+ header: () => (+ <Trans i18nKey="pollOptionsListOption" defaults="Option" />+ ),+ meta: { className: "text-sm" },+ cell: ({ row }) =>+ kind === "date" ? (+ <span className="flex min-w-0 gap-2">+ <CalendarDate+ value={row.original.startTime}+ preset="weekday"+ className="font-medium"+ />+ <CalendarDate+ value={row.original.startTime}+ preset="dateLong"+ className="truncate text-muted-foreground"+ />+ </span>+ ) : (+ <EventTimeRange+ start={row.original.startTime}+ end={+ new Date(+ row.original.startTime.getTime() ++ row.original.duration * 60_000,+ )+ }+ allDay={row.original.duration === 0}+ timeZone={timeZone}+ className="truncate"+ />+ ),+ }),+ columnHelper.display({+ id: "value",+ header: () => <Trans i18nKey="pollOptionsListValue" defaults="Value" />,+ meta: { className: "justify-end" },+ cell: ({ row }) => renderValue(row.original),+ }),+ ];+ }, [kind, renderValue, timeZone]);++ const table = useReactTable({+ data: options,+ columns,+ getCoreRowModel: getCoreRowModel(),+ getRowId: (option) => option.id,+ });++ return (+ <DataList+ table={table}+ // A date poll has one option per day, so a day header would repeat+ // the row it heads.+ getGroup={+ kind === "date"+ ? undefined+ : (option) => {+ const key = dayKey(option);+ return {+ id: key,+ label: (+ <>+ <CalendarDate+ value={calendarDateToUTCMidnight(key)}+ preset="weekday"+ className="font-medium text-foreground"+ />+ <CalendarDate+ value={calendarDateToUTCMidnight(key)}+ preset="dateLong"+ className="text-muted-foreground"+ />+ </>+ ),+ };+ }+ }+ className={cn("grid-cols-[minmax(0,1fr)_auto]", className)}+ />+ );+}diff --git a/apps/web/src/features/poll/components/poll-response-actions.tsx b/apps/web/src/features/poll/components/poll-response-actions.tsxnew file mode 100644index 000000000..d91c82933--- /dev/null+++ b/apps/web/src/features/poll/components/poll-response-actions.tsx@@ -0,0 +1,164 @@+"use client";++import { Button } from "@rallly/ui/button";+import {+ Dialog,+ DialogClose,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+ useDialog,+} from "@rallly/ui/dialog";+import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuTrigger,+} from "@rallly/ui/dropdown-menu";+import { toast } from "@rallly/ui/sonner";+import { LinkIcon, MoreHorizontalIcon, TrashIcon } from "lucide-react";+import { useRouter } from "next/navigation";+import { useCopyToClipboard } from "react-use";+import { useDeleteParticipant } from "@/features/poll/components/mutations";+import { Trans, useTranslation } from "@/i18n/client";++export function PollResponseActions({+ participantId,+ participantName,+ editUrl,+ pollOpen,+ onDelete,+}: {+ participantId: string;+ participantName: string;+ editUrl: string;+ pollOpen: boolean;+ onDelete?: () => void;+}) {+ const { t } = useTranslation();+ const router = useRouter();+ const deleteDialog = useDialog();+ const deleteParticipant = useDeleteParticipant();+ const [, copy] = useCopyToClipboard();++ return (+ <div className="relative z-10">+ <DropdownMenu>+ <DropdownMenuTrigger+ render={+ <Button+ aria-label={t("pollResponseActions", {+ defaultValue: "Actions for {name}",+ name: participantName,+ })}+ variant="ghost"+ size="icon"+ className="size-8"+ />+ }+ >+ <MoreHorizontalIcon />+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end">+ <DropdownMenuItem+ onClick={() => {+ copy(editUrl);+ toast(+ t("participantEditLinkCopied", {+ defaultValue: "Edit link for {name} copied",+ name: participantName,+ }),+ );+ }}+ >+ <LinkIcon />+ <Trans i18nKey="copyEditLink" defaults="Copy edit link" />+ </DropdownMenuItem>+ {/* A closed or scheduled poll accepts no changes to its responses */}+ <DropdownMenuItem+ variant="destructive"+ disabled={!pollOpen}+ onClick={() => deleteDialog.trigger()}+ className="items-start"+ >+ <TrashIcon className="mt-0.5" />+ <span className="flex flex-col">+ <Trans i18nKey="delete" defaults="Delete" />+ {pollOpen ? null : (+ <span className="text-muted-foreground text-xs">+ <Trans+ i18nKey="pollResponseActionsDeleteClosed"+ defaults="Reopen the poll to delete responses"+ />+ </span>+ )}+ </span>+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ <Dialog {...deleteDialog.dialogProps}>+ <DialogContent>+ <DialogHeader>+ <DialogTitle>+ <Trans+ i18nKey="deleteParticipant"+ defaults="Delete {name}?"+ values={{ name: participantName }}+ />+ </DialogTitle>+ <DialogDescription>+ <Trans+ i18nKey="deleteParticipantDescription"+ defaults="Are you sure you want to delete this participant? This action cannot be undone."+ />+ </DialogDescription>+ </DialogHeader>+ <DialogFooter>+ <DialogClose render={<Button />}>+ <Trans i18nKey="cancel" defaults="Cancel" />+ </DialogClose>+ <Button+ variant="destructive"+ loading={deleteParticipant.isPending}+ onClick={async () => {+ const result = await deleteParticipant.execute({+ participantId,+ });+ if (!result.ok) {+ toast.error(+ result.reason === "closed"+ ? t("pollClosedDescription", {+ defaultValue: "No more responses are being accepted.",+ })+ : t("actionErrorInternalServerError", {+ defaultValue: "An internal server error occurred",+ }),+ );+ return;+ }+ deleteDialog.dismiss();+ toast(+ t("pollResponseDeleted", {+ defaultValue: "Response from {name} deleted",+ name: participantName,+ }),+ );+ if (onDelete) {+ onDelete();+ } else {+ // The admin pages are server rendered, so the list only+ // drops the row once they are fetched again.+ router.refresh();+ }+ }}+ >+ <Trans i18nKey="delete" defaults="Delete" />+ </Button>+ </DialogFooter>+ </DialogContent>+ </Dialog>+ </div>+ );+}diff --git a/apps/web/src/features/poll/components/poll-response-detail.tsx b/apps/web/src/features/poll/components/poll-response-detail.tsxnew file mode 100644index 000000000..2ab2258bb--- /dev/null+++ b/apps/web/src/features/poll/components/poll-response-detail.tsx@@ -0,0 +1,170 @@+"use client";++import { cn } from "@rallly/ui";+import { Card } from "@rallly/ui/card";+import { ArrowLeftIcon } from "lucide-react";+import { useRouter } from "next/navigation";+import React from "react";+import { Link } from "@/components/link";+import { OptimizedAvatarImage } from "@/components/optimized-avatar-image";+import { PollOptionsList } from "@/features/poll/components/poll-options-list";+import { PollResponseActions } from "@/features/poll/components/poll-response-actions";+import VoteIcon from "@/features/poll/components/vote-icon";+import type { VoteType } from "@/features/poll/constants";+import { Trans } from "@/i18n/client";++function VoteLabel({ type }: { type?: VoteType }) {+ switch (type) {+ case "yes":+ return <Trans i18nKey="yes" defaults="Yes" />;+ case "ifNeedBe":+ return <Trans i18nKey="ifNeedBe" defaults="If need be" />;+ case "no":+ return <Trans i18nKey="no" defaults="No" />;+ default:+ return <Trans i18nKey="pollResponseDetailNoVote" defaults="No answer" />;+ }+}++/**+ * The card the detail pane shows, filling the pane and scrolling on its own,+ * whether it holds a response or an empty state.+ */+export function PollResponseDetailCard({+ children,+ header,+ className,+}: {+ children: React.ReactNode;+ header?: React.ReactNode;+ className?: string;+}) {+ return (+ <div className="flex h-full flex-col gap-4 px-2 pt-0 pb-2 md:pl-0">+ {header}+ <Card className={cn("min-h-0 flex-1 overflow-y-auto p-5", className)}>+ {children}+ </Card>+ </div>+ );+}++export function PollResponseDetail({+ pollId,+ pollOpen,+ kind,+ timeZone,+ response,+ options,+ activity,+}: {+ pollId: string;+ pollOpen: boolean;+ kind: "date" | "time";+ timeZone: string | null;+ response: {+ id: string;+ name: string;+ email: string | null;+ note: string | null;+ image: string | null;+ createdAt: Date;+ editUrl: string;+ votes: { optionId: string; type: VoteType }[];+ };+ options: { id: string; startTime: Date; duration: number }[];+ activity: React.ReactNode;+}) {+ const router = useRouter();+ const voteByOptionId = React.useMemo(+ () => new Map(response.votes.map((vote) => [vote.optionId, vote.type])),+ [response.votes],+ );+ const renderVote = React.useCallback(+ (option: { id: string }) => {+ const type = voteByOptionId.get(option.id);+ return (+ <span className="flex items-center gap-2 text-muted-foreground text-sm">+ <VoteIcon type={type} size="sm" />+ <VoteLabel type={type} />+ </span>+ );+ },+ [voteByOptionId],+ );++ return (+ <PollResponseDetailCard+ className="space-y-8"+ header={+ <Link+ href={`/polls/${pollId}/responses`}+ scroll={false}+ className="inline-flex items-center gap-1.5 text-muted-foreground text-sm hover:text-foreground md:hidden"+ >+ <ArrowLeftIcon className="size-4" />+ <Trans i18nKey="responses" defaults="Responses" />+ </Link>+ }+ >+ <div className="flex items-start gap-3">+ <OptimizedAvatarImage+ size="lg"+ name={response.name}+ src={response.image ?? undefined}+ />+ <div className="min-w-0 flex-1">+ <h2 className="truncate font-semibold text-base">{response.name}</h2>+ <p className="truncate text-muted-foreground text-sm">+ {response.email || (+ <i>+ <Trans+ i18nKey="pollResponseDetailNoEmail"+ defaults="No email provided"+ />+ </i>+ )}+ </p>+ </div>+ <PollResponseActions+ participantId={response.id}+ participantName={response.name}+ editUrl={response.editUrl}+ pollOpen={pollOpen}+ onDelete={() => router.replace(`/polls/${pollId}/responses`)}+ />+ </div>+ {response.note ? (+ <section className="space-y-2">+ <h3 className="font-medium text-sm">+ <Trans i18nKey="pollResponseDetailNote" defaults="Note" />+ </h3>+ <p className="whitespace-pre-wrap break-words rounded-lg border bg-card px-3 py-2 text-sm">+ {response.note}+ </p>+ </section>+ ) : null}+ <section className="space-y-2">+ <h3 className="font-medium text-sm">+ <Trans+ i18nKey="pollResponseDetailAvailability"+ defaults="Availability"+ />+ </h3>+ <PollOptionsList+ kind={kind}+ options={options}+ timeZone={timeZone}+ renderValue={renderVote}+ className="-mx-4 py-0"+ />+ </section>+ <section className="space-y-2">+ <h3 className="font-medium text-sm">+ <Trans i18nKey="pollResponseDetailActivity" defaults="Activity" />+ </h3>+ {activity}+ </section>+ </PollResponseDetailCard>+ );+}diff --git a/apps/web/src/features/poll/components/poll-responses-list.tsx b/apps/web/src/features/poll/components/poll-responses-list.tsxnew file mode 100644index 000000000..a1cf49cbd--- /dev/null+++ b/apps/web/src/features/poll/components/poll-responses-list.tsx@@ -0,0 +1,164 @@+"use client";++import { cn } from "@rallly/ui";+import {+ createColumnHelper,+ getCoreRowModel,+ useReactTable,+} from "@tanstack/react-table";+import { InboxIcon } from "lucide-react";+import React from "react";+import { DataList } from "@/components/data-list";+import {+ EmptyState,+ EmptyStateDescription,+ EmptyStateIcon,+ EmptyStateTitle,+} from "@/components/empty-state";+import { Link } from "@/components/link";+import { OptimizedAvatarImage } from "@/components/optimized-avatar-image";+import { PollResponseActions } from "@/features/poll/components/poll-response-actions";+import { Trans } from "@/i18n/client";+import { RelativeTime } from "@/lib/datetime/relative-time";++type ResponseRow = {+ id: string;+ name: string;+ note: string | null;+ image: string | null;+ createdAt: Date;+ editUrl: string;+};++const columnHelper = createColumnHelper<ResponseRow>();++/**+ * Responses as rows that open the response on the Responses page. `compact`+ * is the split view's list: the detail beside it carries the note and the+ * actions.+ */+export function PollResponsesList({+ pollId,+ participants,+ pollOpen,+ selectedId,+ compact = false,+ className,+}: {+ pollId: string;+ participants: ResponseRow[];+ pollOpen: boolean;+ selectedId?: string;+ compact?: boolean;+ className?: string;+}) {+ const columns = React.useMemo(+ () => [+ columnHelper.accessor("name", {+ header: () => <Trans i18nKey="name" defaults="Name" />,+ cell: ({ row }) => (+ <div className="flex min-w-0 items-center gap-3">+ <OptimizedAvatarImage+ size="sm"+ name={row.original.name}+ src={row.original.image ?? undefined}+ />+ <div className="min-w-0">+ <Link+ href={`/polls/${pollId}/responses?responseId=${row.original.id}`}+ aria-current={+ row.original.id === selectedId ? "page" : undefined+ }+ scroll={false}+ className="block truncate text-sm outline-none after:absolute after:inset-0"+ >+ {row.original.name}+ </Link>+ </div>+ </div>+ ),+ }),+ ...(compact+ ? []+ : [+ columnHelper.accessor("note", {+ header: () => (+ <Trans i18nKey="pollResponsesListNote" defaults="Note" />+ ),+ meta: {+ className: "hidden text-muted-foreground text-sm sm:flex",+ },+ cell: ({ getValue }) => (+ <span className="truncate" title={getValue() ?? undefined}>+ {getValue()}+ </span>+ ),+ }),+ ]),+ columnHelper.accessor("createdAt", {+ header: () => <Trans i18nKey="respondedOn" defaults="Responded on" />,+ meta: {+ className: "justify-end text-muted-foreground text-xs",+ },+ cell: ({ getValue }) => <RelativeTime value={getValue()} />,+ }),+ ...(compact+ ? []+ : [+ columnHelper.display({+ id: "actions",+ header: () => (+ <Trans i18nKey="pollResponsesListActions" defaults="Actions" />+ ),+ cell: ({ row }) => (+ <PollResponseActions+ participantId={row.original.id}+ participantName={row.original.name}+ editUrl={row.original.editUrl}+ pollOpen={pollOpen}+ />+ ),+ }),+ ]),+ ],+ [compact, pollId, pollOpen, selectedId],+ );++ const table = useReactTable({+ data: participants,+ columns,+ getCoreRowModel: getCoreRowModel(),+ getRowId: (participant) => participant.id,+ });++ if (participants.length === 0) {+ return (+ <EmptyState className="h-96">+ <EmptyStateIcon>+ <InboxIcon />+ </EmptyStateIcon>+ <EmptyStateTitle>+ <Trans i18nKey="pollResponsesListEmpty" defaults="No responses" />+ </EmptyStateTitle>+ <EmptyStateDescription>+ <Trans+ i18nKey="pollResponsesListEmptyDescription"+ defaults="Responses will show up here once participants vote."+ />+ </EmptyStateDescription>+ </EmptyState>+ );+ }++ return (+ <DataList+ table={table}+ className={cn(+ compact+ ? "grid-cols-[minmax(0,1fr)_auto]"+ : "grid-cols-[minmax(0,1fr)_auto_auto] sm:grid-cols-[minmax(0,1fr)_minmax(0,1.5fr)_auto_auto]",+ className,+ )}+ />+ );+}diff --git a/apps/web/src/features/poll/components/poll-top-dates.tsx b/apps/web/src/features/poll/components/poll-top-dates.tsxnew file mode 100644index 000000000..e18e95a8e--- /dev/null+++ b/apps/web/src/features/poll/components/poll-top-dates.tsx@@ -0,0 +1,80 @@+"use client";++import { cn } from "@rallly/ui";+import { Card } from "@rallly/ui/card";+import { VoteBar } from "@/features/poll/components/vote-bar";+import type { VoteType } from "@/features/poll/constants";+import {+ EventCalendarCard,+ EventDate,+ EventTimeRange,+} from "@/features/scheduled-event/components/event-date-time";++type TopOption = {+ id: string;+ startTime: Date;+ duration: number;+ votes: { type: VoteType; count: number }[];+};++export function PollTopDates({+ options,+ participantCount,+ timeZone,+ className,+}: {+ options: TopOption[];+ participantCount: number;+ timeZone: string | null;+ className?: string;+}) {+ return (+ <ul className={cn("grid gap-4 sm:grid-cols-3", className)}>+ {options.map((option) => {+ const allDay = option.duration === 0;+ const count = (type: VoteType) =>+ option.votes.find((vote) => vote.type === type)?.count ?? 0;++ return (+ <li key={option.id}>+ <Card className="flex h-full flex-col gap-4 p-3.5">+ <div className="flex items-center gap-3">+ <EventCalendarCard+ start={option.startTime}+ allDay={allDay}+ timeZone={timeZone}+ />+ <div className="min-w-0 text-sm">+ <EventDate+ value={option.startTime}+ allDay={allDay}+ timeZone={timeZone}+ preset="weekday"+ className="block truncate font-medium"+ />+ <EventTimeRange+ start={option.startTime}+ end={+ new Date(+ option.startTime.getTime() + option.duration * 60_000,+ )+ }+ allDay={allDay}+ timeZone={timeZone}+ className="block truncate text-muted-foreground"+ />+ </div>+ </div>+ <VoteBar+ className="mt-auto w-full"+ yes={count("yes")}+ ifNeedBe={count("ifNeedBe")}+ total={participantCount}+ />+ </Card>+ </li>+ );+ })}+ </ul>+ );+}diff --git a/apps/web/src/features/poll/components/share-dialog.tsx b/apps/web/src/features/poll/components/share-dialog.tsxindex 4b3e96d86..2a0e2a70f 100644--- a/apps/web/src/features/poll/components/share-dialog.tsx+++ b/apps/web/src/features/poll/components/share-dialog.tsx@@ -14,15 +14,22 @@ import { Separator } from "@rallly/ui/separator";import { Share2Icon } from "lucide-react";import React from "react";import { useIsFree } from "@/features/billing/client";-import { usePoll } from "@/features/poll/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";-export function ShareDialog() {- const poll = usePoll();+export function ShareDialog({+ pollId,+ pollStatus,+ inviteLink,+}: {+ pollId: string;+ pollStatus: PollStatus;+ inviteLink: string;+}) {const dialog = useDialog();const isFree = useIsFree();const isOpen = dialog.dialogProps.open;@@ -35,7 +42,7 @@ export function ShareDialog() {// replay it.// biome-ignore lint/correctness/useExhaustiveDependencies: runs once per flash arrivalReact.useEffect(() => {- if (sharePollFlash !== poll.id) return;+ if (sharePollFlash !== pollId) return;openSource.current = "poll_created";dialog.trigger();}, [sharePollFlash]);@@ -43,12 +50,12 @@ export function ShareDialog() {React.useEffect(() => {if (!isOpen) return;posthog?.capture("poll_share:dialog_open", {- poll_id: poll.id,+ poll_id: pollId,tier: isFree ? "free" : "pro",source: openSource.current,});openSource.current = "manual";- }, [isOpen, poll.id, isFree]);+ }, [isOpen, pollId, isFree]);return (<>@@ -71,9 +78,9 @@ export function ShareDialog() {/></DialogDescription></DialogHeader>- <InviteLinkRow inviteLink={poll.inviteLink} />+ <InviteLinkRow pollId={pollId} inviteLink={inviteLink} /><Separator />- <InviteByEmail />+ <InviteByEmail pollId={pollId} pollStatus={pollStatus} /></DialogContent></Dialog></>diff --git a/apps/web/src/features/poll/components/vote-bar.tsx b/apps/web/src/features/poll/components/vote-bar.tsxnew file mode 100644index 000000000..294cf192b--- /dev/null+++ b/apps/web/src/features/poll/components/vote-bar.tsx@@ -0,0 +1,39 @@+"use client";++import { cn } from "@rallly/ui";+import { useTranslation } from "@/i18n/client";++export function VoteBar({+ yes,+ ifNeedBe,+ total,+ className,+}: {+ yes: number;+ ifNeedBe: number;+ total: number;+ className?: string;+}) {+ const { t } = useTranslation();+ const width = (count: number) =>+ total > 0 ? `${(count / total) * 100}%` : "0%";+ return (+ <div+ role="img"+ aria-label={t("voteBarLabel", {+ defaultValue:+ "{yes} yes, {ifNeedBe} if need be, out of {total, plural, one {1 response} other {# responses}}",+ yes,+ ifNeedBe,+ total,+ })}+ className={cn(+ "flex h-1.5 overflow-hidden rounded-sm bg-muted",+ className,+ )}+ >+ <div className="h-full bg-green-500" style={{ width: width(yes) }} />+ <div className="h-full bg-amber-400" style={{ width: width(ifNeedBe) }} />+ </div>+ );+}diff --git a/apps/web/src/features/poll/data.ts b/apps/web/src/features/poll/data.tsindex c0175d2a7..7613ec3dc 100644--- a/apps/web/src/features/poll/data.ts+++ b/apps/web/src/features/poll/data.ts@@ -45,6 +45,7 @@ export async function getPoll({id: true,title: true,status: true,+ timeZone: true,},});}diff --git a/apps/web/src/features/poll/loaders.ts b/apps/web/src/features/poll/loaders.tsindex 00a7e73bc..b0b59039e 100644--- a/apps/web/src/features/poll/loaders.ts+++ b/apps/web/src/features/poll/loaders.ts@@ -3,12 +3,14 @@ import "server-only";import { shortUrl } from "@rallly/utils/absolute-url";import { notFound, redirect } from "next/navigation";import { cache } from "react";+import { listPollActivity } from "@/features/activity/data";import { loadConferencingOptions } from "@/features/conferencing/loaders";import {canUserManagePoll,getPoll,getPollAvailability,getPollDetails,+ getPollResults,getPollStatusCounts,listParticipantIdsByToken,listPollComments,@@ -39,6 +41,110 @@ export const loadPoll = cache(async (pollId: string) => {return poll;});+// Responses for the poll admin pages. loadPoll proves the poll is in the+// viewer's space before any response is read; one read of the full rows per+// request is shared by the list and the detail.+const loadParticipantRows = cache(async (pollId: string) => {+ await loadPoll(pollId);+ return listPollParticipants({ pollId });+});++// The link from the response's confirmation email, for the host to hand to+// a respondent who lost it.+const getEditUrl = ({ pollId, token }: { pollId: string; token: string }) =>+ shortUrl(getPollInvitePath({ pollId, token }));++export const loadPollParticipants = cache(async (pollId: string) => {+ const participants = await loadParticipantRows(pollId);+ return participants.map(({ id, name, note, image, createdAt, token }) => ({+ id,+ name,+ note,+ image,+ createdAt,+ editUrl: getEditUrl({ pollId, token }),+ }));+});++/**+ * One response with its votes, or null when it no longer exists (e.g. it+ * was deleted while its link stayed open).+ */+export const loadOptionalPollResponse = cache(+ async (pollId: string, participantId: string) => {+ const participants = await loadParticipantRows(pollId);+ const participant = participants.find(({ id }) => id === participantId);++ if (!participant) {+ return null;+ }++ const { token, userId: _userId, ...rest } = participant;+ return { ...rest, editUrl: getEditUrl({ pollId, token }) };+ },+);++/**+ * Every option with its vote counts, in date order.+ */+export const loadPollResults = cache(async (pollId: string) => {+ const [scope] = await Promise.all([+ loadActiveSpaceContentScope(),+ loadPoll(pollId),+ ]);+ const results = await getPollResults({ pollId, spaceId: scope.spaceId });++ if (!results) {+ notFound();+ }++ return results;+});++/**+ * The poll's most popular options, best first. Options nobody can attend are+ * left out, so a poll without votes has none.+ */+export const loadPollTopOptions = cache(+ async (pollId: string, limit: number) => {+ const results = await loadPollResults(pollId);+ return {+ participantCount: results.participantCount,+ options: results.options+ .filter((option) => option.score > 0)+ .sort(+ (a, b) =>+ b.score - a.score || a.startTime.getTime() - b.startTime.getTime(),+ )+ .slice(0, limit),+ };+ },+);++export const loadPollActivity = cache(+ async (pollId: string, limit?: number) => {+ const [scope] = await Promise.all([+ loadActiveSpaceContentScope(),+ loadPoll(pollId),+ ]);+ return listPollActivity({ pollId, spaceId: scope.spaceId, limit });+ },+);++export const loadPollResponseActivity = cache(+ async (pollId: string, participantId: string) => {+ const [scope] = await Promise.all([+ loadActiveSpaceContentScope(),+ loadPoll(pollId),+ ]);+ return listPollActivity({+ pollId,+ spaceId: scope.spaceId,+ participantId,+ });+ },+);+/*** The token from the emailed link is its own proof of scope: no session is* consulted, so a forwarded link acts for the response it names.diff --git a/apps/web/src/features/poll/participant/mutations.ts b/apps/web/src/features/poll/participant/mutations.tsindex a58d2f9da..4f329a772 100644--- a/apps/web/src/features/poll/participant/mutations.ts+++ b/apps/web/src/features/poll/participant/mutations.ts@@ -237,7 +237,10 @@ export async function addParticipant({type: "response_created",userId,participantId: participant.id,- payload: { name: participant.name },+ payload: {+ name: participant.name,+ ...(participant.note && { note: participant.note }),+ },},]);scheduleWebhookDispatch({ pollId: pollId });