Share one recipients editor across the email composer, approval cards and calendar

Merged
FE
11h ago
+829-683

Based on main. Also carries the change from twentyhq/twenty#30415 (closed in favour of this stack): email proposal bodies are stored as documents, so plain-text bodies keep their line breaks, and the approval card only reads documents. twentyhq/twenty#30456 later replaces that server conversion with explicit body formats.

Problem

There were two To/Cc/Bcc editors. The composer used EmailRecipientsFieldInput (contact suggestions, drag between fields, chip keyboard navigation). The AI approval card and review deck used AiChatEmailRecipientsRow, a plain input with chips. On top of that, the drag-and-drop setup (sensors, plugins, handlers, drop context, dragged indices, excluded suggestion keys) was copied in the composer, the calendar composer and the field story.

Change

  • EmailRecipientsProvider owns the recipients of a group of fields (recipientsByFieldId and onChange) plus all the drag-and-drop wiring. It exposes them through EmailRecipientsContext, built with the existing createRequiredContext.
  • EmailRecipientsFieldInput now takes only fieldId, label, onSubmit, contextRecord and inputRef. It reads its recipients, drag state and excluded suggestion keys from the context, so a caller can no longer pass them inconsistently.
  • EmailRecipientsFields is the To/Cc/Bcc group: { recipientsByFieldId, onChange, onSubmit?, contextRecord?, readonly? }.
    • It owns the Cc/Bcc toggle: Cc and Bcc show when expanded, while a drag is in progress, or when either already has recipients.
    • It has a read-only mode (EmailRecipientsReadonlyFields) for sent or skipped emails in the review deck.
  • Callers:
    • The composer uses EmailRecipientsFields. showCcBcc is removed from useEmailComposerState.
    • The AI approval card and review deck use EmailRecipientsFields. isCcBccExpanded is removed from the draft type. AiChatEmailRecipientsRow is deleted. Approval cards gain contact suggestions, drag between fields and chip keyboard navigation.
    • The calendar composer wraps its Guests field in EmailRecipientsProvider.
  • EmailRecipientsByFieldId moves from moveEmailRecipientsBetweenFields.ts to types/, and DraggedEmailRecipients gets its own type.

Screenshots

From Storybook, before (twentyhq/twenty#30415) and after. The layout is unchanged on purpose; what changes is that the approval card now runs the composer's editor.

AI approval deck, typing in To. Before: a plain text box. After: the shared editor's autocomplete. It reads "No results" only because the story mocks no people.

BeforeAfter

AI approval deck, Cc/Bcc expanded. Before: "Add recipient" placeholders on the old row. After: the same fields as the composer.

BeforeAfter

Read-only review (sent or locked). Before: a "Cc/Bcc" toggle stayed on a card that can't be edited. After: EmailRecipientsReadonlyFields lists the recipients only.

BeforeAfter

Unchanged on screen, now built on the same component: the email composer (Cc/Bcc expanded) and the calendar composer's Guests field.

Email composerCalendar guests

Not in scope

  • Campaigns: they target a message list, not addresses, so they keep their list picker.
  • Workflow email steps: recipients are variable-capable text fields there. Moving them onto chips needs variable support in the chip input, which is a separate change.

Tests

  • New EmailRecipientsFields.test.tsx: Cc/Bcc revealed on demand and focused; shown when they already have recipients; removing a chip updates its field; read-only lists recipients without inputs or remove buttons.
  • AiChatToolCallApprovalEmailCard.test.tsx now mocks contact suggestions, renders inside a ToastProvider and polyfills PointerEvent, like other drag-and-drop tests.
  • build-inbox-message-tool-call-part.util.spec.ts (from #30415): an app proposing a plain-text body gets a document with hard breaks.
  • The ai, activities, side-panel and email-thread widget suites pass (1,845 tests). Typecheck, oxlint and oxfmt are clean on the changed files.

Generated by Claude Code