Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
🐛 Show the open poll limit on a /new the client router had cached (#3491)
Luke Vella28fd55b7dc84
diff --git a/apps/web/src/features/poll/components/create-poll.tsx b/apps/web/src/features/poll/components/create-poll.tsxindex bb46b3829..9dddd9b3c 100644--- a/apps/web/src/features/poll/components/create-poll.tsx+++ b/apps/web/src/features/poll/components/create-poll.tsx@@ -26,7 +26,10 @@ import { PollSettingsForm } from "@/features/poll/components/forms/poll-settingsimport type { NewEventData } from "@/features/poll/components/forms/types";import { SelectedOptionsCount } from "@/features/poll/components/selected-options-count";import { SHARE_POLL_FLASH_KEY } from "@/features/poll/constants";-import { showOpenPollLimit } from "@/features/poll/limit/client";+import {+ hideOpenPollLimit,+ showOpenPollLimit,+} from "@/features/poll/limit/client";import type { OpenPollUsage } from "@/features/poll/limit/types";import { isAtOpenPollLimit } from "@/features/poll/limit/utils";import { useUser } from "@/features/user/client";@@ -169,11 +172,27 @@ export const CreatePoll = ({// The form persists, so it survives closing a poll to make room. The count// is the server's at page load, so the poll created here can't trip it.React.useEffect(() => {- if (openPollUsage && isAtOpenPollLimit(openPollUsage)) {+ if (!openPollUsage) {+ return;+ }+ if (isAtOpenPollLimit(openPollUsage)) {showOpenPollLimit("create", openPollUsage);+ } else {+ hideOpenPollLimit("create");}}, [openPollUsage]);+ // The client router reuses a page it rendered in the last minute+ // (staleTimes.dynamic), so a /new loaded before the organizer opened or+ // closed polls would show the old count. Render it fresh once on arrival.+ const hasRefreshedUsage = React.useRef(false);+ React.useEffect(() => {+ if (openPollUsage && !hasRefreshedUsage.current) {+ hasRefreshedUsage.current = true;+ router.refresh();+ }+ }, [openPollUsage, router]);+return (<Form {...form}><header className="sticky top-0 z-20 bg-gray-100/90 p-3 backdrop-blur-md xl:bg-transparent xl:backdrop-blur-none dark:bg-gray-900/90 dark:xl:bg-transparent">diff --git a/apps/web/src/features/poll/limit/client.tsx b/apps/web/src/features/poll/limit/client.tsxindex 522b381d5..9f06dc65e 100644--- a/apps/web/src/features/poll/limit/client.tsx+++ b/apps/web/src/features/poll/limit/client.tsx@@ -38,6 +38,14 @@ export const showOpenPollLimit = (usage: OpenPollUsage,) => useOpenPollLimitStore.getState().show(source, usage);+/** Closes the dialog if it was opened for this reason. */+export const hideOpenPollLimit = (source: OpenPollLimitSource) => {+ const { isOpen, content, hide } = useOpenPollLimitStore.getState();+ if (isOpen && content?.source === source) {+ hide();+ }+};+/** The refusal a create, reopen or duplicate returned, or null. */export function getOpenPollLimitRefusal<E extends { code: string }>(result: {ok: boolean;diff --git a/apps/web/tests/open-poll-limit.spec.ts b/apps/web/tests/open-poll-limit.spec.tsindex 1a8387519..0bb8ea931 100644--- a/apps/web/tests/open-poll-limit.spec.ts+++ b/apps/web/tests/open-poll-limit.spec.ts@@ -183,6 +183,30 @@ test.describe("free organizer", () => {).toBeVisible();});+ test("is shown the limit on a /new the router had cached below it", async () => {+ // Start one under the limit, so /new renders without the dialog and the+ // client router keeps that render.+ await prisma.poll.update({+ where: { id: pollIds[0] },+ data: { status: "closed", closedReason: "manual" },+ });+ const newPollPage = new NewPollPage(page);+ await newPollPage.goto();+ await expect(+ page.getByRole("dialog", { name: "Open poll limit reached" }),+ ).toHaveCount(0);++ const pollPage = await newPollPage.create({ name: "Third poll" });+ await pollPage.closeShareDialog();++ // Back to /new without a full page load: the cached render says 2 of 3.+ await page.goBack();+ await expect(page).toHaveURL(/\/new/);+ await expect(+ page.getByRole("dialog", { name: "Open poll limit reached" }),+ ).toBeVisible();+ });+test("can leave the limit for their polls", async () => {await page.goto("/new");await page