Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
✨ Add poll admin shell at /polls/[pollId] behind a dev-only flag (#3074)
Luke Vella1074d1d8741b
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.jsonindex 81dcb36d1..1d52b991c 100644--- a/apps/web/public/locales/en/app.json+++ b/apps/web/public/locales/en/app.json@@ -24,6 +24,7 @@"actionErrorUnauthorized": "You are not authorized to perform this action","activate": "Activate","active": "Active",+ "activity": "Activity","addComment": "Add comment","addDescription": "Add description","addLicenseKey": "Add license key",@@ -572,6 +573,7 @@"organizationNameRequired": "Organization name is required","organizedBy": "Organized by {name}","outlook": "Outlook",+ "overview": "Overview","owner": "Owner","ownerPermissionsRequired": "Only space owners can access billing settings.","paginationItems": "Showing {startItem}–{endItem} of {totalItems}",@@ -678,6 +680,7 @@"respondedOn": "Responded on","response": "Response","responseOptions": "Response options",+ "responses": "Responses","revoke": "Revoke","revokeConfirmation": "Are you sure you want to revoke {name}? This will immediately disable the key.","revoked": "Revoked",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.tsxnew file mode 100644index 000000000..ed22960a0--- /dev/null+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/activity/page.tsx@@ -0,0 +1,11 @@+import { loadPoll } from "@/features/poll/loaders";++export default async function Page({+ params,+}: {+ params: Promise<{ pollId: string }>;+}) {+ const { pollId } = await params;+ await loadPoll(pollId);+ return null;+}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.tsxnew file mode 100644index 000000000..ed22960a0--- /dev/null+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/dates/page.tsx@@ -0,0 +1,11 @@+import { loadPoll } from "@/features/poll/loaders";++export default async function Page({+ params,+}: {+ params: Promise<{ pollId: string }>;+}) {+ const { pollId } = await params;+ await loadPoll(pollId);+ return null;+}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.tsxnew file mode 100644index 000000000..6e3686866--- /dev/null+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/layout.tsx@@ -0,0 +1,68 @@+import { buttonVariants } from "@rallly/ui";+import { Skeleton } from "@rallly/ui/skeleton";+import { ArrowLeftIcon } from "lucide-react";+import Link from "next/link";+import { notFound } from "next/navigation";+import { Suspense } from "react";+import {+ PageContainer,+ PageContent,+ PageHeader,+ PageHeaderContent,+ PageTitle,+} from "@/components/page-layout";+import { loadPoll } from "@/features/poll/loaders";+import { Trans } from "@/i18n/client";+import { isFeatureEnabled } from "@/lib/feature-flags/server";+import { PollDetailSheet } from "./poll-detail-sheet";+import { PollShellTabs } from "./poll-shell-tabs";++async function PollPageTitle({+ params,+}: {+ params: Promise<{ pollId: string }>;+}) {+ const { pollId } = await params;+ const poll = await loadPoll(pollId);+ return poll.title;+}++export default function Layout({+ children,+ params,+}: {+ children: React.ReactNode;+ params: Promise<{ pollId: string }>;+}) {+ if (!isFeatureEnabled("pollAdmin")) {+ notFound();+ }++ return (+ <PageContainer>+ <PageHeader>+ <PageHeaderContent className="flex items-center gap-2">+ <Link+ href="/polls"+ className={buttonVariants({ variant: "ghost", size: "icon" })}+ >+ <ArrowLeftIcon className="size-4" />+ <span className="sr-only">+ <Trans i18nKey="back" defaults="Back" />+ </span>+ </Link>+ <PageTitle>+ <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>+ <PollDetailSheet />+ </PageContainer>+ );+}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.tsxnew file mode 100644index 000000000..ed22960a0--- /dev/null+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/page.tsx@@ -0,0 +1,11 @@+import { loadPoll } from "@/features/poll/loaders";++export default async function Page({+ params,+}: {+ params: Promise<{ pollId: string }>;+}) {+ const { pollId } = await params;+ await loadPoll(pollId);+ return null;+}diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/poll-detail-sheet.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/poll-detail-sheet.tsxnew file mode 100644index 000000000..d4f34995b--- /dev/null+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/poll-detail-sheet.tsx@@ -0,0 +1,8 @@+"use client";++// Shell-scoped mount point for the detail sheet driven by ?responseId= /+// ?optionId=. It mounts once from the poll layout so every poll page shares+// one sheet; content and history behavior land with the detail sheets issue.+export function PollDetailSheet() {+ return null;+}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.tsxnew file mode 100644index 000000000..1290b7c95--- /dev/null+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/poll-shell-tabs.tsx@@ -0,0 +1,53 @@+"use client";++import { cn } from "@rallly/ui";+import Link from "next/link";+import { usePathname } from "next/navigation";+import { Trans } from "@/i18n/client";++export function PollShellTabs() {+ const pathname = usePathname();+ const basePath = pathname.replace(/\/(responses|dates|activity)$/, "");++ const tabs = [+ {+ href: basePath,+ label: <Trans i18nKey="overview" defaults="Overview" />,+ },+ {+ href: `${basePath}/responses`,+ label: <Trans i18nKey="responses" defaults="Responses" />,+ },+ {+ href: `${basePath}/dates`,+ label: <Trans i18nKey="dates" defaults="Dates" />,+ },+ {+ href: `${basePath}/activity`,+ label: <Trans i18nKey="activity" defaults="Activity" />,+ },+ ];++ return (+ <nav className="flex space-x-4 border-b border-b-border">+ {tabs.map((tab) => {+ const isActive = pathname === tab.href;+ return (+ <Link+ 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",+ )}+ >+ {tab.label}+ </Link>+ );+ })}+ </nav>+ );+}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.tsxnew file mode 100644index 000000000..ed22960a0--- /dev/null+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/polls/[pollId]/responses/page.tsx@@ -0,0 +1,11 @@+import { loadPoll } from "@/features/poll/loaders";++export default async function Page({+ params,+}: {+ params: Promise<{ pollId: string }>;+}) {+ const { pollId } = await params;+ await loadPoll(pollId);+ return null;+}diff --git a/apps/web/src/features/poll/components/polls-infinite-list.tsx b/apps/web/src/features/poll/components/polls-infinite-list.tsxindex 2c1796501..46835032f 100644--- a/apps/web/src/features/poll/components/polls-infinite-list.tsx+++ b/apps/web/src/features/poll/components/polls-infinite-list.tsx@@ -39,6 +39,7 @@ import { StackedList, StackedListItem } from "@/components/stacked-list";import { PollStatusIcon } from "@/features/poll/components/poll-status-icon";import type { PollClosedReason, PollStatus } from "@/features/poll/schema";import { Trans, useTranslation } from "@/i18n/client";+import { useFeatureFlag } from "@/lib/feature-flags/client";import { trpc } from "@/trpc/client";interface PollsInfiniteListProps {@@ -65,6 +66,7 @@ function PollListItem({}) {const { t } = useTranslation();const router = useRouter();+ const isPollAdminEnabled = useFeatureFlag("pollAdmin");const deletePollDialog = useDialog();// Refresh server components so server-fetched data that depends on poll// status (e.g. the status tab counts) stays in sync with the list.@@ -79,7 +81,9 @@ function PollListItem({<PollStatusIcon status={status} showTooltip={false} /><HoverPrefetchLinkclassName="min-w-0 text-sm hover:underline focus:ring-ring focus-visible:ring-2"- href={absoluteUrl(`/poll/${id}`)}+ href={+ isPollAdminEnabled ? `/polls/${id}` : absoluteUrl(`/poll/${id}`)+ }><span className="absolute inset-0" /><span className="block truncate">{title}</span>diff --git a/apps/web/src/features/poll/data.ts b/apps/web/src/features/poll/data.tsindex 8cecc3041..c277aad65 100644--- a/apps/web/src/features/poll/data.ts+++ b/apps/web/src/features/poll/data.ts@@ -5,6 +5,27 @@ import { prisma } from "@rallly/database";import { effectiveSpaceMemberWhere } from "@/features/space/member/utils";import type { AuthorizedSpaceId } from "@/features/space/types";+export async function getPoll({+ pollId,+ spaceId,+}: {+ pollId: string;+ spaceId: AuthorizedSpaceId;+}) {+ return prisma.poll.findFirst({+ where: {+ id: pollId,+ spaceId,+ deleted: false,+ },+ select: {+ id: true,+ title: true,+ status: true,+ },+ });+}+export async function getPollResults({pollId,spaceId,diff --git a/apps/web/src/features/poll/loaders.ts b/apps/web/src/features/poll/loaders.tsindex 0d7aea2ae..987c6627c 100644--- a/apps/web/src/features/poll/loaders.ts+++ b/apps/web/src/features/poll/loaders.ts@@ -1,10 +1,22 @@import "server-only";+import { notFound } from "next/navigation";import { cache } from "react";-import { getPollStatusCounts } from "@/features/poll/data";+import { getPoll, getPollStatusCounts } from "@/features/poll/data";import { getActiveSpace } from "@/features/space/loaders";export const loadPollStatusCounts = cache(async () => {const space = await getActiveSpace();return getPollStatusCounts({ spaceId: space.id });});++export const loadPoll = cache(async (pollId: string) => {+ const space = await getActiveSpace();+ const poll = await getPoll({ pollId, spaceId: space.id });++ if (!poll) {+ notFound();+ }++ return poll;+});diff --git a/apps/web/src/lib/feature-flags/config.ts b/apps/web/src/lib/feature-flags/config.tsindex eba099908..7f50abbd5 100644--- a/apps/web/src/lib/feature-flags/config.ts+++ b/apps/web/src/lib/feature-flags/config.ts@@ -22,4 +22,7 @@ export const featureFlagConfig: FeatureFlagConfig = {registration: isEmailLoginEnabled && isRegistrationEnabled,calendars: isCalendarsEnabled,eventTypes: isEventTypesEnabled,+ // The new poll admin at /polls/[pollId] is dev-only until it reaches+ // feature parity with the legacy admin and cuts over.+ pollAdmin: env.NODE_ENV === "development",};diff --git a/apps/web/src/lib/feature-flags/types.ts b/apps/web/src/lib/feature-flags/types.tsindex 9f4defa2c..5fc985478 100644--- a/apps/web/src/lib/feature-flags/types.ts+++ b/apps/web/src/lib/feature-flags/types.ts@@ -7,6 +7,7 @@ export interface FeatureFlagConfig {registration: boolean;calendars: boolean;eventTypes: boolean;+ pollAdmin: boolean;}export type Feature = keyof FeatureFlagConfig;