Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
✨ Make auto-closed polls discoverable (#2711)
Luke Vella73747523ab2f
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.jsonindex a338a5260..62bf8bd27 100644--- a/apps/web/public/locales/en/app.json+++ b/apps/web/public/locales/en/app.json@@ -451,6 +451,8 @@"noKeepCurrentTimezone": "No, keep the current timezone","noLicenseKey": "No license key found","noLicenseKeyDescription": "This instance doesn’t have a license key yet.",+ "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}}.","noParticipants": "No participants","noParticipantsDescription": "Click <b>Share</b> to invite participants","noPolls": "No polls",@@ -513,6 +515,9 @@"planFree": "Free","planHobbyDescription": "For casual users","planProDescription": "For professionals and power users",+ "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.","pollDeleted": "Poll deleted",@@ -737,6 +742,7 @@"verifyEmail": "Verify your email","verifyEmailDescription": "Enter the 6-digit code we sent to <b>{email}</b>","verifyEmailTitle": "Verify Your Email",+ "viewClosedPolls": "View closed polls","viewPoll": "View poll","viewResults": "View results","weekView": "Week view",diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/page.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/page.tsxindex 54d5160df..7c2f7c3ca 100644--- a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/page.tsx+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/page.tsx@@ -1,5 +1,7 @@import { dehydrate, HydrationBoundary } from "@tanstack/react-query";import type { Metadata } from "next";+import { getPollStatusCounts } from "@/features/poll/data";+import { getActiveSpace } from "@/features/space/data";import { getTranslation } from "@/i18n/server";import { createPrivateSSRHelper } from "@/trpc/server/create-ssr-helper";import { PollsPage } from "./polls-page";@@ -11,9 +13,11 @@ export default async function Page(props: {const searchParams = await props.searchParams;const { status, q, member } = searchParamsSchema.parse(searchParams);+ const space = await getActiveSpace();const helpers = await createPrivateSSRHelper();- await Promise.all([+ const [counts] = await Promise.all([+ getPollStatusCounts({ spaceId: space.id }),helpers.spaces.listMembers.prefetch(),helpers.polls.infiniteChronological.prefetchInfinite({status,@@ -24,7 +28,7 @@ export default async function Page(props: {return (<HydrationBoundary state={dehydrate(helpers.queryClient)}>- <PollsPage />+ <PollsPage counts={counts} /></HydrationBoundary>);}diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/polls-page.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/polls-page.tsxindex 182295ee5..2ab80804b 100644--- a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/polls-page.tsx+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/polls-page.tsx@@ -1,7 +1,7 @@"use client";import { buttonVariants } from "@rallly/ui";-import { InboxIcon, PlusIcon } from "lucide-react";+import { CircleStopIcon, InboxIcon, PlusIcon } from "lucide-react";import Link from "next/link";import { useSearchParams } from "next/navigation";import {@@ -22,11 +22,43 @@ import {} from "@/components/page-layout";import { SearchInput } from "@/components/search-input";import { PollsInfiniteList } from "@/features/poll/components/polls-infinite-list";+import type { PollStatus } from "@/features/poll/schema";import { Trans, useTranslation } from "@/i18n/client";import { trpc } from "@/trpc/client";import { PollsTabbedView } from "./polls-tabbed-view";import { searchParamsSchema } from "./schema";+function NoOpenPollsEmptyState({ closedCount }: { closedCount: number }) {+ return (+ <EmptyState className="h-96">+ <EmptyStateIcon>+ <CircleStopIcon />+ </EmptyStateIcon>+ <EmptyStateTitle>+ <Trans i18nKey="noOpenPolls" defaults="No open polls" />+ </EmptyStateTitle>+ <EmptyStateDescription>+ <Trans+ i18nKey="noOpenPollsDescription"+ defaults="Polls close automatically once all of their dates have passed. You have {count, plural, one {1 closed poll} other {# closed polls}}."+ values={{ count: closedCount }}+ />+ </EmptyStateDescription>+ <EmptyStateFooter className="flex flex-wrap justify-center gap-2">+ <Link+ href="?status=closed"+ className={buttonVariants({ variant: "primary" })}+ >+ <Trans i18nKey="viewClosedPolls" defaults="View closed polls" />+ </Link>+ <Link href="/new" className={buttonVariants()}>+ <Trans i18nKey="createPoll" defaults="Create Poll" />+ </Link>+ </EmptyStateFooter>+ </EmptyState>+ );+}+function PollsEmptyState() {return (<EmptyState className="h-96">@@ -51,7 +83,7 @@ function PollsEmptyState() {);}-export function PollsPage() {+export function PollsPage({ counts }: { counts: Record<PollStatus, number> }) {const searchParams = useSearchParams();const { t } = useTranslation();const [{ data: members }] = trpc.spaces.listMembers.useSuspenseQuery();@@ -60,6 +92,10 @@ export function PollsPage() {Object.fromEntries(searchParams.entries()),);+ const hasFilters = Boolean(q || member);+ const showClosedPollsPointer =+ status === "open" && !hasFilters && counts.closed > 0;+return (<PageContainer><PageHeader>@@ -76,7 +112,7 @@ export function PollsPage() {</PageHeaderActions></PageHeader><PageContent>- <PollsTabbedView>+ <PollsTabbedView counts={counts}><div className="mb-6 flex gap-x-2"><SearchInputplaceholder={t("searchPollsPlaceholder", {@@ -89,7 +125,13 @@ export function PollsPage() {status={status}search={q}member={member}- emptyState={<PollsEmptyState />}+ emptyState={+ showClosedPollsPointer ? (+ <NoOpenPollsEmptyState closedCount={counts.closed} />+ ) : (+ <PollsEmptyState />+ )+ }/></PollsTabbedView></PageContent>diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/polls-tabbed-view.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/polls-tabbed-view.tsxindex d4ee0520b..e4ecad36e 100644--- a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/polls-tabbed-view.tsx+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/polls-tabbed-view.tsx@@ -7,13 +7,32 @@ import React from "react";import { Trans } from "@/i18n/client";import { statusSchema } from "./schema";-export function PollsTabbedView({ children }: { children: React.ReactNode }) {+function TabCount({ count }: { count: number }) {+ return (+ <span className="ml-2 rounded-full bg-muted px-2 py-0.5 text-muted-foreground text-xs tabular-nums">+ {count}+ </span>+ );+}++export function PollsTabbedView({+ counts,+ children,+}: {+ counts: { open: number; closed: number; scheduled: number };+ children: React.ReactNode;+}) {const searchParams = useSearchParams();const name = "status";const router = useRouter();const [isPending, startTransition] = React.useTransition();const status = statusSchema.parse(searchParams.get("status"));const [tab, setTab] = React.useState(status);++ React.useEffect(() => {+ setTab(status);+ }, [status]);+const handleTabChange = React.useCallback((value: string) => {const params = new URLSearchParams(searchParams);@@ -36,12 +55,15 @@ export function PollsTabbedView({ children }: { children: React.ReactNode }) {<TabsList><TabsTrigger value="open"><Trans i18nKey="pollStatusOpen" defaults="Open" />+ <TabCount count={counts.open} /></TabsTrigger><TabsTrigger value="closed"><Trans i18nKey="pollStatusClosed" defaults="Closed" />+ <TabCount count={counts.closed} /></TabsTrigger><TabsTrigger value="scheduled"><Trans i18nKey="pollStatusScheduled" defaults="Scheduled" />+ <TabCount count={counts.scheduled} /></TabsTrigger></TabsList><TabsContentdiff --git a/apps/web/src/features/poll/components/polls-infinite-list.tsx b/apps/web/src/features/poll/components/polls-infinite-list.tsxindex 4ea13ce5c..014073eeb 100644--- a/apps/web/src/features/poll/components/polls-infinite-list.tsx+++ b/apps/web/src/features/poll/components/polls-infinite-list.tsx@@ -1,5 +1,6 @@"use client";+import { Badge } from "@rallly/ui/badge";import { Button } from "@rallly/ui/button";import {Dialog,@@ -28,6 +29,7 @@ import {StickerIcon,TrashIcon,} from "lucide-react";+import { useRouter } from "next/navigation";import React from "react";import { CopyLinkButton } from "@/components/copy-link-button";import { HoverPrefetchLink } from "@/components/hover-prefetch-link";@@ -35,7 +37,7 @@ import { OptimizedAvatarImage } from "@/components/optimized-avatar-image";import { Spinner } from "@/components/spinner";import { StackedList, StackedListItem } from "@/components/stacked-list";import { PollStatusIcon } from "@/features/poll/components/poll-status-icon";-import type { PollStatus } from "@/features/poll/schema";+import type { PollClosedReason, PollStatus } from "@/features/poll/schema";import { Trans, useTranslation } from "@/i18n/client";import { trpc } from "@/trpc/client";@@ -50,20 +52,26 @@ function PollListItem({id,title,status,+ closedReason,participants,user,}: {id: string;title: string;status: PollStatus;+ closedReason: PollClosedReason | null;participants: { id: string; name: string }[];user: { name: string; image: string | null } | null;}) {const { t } = useTranslation();+ const router = useRouter();const deletePollDialog = useDialog();- const deletePoll = trpc.polls.markAsDeleted.useMutation();- const closePoll = trpc.polls.close.useMutation();- const reopenPoll = trpc.polls.reopen.useMutation();+ // Refresh server components so server-fetched data that depends on poll+ // status (e.g. the status tab counts) stays in sync with the list.+ const refresh = { onSuccess: () => router.refresh() };+ const deletePoll = trpc.polls.markAsDeleted.useMutation(refresh);+ const closePoll = trpc.polls.close.useMutation(refresh);+ const reopenPoll = trpc.polls.reopen.useMutation(refresh);return (<><div className="grid w-full grid-cols-[1fr_auto] gap-2">@@ -76,6 +84,26 @@ function PollListItem({<span className="absolute inset-0" /><span className="block truncate">{title}</span></HoverPrefetchLink>+ {status === "closed" && closedReason === "auto" && (+ <Tooltip>+ <TooltipTrigger+ render={+ <Badge size="sm" className="relative cursor-help">+ <Trans+ i18nKey="pollAutoClosedBadge"+ defaults="Automatically closed"+ />+ </Badge>+ }+ />+ <TooltipContent>+ <Trans+ i18nKey="pollAutoClosedTooltip"+ defaults="This poll was closed automatically because all of its dates have passed. You can reopen it at any time."+ />+ </TooltipContent>+ </Tooltip>+ )}</div><div className="hidden items-center justify-end gap-4 sm:flex">{participants.length > 0 ? (@@ -300,12 +328,13 @@ export function PollsInfiniteList({return (<StackedList>- {polls.map(({ id, title, status, participants, user }) => (+ {polls.map(({ id, title, status, closedReason, participants, user }) => (<StackedListItem key={id}><PollListItemid={id}title={title}status={status}+ closedReason={closedReason}participants={participants}user={user}/>diff --git a/apps/web/src/features/poll/components/responsive-results.tsx b/apps/web/src/features/poll/components/responsive-results.tsxindex ff6910a8e..4a7457840 100644--- a/apps/web/src/features/poll/components/responsive-results.tsx+++ b/apps/web/src/features/poll/components/responsive-results.tsx@@ -100,10 +100,17 @@ export function ResponsiveResults() {<Trans i18nKey="pollStatusClosed" defaults="Closed" /></EmptyStateTitle><EmptyStateDescription>- <Trans- i18nKey="pollClosedDescription"- defaults="No more responses are being accepted."- />+ {poll.closedReason === "auto" ? (+ <Trans+ i18nKey="pollAutoClosedDescription"+ defaults="This poll was closed automatically because all of its dates have passed. No more responses are being accepted."+ />+ ) : (+ <Trans+ i18nKey="pollClosedDescription"+ defaults="No more responses are being accepted."+ />+ )}</EmptyStateDescription><EmptyStateFooter><Button onClick={() => setDismissed(true)}>diff --git a/apps/web/src/features/poll/data.ts b/apps/web/src/features/poll/data.tsindex de6435bc4..d32880e5b 100644--- a/apps/web/src/features/poll/data.ts+++ b/apps/web/src/features/poll/data.ts@@ -186,6 +186,7 @@ export const getPolls = async ({id: true,title: true,status: true,+ closedReason: true,createdAt: true,updatedAt: true,user: {@@ -220,6 +221,7 @@ export const getPolls = async ({id: poll.id,title: poll.title,status: poll.status,+ closedReason: poll.closedReason,createdAt: poll.createdAt,updatedAt: poll.updatedAt,user: poll.user@@ -248,6 +250,36 @@ export const getPolls = async ({};};+export const getPollStatusCounts = async ({+ spaceId,+}: {+ spaceId: AuthorizedSpaceId;+}) => {+ const res = await prisma.poll.groupBy({+ by: ["status"],+ where: {+ spaceId,+ deletedAt: null,+ },+ _count: {+ status: true,+ },+ });++ const counts: Record<PollStatus, number> = {+ open: 0,+ closed: 0,+ scheduled: 0,+ canceled: 0,+ };++ for (const { status, _count } of res) {+ counts[status] = _count.status;+ }++ return counts;+};+export async function canUserManagePoll(user: {id: string;diff --git a/apps/web/src/features/poll/schema.ts b/apps/web/src/features/poll/schema.tsindex 6e1df71fc..7aaa583c4 100644--- a/apps/web/src/features/poll/schema.ts+++ b/apps/web/src/features/poll/schema.ts@@ -15,3 +15,7 @@ export const pollStatusSchema = z.enum([]);export type PollStatus = z.infer<typeof pollStatusSchema>;++export const pollClosedReasonSchema = z.enum(["auto", "manual"]);++export type PollClosedReason = z.infer<typeof pollClosedReasonSchema>;diff --git a/apps/web/src/trpc/routers/polls.ts b/apps/web/src/trpc/routers/polls.tsindex 9ac501f3c..8de1f5c1e 100644--- a/apps/web/src/trpc/routers/polls.ts+++ b/apps/web/src/trpc/routers/polls.ts@@ -1,4 +1,3 @@-import type { PollStatus } from "@rallly/database";import { prisma } from "@rallly/database";import { sendFinalizeHostEmail } from "@rallly/emails/templates/finalized-host";import { sendFinalizeParticipantEmail } from "@rallly/emails/templates/finalized-participant";@@ -85,27 +84,6 @@ export const polls = router({total: result.total,};}),- getCountByStatus: privateProcedure.query(async ({ ctx }) => {- const res = await prisma.poll.groupBy({- by: ["status"],- where: {- userId: ctx.user.id,- deletedAt: null,- },- _count: {- status: true,- },- });-- return res.reduce(- (acc, { status, _count }) => {- acc[status] = _count.status;- return acc;- },- {} as Record<PollStatus, number>,- );- }),-make: possiblyPublicProcedure.input(z.object({@@ -640,6 +618,7 @@ export const polls = router({createdAt: true,participantUrlId: true,status: true,+ closedReason: true,hideParticipants: true,disableComments: true,hideScores: true,