Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
32c519b
feat(core): add quick poll limits
musa-kal Nov 22, 2026
ed86fab
feat(db): add quick polls tables, RPCs and purge job
musa-kal Nov 22, 2026
f6f97fd
feat(api): add quick poll queries and mutations
musa-kal Nov 22, 2026
5e8cdd4
feat(i18n): word the quick poll error codes
musa-kal Nov 22, 2026
a573d02
docs: document quick polls
musa-kal Nov 22, 2026
f66beb4
refactor(web): share link memory, public page frame, window fields an…
musa-kal Nov 22, 2026
23f3ac1
refactor(web): share the sent card, window facts and token memory wit…
musa-kal Nov 23, 2026
32cb20d
feat(i18n): word the quick poll screens and the landing entry
musa-kal Nov 23, 2026
4caf079
feat(web): quick poll create page and poll page
musa-kal Nov 23, 2026
e3a660e
feat(web): quick poll entry on the landing page
musa-kal Nov 23, 2026
92d157f
test(e2e): quick poll journey, full poll and accessibility
musa-kal Nov 23, 2026
8921277
docs: quick poll screens, journey and shared public page pieces
musa-kal Nov 23, 2026
120609c
test(e2e): count the friend's edit from the slots already painted
musa-kal Nov 23, 2026
2b49627
review: fix quick poll stale refetch, unsaved flag, slot parsing
musa-kal Nov 23, 2026
a36b5f4
fix(quick-polls): the browser makes its answer token so a retried fir…
musa-kal Nov 23, 2026
df9a7a9
fix(web): keep the quick poll window while its first day is cleared o…
musa-kal Nov 23, 2026
ed84a10
refactor(core): drop isQuickPollTtl, which nothing calls
musa-kal Nov 23, 2026
5624686
review: keep made poll token in page state so refetches carry it
musa-kal Nov 23, 2026
a4a72d0
review: keep poll on screen and read fresh after a first save
musa-kal Nov 23, 2026
9e2a166
document: docs: list quick polls in the README features
musa-kal Nov 23, 2026
714390d
document: docs: name quick poll routes as signed out in web AGENTS
musa-kal Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ passes; if a journey changed, its e2e spec passes. Report the commands you ran a
- New public function: `security definer`, `set search_path = ''`, schema-qualify every name, then
`revoke execute on function public.f(...) from public, anon;` and
`grant execute on function public.f(...) to authenticated, service_role;` (Supabase's default
privileges let `anon` execute every new public function). Only invite previews, `email_unsubscribe`
and guest link RPCs are anon-callable; adding one means updating `01_schema.test.sql`, ADR 4 and `docs/security.md`.
privileges let `anon` execute every new public function). Only invite previews, `email_unsubscribe`,
guest link and quick poll RPCs are anon-callable; adding one means updating `01_schema.test.sql`, ADR 4 and `docs/security.md`.
- Every new table in `public`: RLS on, policies with `(select auth.uid())` and
`group_id = any (array(select private.my_group_ids()))`, revoke-all then column grants, an index per
foreign key, pgTAP for who can and who cannot.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Live at https://potluck.fermulate.com (user guide at https://docs.potluck.fermul
- Ranked best times, with who can and cannot make each one
- Lock in a time, RSVP, and get reminders the day before
- Personal calendar feed (`.ics`) for every plan you are part of
- Quick polls: share an availability link that up to 15 people answer without an account

**Everywhere**

Expand Down
4 changes: 2 additions & 2 deletions apps/web/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Per-feature notes (payers and refunds, repeating expenses, language, two-step si
a validator returns every key, `undefined` when dropped, or the raw value shows through),
no feature imports beyond the screen. A `loader` may call `prefetch.<screen>()` from
`src/lib/prefetch.ts` and must not await it.
- `/a/$code` (guest links) is signed out. `/` is prerendered (`prerender-landing.ts`): nothing on the
landing page may touch `window` during render.
- `/a/$code` (guest links), `/poll` and `/p/$code` (quick polls) are signed out. `/` is prerendered
(`prerender-landing.ts`): nothing on the landing page may touch `window` during render.
- Server data goes through `@potluck/api` functions and `queryOptions`; never `supabase.from()` in a component.
- Realtime: subscribe with `useRealtime` / `useBatchedInvalidate` (`src/lib/realtime.ts`) and invalidate
query keys; never patch the cache from the payload.
Expand Down
26 changes: 25 additions & 1 deletion apps/web/e2e/a11y.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import AxeBuilder from '@axe-core/playwright'
import { addPlaceholderMember, createPlanEvent, fetchMyFriendLink } from '@potluck/api'
import { t } from '@potluck/i18n'
import type { Page, TestInfo } from '@playwright/test'
import { addEqualExpense, groupWith, guestLinkFor, pollIn } from './support/api'
import {
addEqualExpense,
answerQuickPoll,
groupWith,
guestLinkFor,
pollIn,
quickPoll,
} from './support/api'
import { expect, test, unique, type TestUser } from './support/fixtures'

/** Serious and critical WCAG 2.1 A/AA violations fail the test; the rest are reported. */
Expand Down Expand Up @@ -233,6 +240,23 @@ test.describe('accessibility', () => {
await audit(page, testInfo)
})

test('quick poll pages, signed out', async ({ openAs }, testInfo) => {
const page = await openAs(null)
await page.goto('/poll')
await expect(
page.getByRole('heading', { level: 1, name: t('quickPolls.create.title') }),
).toBeVisible()
await audit(page, testInfo)

const title = unique('Picnic')
const poll = await quickPoll({ title })
await answerQuickPoll(poll.code, unique('Cy'))
await page.goto(`/p/${poll.code}`)
await expect(page.getByRole('heading', { level: 1, name: title })).toBeVisible()
await expect(page.getByRole('grid').first()).toBeVisible()
await audit(page, testInfo)
})

test('me', async ({ newUser, openAs }, testInfo) => {
const page = await openAs(await newUser())
await page.goto('/me')
Expand Down
129 changes: 129 additions & 0 deletions apps/web/e2e/quick-polls.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { t } from '@potluck/i18n'
import type { Page } from '@playwright/test'
import { answerQuickPoll, clearQuickPollCreates, quickPoll } from './support/api'
import { expect, test, unique } from './support/fixtures'

/**
* Paints `count` cells down from the first free one with the keyboard; `total` is how many the
* answer then has.
*/
async function paint(page: Page, title: string, count: number, total = count) {
const painter = page.getByRole('grid', { name: t('quickPolls.page.gridLabel', { title }) })
await expect(painter).toBeVisible()
await painter
.getByRole('gridcell', { name: /not set/ })
.first()
.focus()
await page.keyboard.press('Space')
for (let i = 1; i < count; i++) await page.keyboard.press('Shift+ArrowDown')
await expect(page.getByText(t('availability.mySlots', { count: total }))).toBeVisible()
}

async function answer(page: Page, title: string, name: string, count: number) {
await page.getByLabel(t('quickPolls.page.nameLabel')).fill(name)
await paint(page, title, count)
await page.getByRole('button', { name: t('quickPolls.page.submit') }).click()
await expect(page.getByText(t('quickPolls.page.sentTitle', { name }))).toBeVisible()
}

test('make a quick poll from the landing page, two people answer without accounts', async ({
openAs,
}) => {
clearQuickPollCreates()
const title = unique('Board games')
const ava = unique('Ava')
const ben = unique('Ben')

// Someone signed out finds the poll in the hero and makes one from the defaults.
const creator = await openAs(null)
// WebKit has no clipboard permissions to grant, so keep what the page copies instead.
await creator.addInitScript(() => {
const keep = (text: string) => {
;(window as unknown as { copied?: string }).copied = text
return Promise.resolve()
}
Object.defineProperty(navigator, 'clipboard', {
value: { writeText: keep },
configurable: true,
})
})
await creator.goto('/')
await creator
.getByRole('link', { name: new RegExp(`^${t('app.landing.quickPoll.title')}`) })
.click()
await expect(
creator.getByRole('heading', { level: 1, name: t('quickPolls.create.title') }),
).toBeVisible()
await creator.getByLabel(t('quickPolls.create.titleLabel')).fill(title)
await creator.getByRole('button', { name: t('quickPolls.create.submit') }).click()

// The new poll puts sharing first.
await expect(creator.getByRole('heading', { level: 1, name: title })).toBeVisible()
await expect(creator.getByText(t('quickPolls.page.readyTitle'))).toBeVisible()
await creator.getByRole('button', { name: t('quickPolls.page.copy') }).click()
await expect(creator.getByText(t('quickPolls.page.copied')).first()).toBeVisible()
const url = await creator.evaluate(() => (window as unknown as { copied?: string }).copied ?? '')
expect(url).toMatch(/\/p\/[\w-]+$/)
expect(new URL(url).pathname).toBe(new URL(creator.url()).pathname)

// The creator answers like anyone else.
await answer(creator, title, ava, 3)
await expect(creator.getByText(t('quickPolls.page.readyTitle'))).toHaveCount(0)

// A second person, also without an account, opens the link and adds their times.
const friend = await openAs(null)
await friend.goto(new URL(url).pathname)
await expect(friend.getByRole('heading', { level: 1, name: title })).toBeVisible()
await expect(friend.getByText(t('quickPolls.page.answered', { count: 1, max: 10 }))).toBeVisible()
await answer(friend, title, ben, 2)
const heatmap = friend.getByRole('grid', { name: t('quickPolls.page.heatGridLabel', { title }) })
await expect(heatmap.getByRole('gridcell', { name: /: 2 free, 0 maybe/ })).toHaveCount(2)

// The creator's page picks the new answer up without a reload.
await expect(creator.getByText(t('quickPolls.page.answered', { count: 2, max: 10 }))).toBeVisible(
{ timeout: 25_000 },
)
await expect(
creator
.getByRole('region', { name: t('bestTime.title') })
.getByText(t('bestTime.everyoneCanMake'))
.first(),
).toBeVisible()

// The friend comes back on the same browser and changes their answer.
await friend.reload()
await friend.getByRole('button', { name: t('quickPolls.page.edit') }).click()
await paint(friend, title, 1, 3)
await friend.getByRole('button', { name: t('quickPolls.page.update') }).click()
await expect(friend.getByText(t('quickPolls.page.sentTitle', { name: ben }))).toBeVisible()

// The creator closes the poll; the friend sees it read only.
await creator.getByRole('button', { name: t('quickPolls.page.close') }).click()
await creator
.getByRole('dialog', { name: t('quickPolls.page.closeTitle') })
.getByRole('button', { name: t('quickPolls.page.close') })
.click()
await expect(
creator.getByRole('heading', { name: t('quickPolls.page.closedTitle') }),
).toBeVisible()
await friend.reload()
await expect(
friend.getByRole('heading', { name: t('quickPolls.page.closedTitle') }),
).toBeVisible()
await expect(friend.getByRole('button', { name: t('quickPolls.page.edit') })).toHaveCount(0)
})

test('a full poll turns a new person away but shows the results', async ({ openAs }) => {
const title = unique('Picnic')
const poll = await quickPoll({ title, maxPeople: 2 })
await answerQuickPoll(poll.code, unique('Cy'))
await answerQuickPoll(poll.code, unique('Dee'))

const late = await openAs(null)
await late.goto(`/p/${poll.code}`)
await expect(late.getByRole('heading', { name: t('quickPolls.page.fullTitle') })).toBeVisible()
await expect(late.getByLabel(t('quickPolls.page.nameLabel'))).toHaveCount(0)
await expect(
late.getByRole('grid', { name: t('quickPolls.page.heatGridLabel', { title }) }),
).toBeVisible()
})
77 changes: 76 additions & 1 deletion apps/web/e2e/support/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ import {
createGuestLink,
createInvite,
createPlanEvent,
createQuickPoll,
setQuickPollAvailability,
type CreateQuickPollInput,
type ExpensePayload,
} from '@potluck/api'
import { createClient } from '@supabase/supabase-js'
import { stackEnv } from './env'
import { execFileSync } from 'node:child_process'
import { randomUUID } from 'node:crypto'
import { readFileSync } from 'node:fs'
import { repoRoot, stackEnv } from './env'
import { unique, type TestUser } from './fixtures'

/** `days` from today as YYYY-MM-DD (UTC, like every e2e user). */
Expand Down Expand Up @@ -100,3 +106,72 @@ export async function addEqualExpense(
...extra,
})
}

/**
* Empties the quick poll create log on the local database. Creating is limited to 5 polls an
* hour per client address and every local call shares one address, so each test that makes a
* poll starts here; the limit itself stays as it is. Runs psql inside the local stack's database
* container (the stack's `project_id` names it), never against a hosted project.
*/
export function clearQuickPollCreates() {
const config = readFileSync(`${repoRoot}supabase/config.toml`, 'utf8')
const projectId = /^project_id\s*=\s*"([^"]+)"/m.exec(config)?.[1] ?? 'potluck'
execFileSync(
'docker',
[
'exec',
`supabase_db_${projectId}`,
'psql',
'-U',
'postgres',
'-tAc',
'delete from private.quick_poll_creates',
],
{ stdio: 'ignore' },
)
}

/** A client with no account, like a browser that never signed in. */
function anonymousClient() {
const env = stackEnv()
return createClient(env.url, env.publishableKey, {
auth: { persistSession: false, autoRefreshToken: false },
})
}

/**
* A quick poll made without an account: tomorrow and the day after, 10:00 to 12:00 UTC, one hour
* long. Returns its code and the creator token.
*/
export async function quickPoll(input: Partial<CreateQuickPollInput> = {}) {
clearQuickPollCreates()
return createQuickPoll(anonymousClient(), {
title: unique('Picnic'),
timeZone: 'UTC',
windowStart: dayFromToday(1),
windowEnd: dayFromToday(2),
dayStartMinute: 600,
dayEndMinute: 720,
durationMinutes: 60,
slotMinutes: 30,
ttl: '7d',
namesRequired: true,
maxPeople: 10,
...input,
})
}

/** Someone without an account answers `code` with tomorrow 10:00 to 11:00; returns their token. */
export async function answerQuickPoll(code: string, name: string, token = randomUUID()) {
const day = dayFromToday(1)
const saved = await setQuickPollAvailability(anonymousClient(), {
code,
name,
token,
slots: [
{ slot_start: `${day}T10:00:00.000Z`, level: 'yes' },
{ slot_start: `${day}T10:30:00.000Z`, level: 'yes' },
],
})
return saved.token
}
3 changes: 3 additions & 0 deletions apps/web/public/_headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Quick polls are reached by a private link: keep them out of search results.
/p/*
X-Robots-Tag: noindex
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface AvailabilityHeatmapProps {
viewerId?: string
label: string
avatarUrl?: (path: string | null) => string | null
/** How the inspector names someone; first names with a guest tag by default. */
nameOf?: (person: PlanMember | undefined) => string
}

interface SlotInfo {
Expand Down Expand Up @@ -55,6 +57,7 @@ export function AvailabilityHeatmap({
viewerId,
label,
avatarUrl,
nameOf = personName,
}: AvailabilityHeatmapProps) {
const reduced = usePrefersReducedMotion()
const gridRef = useRef<HTMLDivElement>(null)
Expand Down Expand Up @@ -121,7 +124,7 @@ export function AvailabilityHeatmap({
}

const shown = active ? info.get(active) : undefined
const names = (ids: string[]) => ids.map((id) => personName(byId.get(id)))
const names = (ids: string[]) => ids.map((id) => nameOf(byId.get(id)))

return (
<div className="flex flex-col gap-3">
Expand Down
46 changes: 46 additions & 0 deletions apps/web/src/features/availability/sent-card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Button, Card, Stamp, StampAnimation } from '@potluck/ui'

/**
* Someone without an account just sent their times: an olive stamp, a thank you and a way back
* into editing. `stamp` plays the stamp's landing, only right after sending.
*/
export function SentCard({
stamp,
stampLabel,
title,
body,
actionLabel,
onAction,
}: {
stamp: boolean
stampLabel: string
title: string
body: string
actionLabel: string
onAction: () => void
}) {
return (
<Card tone="sunken" padding="roomy" className="flex flex-col gap-4 sm:flex-row sm:items-center">
<div className="shrink-0 self-start sm:self-center">
{stamp ? (
<StampAnimation show rotate={-8}>
<Stamp tone="olive">{stampLabel}</Stamp>
</StampAnimation>
) : (
<span className="inline-flex -rotate-[8deg]">
<Stamp tone="olive">{stampLabel}</Stamp>
</span>
)}
</div>
<div className="flex min-w-0 flex-1 flex-col gap-1">
<p role="status" className="flourish text-2xl leading-tight">
{title}
</p>
<p className="text-sm text-mute">{body}</p>
</div>
<Button variant="secondary" className="self-start sm:self-center" onClick={onAction}>
{actionLabel}
</Button>
</Card>
)
}
Loading
Loading