fix(collections): a list invite can be accepted where its notification leads, on phone and desktop

The invite notification links to /collections/:id, a list the invitee
cannot read until they accept. The phone screen had no invite UI at all
and showed "Start your first collection", and on desktop the rail with the
invites is hidden below 1080px while the empty state had no way to open it.

useCollections now recognises a route id that is a pending invite, keeps
it out of the route sync and puts it first in the invites it hands out.
The phone screen shows the pending invites as cards above the lists, and
the desktop body shows them when the person has no lists of their own,
or the one invite the route points at. Both reuse the existing invite
strings. A route id that is neither a list nor an invite (declined,
withdrawn, deleted) now drops back to /collections once the lists are in,
instead of leaving the page on a list it cannot show.

Refs #2645
This commit is contained in:
Maurice
2026-10-12 10:44:57 +02:00
parent c94d275cfd
commit e3bf18f9a6
13 changed files with 277 additions and 22 deletions
@@ -0,0 +1,39 @@
import React from 'react';
import type { IncomingCollectionInvite } from '../../store/collectionStore';
import type { TranslationFn } from '../../types';
interface CollectionInviteCardProps {
invite: IncomingCollectionInvite;
onAccept: (id: number) => void;
onDecline: (id: number) => void;
t: TranslationFn;
}
/**
* One pending list invite with Accept / Decline. Lives in the lists rail, and in
* the page body where the rail is not on screen: no lists of one's own yet, or
* the invite notification's link to a list that is still an invite (#2645).
*/
export default function CollectionInviteCard({
invite,
onAccept,
onDecline,
t,
}: CollectionInviteCardProps): React.ReactElement {
return (
<div className="col-invite">
<div className="t">{invite.name}</div>
<div className="s">
{t('collections.invites.from')} {invite.from.username}
</div>
<div className="col-invite-actions">
<button type="button" onClick={() => onAccept(invite.collection_id)} className="col-invite-accept">
{t('collections.invites.accept')}
</button>
<button type="button" onClick={() => onDecline(invite.collection_id)} className="col-invite-decline">
{t('collections.invites.decline')}
</button>
</div>
</div>
);
}
@@ -4,6 +4,7 @@ import type { Collection } from '@trek/shared'
import type { TranslationFn } from '../../types'
import { ALL_SAVED } from '../../store/collectionStore'
import type { ActiveCollectionId, IncomingCollectionInvite } from '../../store/collectionStore'
import CollectionInviteCard from './CollectionInviteCard'
interface ListsRailProps {
ownedLists: Collection[]
@@ -90,18 +91,7 @@ export default function ListsRail(props: ListsRailProps): React.ReactElement {
<span className="badge">{incomingInvites.length}</span>
</div>
{incomingInvites.map(inv => (
<div key={inv.collection_id} className="col-invite">
<div className="t">{inv.name}</div>
<div className="s">{t('collections.invites.from')} {inv.from.username}</div>
<div className="col-invite-actions">
<button type="button" onClick={() => onAcceptInvite(inv.collection_id)} className="col-invite-accept">
{t('collections.invites.accept')}
</button>
<button type="button" onClick={() => onDeclineInvite(inv.collection_id)} className="col-invite-decline">
{t('collections.invites.decline')}
</button>
</div>
</div>
<CollectionInviteCard key={inv.collection_id} invite={inv} onAccept={onAcceptInvite} onDecline={onDeclineInvite} t={t} />
))}
</>
)}