Description
Multiple co-creators editing an invoice simultaneously have no awareness of each other's position or intent, leading to overwrite conflicts and confusion. This issue implements a real-time collaborative editing layer for /invoice/new and /invoice/[id] using WebSockets or a CRDT-backed channel, rendering each connected user's cursor position and active field as a colored presence indicator. The feature must gracefully degrade when the WebSocket connection drops, locking out concurrent edits and showing a reconnection banner.
Technical Context
Involves creating hooks/useInvoiceCollaboration.ts with a WebSocket connection manager and conflict resolver, extending app/invoice/new/page.tsx and app/invoice/[id]/page.tsx to render <CursorOverlay> and <PresencePill> components. Each form field must emit focus/blur events to the channel. The useReducer pattern should manage remote cursor state keyed by userId. Server-side, a lightweight Next.js Route Handler at app/api/collab/[invoiceId]/route.ts should broker connections or proxy to an external Partykit/Liveblocks endpoint. Existing co-creator permission logic in the permissions panel must gate write access before the socket is opened.
Acceptance Criteria
Description
Multiple co-creators editing an invoice simultaneously have no awareness of each other's position or intent, leading to overwrite conflicts and confusion. This issue implements a real-time collaborative editing layer for
/invoice/newand/invoice/[id]using WebSockets or a CRDT-backed channel, rendering each connected user's cursor position and active field as a colored presence indicator. The feature must gracefully degrade when the WebSocket connection drops, locking out concurrent edits and showing a reconnection banner.Technical Context
Involves creating
hooks/useInvoiceCollaboration.tswith a WebSocket connection manager and conflict resolver, extendingapp/invoice/new/page.tsxandapp/invoice/[id]/page.tsxto render<CursorOverlay>and<PresencePill>components. Each form field must emit focus/blur events to the channel. TheuseReducerpattern should manage remote cursor state keyed byuserId. Server-side, a lightweight Next.js Route Handler atapp/api/collab/[invoiceId]/route.tsshould broker connections or proxy to an external Partykit/Liveblocks endpoint. Existing co-creator permission logic in the permissions panel must gate write access before the socket is opened.Acceptance Criteria