From c998576c95cfa3b0e083d892d8b997206e1542fe Mon Sep 17 00:00:00 2001 From: Musa Kaleem <131704022+musa-kal@users.noreply.github.com> Date: Sat, 14 Nov 2026 19:45:42 -0500 Subject: [PATCH 1/9] show the session-ended note after the 30 s check too When the periodic check found the session gone, auth-js had already dropped the stored session inside getUser, so endEndedSession saw nothing to sign out and never left the note. confirmSession now leaves it as soon as the check says the session is missing (session_not_found, user_not_found, session_ended), before any sign out, and the sign-in page listens for a note that lands after it opened. Co-authored-by: Ferrin <177692050+Ferrin-Y@users.noreply.github.com> Co-authored-by: noorelmosrati <182049385+noorelmosrati@users.noreply.github.com> --- apps/web/e2e/account.spec.ts | 29 ++++++++++++++ .../src/features/auth/sign-in-page.test.tsx | 18 ++++++++- apps/web/src/features/auth/sign-in-page.tsx | 22 ++++++++-- .../features/shell/use-session-check.test.tsx | 31 +++++++++++++- apps/web/src/lib/auth.ts | 40 +++++++++++++++---- 5 files changed, 126 insertions(+), 14 deletions(-) diff --git a/apps/web/e2e/account.spec.ts b/apps/web/e2e/account.spec.ts index d74db6a..c34073c 100644 --- a/apps/web/e2e/account.spec.ts +++ b/apps/web/e2e/account.spec.ts @@ -122,6 +122,35 @@ test('sign out everywhere ends every session', async ({ newUser, openAs }) => { await expect(phone.getByText(t('auth.signIn.sessionEnded'))).toBeVisible() }) +test('a device left open leaves by itself after sign out everywhere, saying why', async ({ + newUser, + openAs, +}) => { + // The other device notices on its next 30 second check, with nobody touching it. + test.setTimeout(120_000) + const user = await newUser() + const phone = await openAs(null) + await signIn(phone, user.email, user.password) + await expect(phone).toHaveURL(/\/home$/) + + const laptop = await openAs(null) + await signIn(laptop, user.email, user.password) + await expect(laptop).toHaveURL(/\/home$/) + await laptop.goto('/me') + await security(laptop) + .getByRole('button', { name: t('security.sessions.signOutAll') }) + .click() + await laptop + .getByRole('dialog', { name: t('security.sessions.confirmTitle') }) + .getByRole('button', { name: t('security.sessions.signOutAll') }) + .click() + await expect(laptop).toHaveURL(/\/sign-in/) + + // No reload, no click: the phone gets to sign in and says why. + await expect(phone).toHaveURL(/\/sign-in/, { timeout: 60_000 }) + await expect(phone.getByText(t('auth.signIn.sessionEnded'))).toBeVisible() +}) + test('two-step sign in: set up, asked at sign in, wrong code refused, off with a code', async ({ newUser, openAs, diff --git a/apps/web/src/features/auth/sign-in-page.test.tsx b/apps/web/src/features/auth/sign-in-page.test.tsx index 24b91a3..ed26f4d 100644 --- a/apps/web/src/features/auth/sign-in-page.test.tsx +++ b/apps/web/src/features/auth/sign-in-page.test.tsx @@ -1,8 +1,8 @@ import { t } from '@potluck/i18n' import { Toaster } from '@potluck/ui' -import { fireEvent, screen, waitFor } from '@testing-library/react' +import { act, fireEvent, screen, waitFor } from '@testing-library/react' import { beforeEach, describe, expect, it, vi } from 'vitest' -import { endEndedSession } from '@/lib/auth' +import { confirmSession, endEndedSession } from '@/lib/auth' import { renderWithProviders } from '@/test/render' import { authCallsTo, resetDb, respondAuth } from '@/test/supabase' import { SignInPage } from './sign-in-page' @@ -59,6 +59,20 @@ describe('SignInPage', () => { expect(screen.queryByText(t('auth.signIn.sessionEnded'))).not.toBeInTheDocument() }) + it('says why when the session check finds the session gone after the page opened', async () => { + renderPage() + expect(await screen.findByRole('button', { name: t('auth.signIn.submit') })).toBeVisible() + expect(screen.queryByText(t('auth.signIn.sessionEnded'))).not.toBeInTheDocument() + + respondAuth('getSession', { data: { session: { user: { id: 'u-1' }, access_token: 'x' } } }) + respondAuth('getUser', async () => { + respondAuth('getSession', { data: { session: null } }) + return { data: { user: null }, error: { name: 'AuthSessionMissingError', status: 400 } } + }) + await act(() => confirmSession()) + expect(await screen.findByText(t('auth.signIn.sessionEnded'))).toBeInTheDocument() + }) + it('never redirects off site after signing in', async () => { const { router } = renderPage({ redirect: 'https://evil.example' }) await fill('ava@example.test', 'hunter22') diff --git a/apps/web/src/features/auth/sign-in-page.tsx b/apps/web/src/features/auth/sign-in-page.tsx index 98ca6fe..c6beb47 100644 --- a/apps/web/src/features/auth/sign-in-page.tsx +++ b/apps/web/src/features/auth/sign-in-page.tsx @@ -2,7 +2,13 @@ import { Link, useNavigate } from '@tanstack/react-router' import { currentLocale, t } from '@potluck/i18n' import { Button, Field, Input, toast } from '@potluck/ui' import { useEffect, useState, type FormEvent } from 'react' -import { authCallbackUrl, clearSessionEnded, safeRedirect, sessionEndedHere } from '@/lib/auth' +import { + authCallbackUrl, + clearSessionEnded, + onSessionEnded, + safeRedirect, + sessionEndedHere, +} from '@/lib/auth' import { errorMessage } from '@/lib/errors' import { detectTimezone } from '@/lib/locale' import { supabase } from '@/lib/supabase' @@ -19,9 +25,17 @@ type Mode = 'password' | 'magic' | 'sent' export function SignInPage({ redirect, notice }: AuthPageProps) { const navigate = useNavigate() - // Signed out because the session ended on another device: say so once, here. - const [ended] = useState(sessionEndedHere) - useEffect(() => clearSessionEnded(), []) + // Signed out because the session ended on another device: say so once, here. The periodic + // check can land on this page a moment before it leaves the note, so listen for it too. + const [ended, setEnded] = useState(sessionEndedHere) + useEffect(() => { + const take = () => { + if (sessionEndedHere()) setEnded(true) + clearSessionEnded() + } + take() + return onSessionEnded(take) + }, []) const [mode, setMode] = useState('password') const [email, setEmail] = useState('') const [password, setPassword] = useState('') diff --git a/apps/web/src/features/shell/use-session-check.test.tsx b/apps/web/src/features/shell/use-session-check.test.tsx index e929c9a..2bb66f5 100644 --- a/apps/web/src/features/shell/use-session-check.test.tsx +++ b/apps/web/src/features/shell/use-session-check.test.tsx @@ -1,7 +1,7 @@ import { act, render, waitFor } from '@testing-library/react' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { clearSessionEnded, sessionEndedHere } from '@/lib/auth' -import { authCallsTo, resetDb, respondAuth } from '@/test/supabase' +import { authCallsTo, emitAuth, resetDb, respondAuth } from '@/test/supabase' import { SESSION_CHECK_INTERVAL_MS, useSessionCheck } from './use-session-check' vi.mock('@/lib/supabase', () => import('@/test/supabase')) @@ -114,6 +114,35 @@ describe('useSessionCheck', () => { expect(sessionEndedHere()).toBe(false) }) + it('leaves the note even when auth-js drops the session inside the check', async () => { + clearSessionEnded() + // What supabase-js does for `session_not_found`: forget the session and announce the + // sign out before `getUser` returns. + respondAuth('getUser', async () => { + respondAuth('getSession', { data: { session: null } }) + expect(sessionEndedHere()).toBe(false) + emitAuth('SIGNED_OUT') + return authError('AuthSessionMissingError', 400) + }) + render() + await waitFor(() => expect(sessionEndedHere()).toBe(true)) + // Nothing left to sign out: the session was already gone. + expect(authCallsTo('signOut')).toEqual([]) + clearSessionEnded() + }) + + it.each([['session_not_found'], ['user_not_found'], ['session_ended']])( + 'leaves the note when the check answers %s', + async (code) => { + clearSessionEnded() + respondAuth('getUser', authError('AuthApiError', 403, code)) + render() + await waitFor(() => expect(authCallsTo('signOut')).toEqual([[{ scope: 'local' }]])) + expect(sessionEndedHere()).toBe(true) + clearSessionEnded() + }, + ) + it('does not ask the server without a session', async () => { respondAuth('getSession', { data: { session: null } }) render() diff --git a/apps/web/src/lib/auth.ts b/apps/web/src/lib/auth.ts index 7b74a5e..7f5acd0 100644 --- a/apps/web/src/lib/auth.ts +++ b/apps/web/src/lib/auth.ts @@ -162,8 +162,13 @@ export async function endEndedSession() { const ENDED_KEY = 'potluck.session-ended' let endedHere = false +const endedListeners = new Set<() => void>() -/** Remembers, for the sign-in page, that the session ended elsewhere (survives its reload). */ +/** + * Remembers, for the sign-in page, that the session ended elsewhere (survives its reload). The + * page may already be open when this runs (auth-js signs out by itself when `getUser` finds the + * session gone, and that sends the app to sign in), so an open page is told as well. + */ function markSessionEnded() { endedHere = true try { @@ -171,6 +176,13 @@ function markSessionEnded() { } catch { // Storage blocked: the in-memory flag still covers the redirect to sign in. } + for (const listener of endedListeners) listener() +} + +/** Calls `listener` each time this device learns its session ended elsewhere. */ +export function onSessionEnded(listener: () => void): () => void { + endedListeners.add(listener) + return () => endedListeners.delete(listener) } /** @@ -196,10 +208,25 @@ export function clearSessionEnded() { } } +/** + * Whether a session check found the session gone: ended elsewhere (`session_not_found`, which + * auth-js turns into `AuthSessionMissingError`), the account deleted (`user_not_found`), or the + * database's own `session_ended`. + */ +function sessionIsGone(error: { name?: string; code?: string }): boolean { + return ( + error.name === 'AuthSessionMissingError' || + error.code === 'session_not_found' || + error.code === 'user_not_found' || + error.code === 'session_ended' + ) +} + /** * Asks Supabase Auth whether this device's session still exists (`getUser` goes to the server, - * unlike `getSession`). A session ended elsewhere answers `session_not_found` (auth-js turns it - * into `AuthSessionMissingError`), a deleted account `user_not_found`, and this device signs out. + * unlike `getSession`). When it is gone, this device signs out. For `session_not_found` auth-js + * has already dropped the stored session inside `getUser`, so the note for the sign-in page is + * left here, before any sign out, not in `endEndedSession` (which then finds no session). * Anything else, such as an expired token (`bad_jwt`) or network trouble, changes nothing. */ export async function confirmSession(): Promise { @@ -207,10 +234,9 @@ export async function confirmSession(): Promise { const { data } = await supabase.auth.getSession() if (!data.session) return const { error } = await supabase.auth.getUser() - if (!error) return - if (error.name === 'AuthSessionMissingError' || error.code === 'user_not_found') { - await endEndedSession() - } + if (!error || !sessionIsGone(error)) return + markSessionEnded() + await endEndedSession() } /** From 7dee0e9bebe64dbf5b1050c51df3bba34b51534a Mon Sep 17 00:00:00 2001 From: Musa Kaleem <131704022+musa-kal@users.noreply.github.com> Date: Sat, 14 Nov 2026 19:45:46 -0500 Subject: [PATCH 2/9] undo a revoked invite from inside the sheet The sheet makes the page behind it inert, so tapping the toast's Undo only closed the sheet, and keyboard users could not reach it. The revoked link now leaves its "Invite revoked" line with an Undo button in its place, focus on Undo, and the toast only shows once the panel goes away. Co-authored-by: Ferrin <177692050+Ferrin-Y@users.noreply.github.com> Co-authored-by: noorelmosrati <182049385+noorelmosrati@users.noreply.github.com> --- apps/web/e2e/groups-invites.spec.ts | 18 +++ .../features/invites/invite-links.test.tsx | 34 +++++- .../features/invites/invite-sheet.test.tsx | 64 ++++++---- .../web/src/features/invites/invite-sheet.tsx | 111 ++++++++++++++---- 4 files changed, 179 insertions(+), 48 deletions(-) diff --git a/apps/web/e2e/groups-invites.spec.ts b/apps/web/e2e/groups-invites.spec.ts index 1639c3b..1daaa70 100644 --- a/apps/web/e2e/groups-invites.spec.ts +++ b/apps/web/e2e/groups-invites.spec.ts @@ -54,4 +54,22 @@ test('create a group, share an invite, and a signed out friend joins', async ({ // The owner sees the new member. await page.reload() await expect(page.getByText(friend.name).first()).toBeVisible() + + // Revoking from the invite sheet by mistake: one tap on Undo, right there, brings it back. + await page.getByRole('button', { name: t('members.invite') }).click() + const inviteSheet = page.getByRole('dialog', { name: t('invites.title') }) + const sheetLink = inviteSheet.getByRole('region', { name: t('invites.latest') }) + await expect(sheetLink.getByText(`/join/${code}`)).toBeVisible() + await sheetLink.getByRole('button', { name: t('invites.revoke') }).click() + await expect(inviteSheet.getByText(t('invites.revoked'))).toBeVisible() + await expect(sheetLink).toBeHidden() + await inviteSheet.getByRole('button', { name: t('common.undo') }).click() + await expect(inviteSheet).toBeVisible() + await expect(sheetLink.getByText(`/join/${code}`)).toBeVisible() + await expect(inviteSheet.getByText(t('invites.revoked'))).toBeHidden() + + // And the link still lets people in. + const later = await openAs(null) + await later.goto(`/join/${code}`) + await expect(later.getByRole('link', { name: t('invites.join.signInToJoin') })).toBeVisible() }) diff --git a/apps/web/src/features/invites/invite-links.test.tsx b/apps/web/src/features/invites/invite-links.test.tsx index feb309a..0b6b9f0 100644 --- a/apps/web/src/features/invites/invite-links.test.tsx +++ b/apps/web/src/features/invites/invite-links.test.tsx @@ -144,17 +144,43 @@ describe('InvitePanel links', () => { renderPanel() await screen.findByRole('region', { name: t('invites.latest') }) fireEvent.click(screen.getByRole('button', { name: t('invites.revoke') })) - expect(await screen.findByText(t('invites.revoked'))).toBeInTheDocument() + // In the link's place: what happened, and one Undo that already has focus. + const note = await screen.findByRole('status') + expect(note).toHaveTextContent(t('invites.revoked')) expect(rowsOf('group_invites')[0]!.revoked_at).toEqual(expect.any(String)) - expect(await screen.findByText(t('invites.intro', { group: 'Hike crew' }))).toBeInTheDocument() expect(screen.queryByRole('region', { name: t('invites.latest') })).not.toBeInTheDocument() expect(screen.getByRole('button', { name: t('invites.create') })).toBeInTheDocument() + const undo = within(note).getByRole('button', { name: t('common.undo') }) + expect(undo).toHaveFocus() + expect(screen.getAllByRole('button', { name: t('common.undo') })).toHaveLength(1) - fireEvent.click(screen.getByRole('button', { name: t('common.undo') })) + fireEvent.click(undo) expect(await screen.findByRole('region', { name: t('invites.latest') })).toHaveTextContent( '/join/code-i-1-xyz', ) - expect(rowsOf('group_invites')[0]!.revoked_at).toBeNull() + expect(screen.queryByRole('status')).not.toBeInTheDocument() + await waitFor(() => expect(rowsOf('group_invites')[0]!.revoked_at).toBeNull()) + }) + + it('revokes an older link, and undo puts it back in the list', async () => { + renderPanel(group(), [invite('i-2', { created_at: '2026-11-03T00:00:00Z' }), invite('i-1')]) + await screen.findByRole('region', { name: t('invites.latest') }) + fireEvent.click( + within(olderLink('code-i-1-xyz')).getByRole('button', { + name: t('invites.revokeLink', { code: 'code-i-1-xyz' }), + }), + ) + const undo = await within(openLinks()).findByRole('button', { name: t('common.undo') }) + expect(undo).toHaveFocus() + expect(within(openLinks()).queryByText(/code-i-1-xyz/)).not.toBeInTheDocument() + // The newest link stays put. + expect(latest()).toHaveTextContent('/join/code-i-2-xyz') + + fireEvent.click(undo) + expect(await within(openLinks()).findByText(/code-i-1-xyz/)).toBeInTheDocument() + await waitFor(() => + expect(rowsOf('group_invites').find((r) => r.id === 'i-1')!.revoked_at).toBeNull(), + ) }) it('keeps the link and explains when revoking fails', async () => { diff --git a/apps/web/src/features/invites/invite-sheet.test.tsx b/apps/web/src/features/invites/invite-sheet.test.tsx index 70d990a..010a2ff 100644 --- a/apps/web/src/features/invites/invite-sheet.test.tsx +++ b/apps/web/src/features/invites/invite-sheet.test.tsx @@ -2,7 +2,7 @@ import type * as ApiModule from '@potluck/api' import type * as AuthModule from '@/lib/auth' import { t } from '@potluck/i18n' import { Toaster } from '@potluck/ui' -import { fireEvent, screen, waitFor, within } from '@testing-library/react' +import { act, fireEvent, render, screen, waitFor, within } from '@testing-library/react' import { encode } from 'uqr' import { beforeEach, describe, expect, it, vi } from 'vitest' import { inviteUrl } from '@/lib/app-url' @@ -54,6 +54,20 @@ vi.mock('@/lib/auth', async (importOriginal) => ({ vi.mock('./share', () => ({ shareInvite: vi.fn(async () => undefined), copyText: vi.fn() })) +const link = { + id: 'i-9', + code: 'zzzzzzzzzz99', + group_id: 'g-hike', + role: 'member' as const, + max_uses: null, + uses: 0, + expires_at: null, + email: null, + created_at: '2026-11-05T00:00:00Z', + created_by: VIEWER, + revoked_at: null, +} + describe('InvitePanel', () => { beforeEach(() => { vi.clearAllMocks() @@ -84,28 +98,9 @@ describe('InvitePanel', () => { expect(screen.getByRole('button', { name: 'New link' })).toBeInTheDocument() }) - it('keeps Revoke apart from Copy, and offers Undo after revoking', async () => { - api.open = [ - { - id: 'i-9', - code: 'zzzzzzzzzz99', - group_id: 'g-hike', - role: 'member', - max_uses: null, - uses: 0, - expires_at: null, - email: null, - created_at: '2026-11-05T00:00:00Z', - created_by: VIEWER, - revoked_at: null, - }, - ] - renderWithProviders( - <> - - - , - ) + it('keeps Revoke apart from Copy, and offers Undo in its place after revoking', async () => { + api.open = [link] + renderWithProviders() const latest = await screen.findByRole('region', { name: 'Your link' }) const copy = within(latest).getByRole('button', { name: 'Copy link' }) const revoke = within(latest).getByRole('button', { name: t('invites.revoke') }) @@ -113,6 +108,29 @@ describe('InvitePanel', () => { expect(copy.parentElement).not.toBe(revoke.parentElement) fireEvent.click(revoke) await waitFor(() => expect(api.revokeInvite).toHaveBeenCalledTimes(1)) + // Undo is in the panel itself (a sheet blocks the toast), with focus on it. + const note = await screen.findByRole('status') + expect(note).toHaveTextContent(t('invites.revoked')) + const undo = within(note).getByRole('button', { name: t('common.undo') }) + expect(undo).toHaveFocus() + fireEvent.click(undo) + await waitFor(() => expect(api.restoreInvite).toHaveBeenCalledTimes(1)) + expect(api.restoreInvite.mock.calls[0]).toEqual([expect.anything(), 'i-9']) + expect(screen.queryByRole('status')).not.toBeInTheDocument() + }) + + it('offers Undo in a toast once the panel is gone', async () => { + api.open = [link] + render() + const { router } = renderWithProviders() + const latest = await screen.findByRole('region', { name: 'Your link' }) + fireEvent.click(within(latest).getByRole('button', { name: t('invites.revoke') })) + await screen.findByRole('status') + // One Undo while the panel is open: no toast behind a sheet. + expect(screen.getAllByRole('button', { name: t('common.undo') })).toHaveLength(1) + + await act(() => router.navigate({ to: '/home' })) + await screen.findByText('elsewhere') fireEvent.click(await screen.findByRole('button', { name: t('common.undo') })) await waitFor(() => expect(api.restoreInvite).toHaveBeenCalledTimes(1)) expect(api.restoreInvite.mock.calls[0]).toEqual([expect.anything(), 'i-9']) diff --git a/apps/web/src/features/invites/invite-sheet.tsx b/apps/web/src/features/invites/invite-sheet.tsx index 05d0850..f91f490 100644 --- a/apps/web/src/features/invites/invite-sheet.tsx +++ b/apps/web/src/features/invites/invite-sheet.tsx @@ -20,8 +20,8 @@ import { toast, } from '@potluck/ui' import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' -import { Check, ChevronDown, Copy, Link2, QrCode, Share2, X } from 'lucide-react' -import { useState } from 'react' +import { Check, ChevronDown, Copy, Link2, QrCode, Share2, Undo2, X } from 'lucide-react' +import { useEffect, useRef, useState } from 'react' import { Help } from '@/features/help/help' import { inviteUrl } from '@/lib/app-url' import { errorMessage } from '@/lib/errors' @@ -160,6 +160,55 @@ export function InvitePanel({ onError: (error) => toast.error(errorMessage(error)), }) + // The last revoked link, offered back right where it was. A sheet blocks taps and focus + // outside it, so a toast's Undo would only close the sheet; the toast waits for the panel + // to go away instead. + const [undoable, setUndoable] = useState<{ invite: GroupInviteRow; wasLatest: boolean } | null>( + null, + ) + const undoableRef = useRef(undoable) + useEffect(() => { + undoableRef.current = undoable + }, [undoable]) + + const restore = async (invite: GroupInviteRow) => { + try { + await restoreInvite(supabase, invite.id) + } catch (error) { + toast.error(errorMessage(error)) + } + void queryClient.invalidateQueries({ queryKey: key }) + } + const restoreRef = useRef(restore) + useEffect(() => { + restoreRef.current = restore + }) + + useEffect( + () => () => { + const left = undoableRef.current + if (!left) return + toast(t('invites.revoked'), { + duration: 8000, + action: { label: t('common.undo'), onClick: () => void restoreRef.current(left.invite) }, + }) + }, + [], + ) + + const undo = () => { + if (!undoable) return + const { invite } = undoable + setUndoable(null) + // Back in its place at once (newest first, as the list is read); the refetch confirms it. + queryClient.setQueryData(key, (rows) => + [...(rows ?? []).filter((r) => r.id !== invite.id), invite].sort((a, b) => + b.created_at.localeCompare(a.created_at), + ), + ) + void restore(invite) + } + const revoke = useMutation({ mutationFn: (invite: GroupInviteRow) => revokeInvite(supabase, invite.id), onMutate: async (invite) => { @@ -168,27 +217,14 @@ export function InvitePanel({ queryClient.setQueryData(key, (rows) => rows?.filter((r) => r.id !== invite.id), ) - return { previous } + return { previous, wasLatest: previous?.[0]?.id === invite.id } }, onError: (error, _invite, context) => { if (context?.previous) queryClient.setQueryData(key, context.previous) toast.error(errorMessage(error)) }, - onSuccess: (_data, invite) => { - toast(t('invites.revoked'), { - duration: 8000, - action: { - label: t('common.undo'), - onClick: async () => { - try { - await restoreInvite(supabase, invite.id) - } catch (error) { - toast.error(errorMessage(error)) - } - void queryClient.invalidateQueries({ queryKey: key }) - }, - }, - }) + onSuccess: (_data, invite, context) => { + setUndoable({ invite, wasLatest: context.wasLatest }) }, }) @@ -218,6 +254,7 @@ export function InvitePanel({ return (
+ {undoable?.wasLatest && } {invites.isPending ? ( ) : latest ? ( @@ -227,7 +264,7 @@ export function InvitePanel({ groupName={group.name} onRevoke={() => revoke.mutate(latest)} /> - ) : intro ? ( + ) : intro && !undoable ? (

{t('invites.intro', { group: group.name })}

) : null} @@ -314,12 +351,17 @@ export function InvitePanel({
- {others.length > 0 && ( + {(others.length > 0 || (undoable && !undoable.wasLatest)) && (

{t('invites.active')}

    + {undoable && !undoable.wasLatest && ( +
  • + +
  • + )} {others.map((invite) => ( void }) { + const button = useRef(null) + useEffect(() => button.current?.focus(), []) + return ( +
    +

    {t('invites.revoked')}

    + +
    + ) +} + /** The newest open link, front and center: the thing people came here to copy. */ function LatestLink({ invite, @@ -397,7 +466,7 @@ function LatestLink({ {/* Revoking sits on its own, below a rule and away from Copy, so a slip never closes - the link; it also leaves an Undo in the toast. */} + the link; it also leaves an Undo in its place. */}
    - {(others.length > 0 || (undoable && !undoable.wasLatest)) && ( + {olderSlots.length > 0 && (

    {t('invites.active')}

      - {undoable && !undoable.wasLatest && ( -
    • - -
    • + {olderSlots.map(({ invite, revoked }) => + revoked ? ( +
    • + undo(invite)} /> +
    • + ) : ( + revoke.mutate(invite)} + /> + ), )} - {others.map((invite) => ( - revoke.mutate(invite)} - /> - ))}
    )} diff --git a/docs/development.md b/docs/development.md index 7a540cc..0e4e68c 100644 --- a/docs/development.md +++ b/docs/development.md @@ -301,7 +301,7 @@ Notes for changing particular screens in `apps/web`. The general rules are in `a - Categories: pick with `CategoryPicker` (`features/expenses/form/category-picker.tsx`, top level chips plus a row of subcategories) and label with `categoryLabel()`. A new expense's category follows core `suggestCategory` (group history from `categoryHistoryQueryOptions`) until someone taps one. Subcategories are stored as their own ids; totals and charts roll them up with core `parentCategory()`. - Groups ([ADR 20](adr/0020-group-types-restorable-deletes-and-shared-notes.md)): a deleted group is gone from every query for 30 days; "Recently deleted" (`features/groups/recently-deleted.tsx`) reads `my_deleted_groups`, and its old address shows the deleted page with Restore (`MissingGroup`). Covers render through `GroupCover` / `coverSrc()` (public URL, works signed out). The Notes tab (`notes-page.tsx`) saves with a base version and subscribes to `group_whiteboards`, refetching through `useRealtime`'s `onSubscribed` once the channel joins (an edit saved while it was joining sends no change event, and every channel asks Realtime to hold `SUBSCRIBED` until Postgres changes flow with `postgres_changes_options.wait`; the plan page's `useEventRealtime` does the same for paints and guest answers); keep that pattern for any other shared text. Long names with no spaces use `wrap-anywhere`, not `break-words`, so they cannot widen a grid column or the phone page. - Errors and offline: a screen that throws renders `RouteError` (`features/shell/route-error.tsx`, the router's `defaultErrorComponent` and the root's `errorComponent`) with Try again and Go home. `OfflineBanner` (root layout) shows while `useOnline()` (`src/lib/online.ts`, `navigator.onLine` plus its events) is false. A form in `MoneyPageShell` disables its save offline, shows `OfflineSaveNote` and calls `useWarnBeforeUnload` while its entry would be lost; do the same for any new save button there. A save that fails because Potluck could not be reached (`isNetworkError` in `src/lib/errors.ts`, classified once in the mutation's `onError`) gets no toast: the form stays as typed and read only (a `fieldset disabled` around its fields, also while the save is out) so a retry repeats exactly what was sent, `OfflineSaveNote` (`failed`) says so, the save button itself reads Try again (one action, never a second button beside it), and the group's money queries are invalidated so a save that did arrive shows up once back online. Saves are never retried by themselves. A new expense or payment carries one request id per form (`newRequestId` in `src/lib/request-id.ts`, kept in `useState`), sent with every try, so a retry after a lost reply returns the first save instead of a second (ADR 8, Request keys), and the success message describes the returned row, not the form; a new create form that can be retried does the same. A held payment form keeps showing the debt it was sent against (the same snapshot the settled screen uses), since the refetched debts may already count it. -- Undo inside a sheet: a sheet makes everything behind it inert, so a toast's Undo cannot be tapped or reached by keyboard while it is open. Put Undo in the sheet where the thing was (the invite panel's `RevokedNote` takes focus when its link goes) and raise the toast only once the sheet closes (`inSheet`; the members page's inline panel keeps the note alone). The note lasts as long as the toast would (8 s), and a reply that lands after the panel is gone raises the toast directly. +- Undo inside a sheet: a sheet makes everything behind it inert, so a toast's Undo cannot be tapped or reached by keyboard while it is open. Put Undo in the sheet where the thing was (the invite panel shows one `RevokedNote` per revoked link, in that link's slot, and each takes focus when its link goes) and raise the toasts, one per link still undoable, only once the sheet closes (`inSheet`; the members page's inline panel keeps the notes alone). Each note lasts as long as the toast would (8 s), and a reply that lands after the panel is gone raises the toast directly. - Blocks in forms: the expense form tells whoever placed a block, by name and before saving, when the person they blocked is in the split or among the payers (`blockedOnExpense`, from `my_blocks`, the same rule as `private.blocked_pair`); everyone else only hears the server's neutral `blocked_person`. Payment controls in a 1:1 tab follow `useBlockedInTab` (`features/friends/split-note.ts`): the blocked side sees Edit, Delete and Restore only on payments they recorded, and `paymentErrorMessage` words any remaining refusal for a payment. Who may edit a payment is `mayEditPayment` (`features/settle/payment-rules.ts`), used by the Edit button on the payment's page, the payment menu in the expenses list (hidden in an archived group) and `/payments/$paymentId/edit`, which sends anyone else back to the payment's page. Never show who blocked whom to the blocked side. - Sessions ended elsewhere: `endEndedSession` leaves a flag (`sessionEndedHere`, cleared by the sign-in page) so sign in says why once. `confirmSession` leaves it itself as soon as `getUser` answers that the session is gone, before any sign out, because auth-js has already dropped the stored session inside `getUser` by then (and fired `SIGNED_OUT`, which may open sign in first); the sign-in page also listens (`onSessionEnded`) for a flag left after it opened. `useSessionCheck` checks on open and on focus or visibility (those two throttled to one check per 30 seconds), and its timer starts again after every check, so no two checks while on screen are more than 30 seconds apart. - Split editor people are listed with `viewerFirst()` (you, then member order) in every split type, by item too, with the same avatar size; payloads keep member order. `CategoryPicker` rows are radio groups with one Tab stop and arrow keys.