Commit a393365
feat(billing): normalize the invoice editor onto the quote save grammar (#2829)
Brings the **Invoice** editor/detail/workspace onto the same save/UX
grammar the **Quote** side already had, de-duplicates the two, and fixes
the save-gate bugs that surfaced once both surfaces were compared side
by side.
Two commits: the normalization, then the fixes from a full multi-agent
review of it.
## The normalization
**New shared modules**
- `billing/shared/saveCues.tsx` — the blur-to-save grammar
(`useSavedFlash`, `SrSaved`, `fieldRing`, `seamless`, `unsavedHintId`),
lifted out of `quoteEditorShared`. The dirty signal moved from a ring to
border-color because the focus ring occupies the box-shadow channel and
was painting over the cue on exactly the field being edited.
- `billing/shared/OrgCombobox.tsx` — typeahead org picker replacing a
native `<select>`, which stops scaling at MSP org counts.
**Invoices** — autosave hint + last-saved indicator, undo line-delete,
show/hide cost & margin, aria label on the horizontally scrolling lines
table.
**Quotes** — send-dialog warnings ($0 total, no Stripe, missing billing
contact, deposit-without-Stripe), undo-send / send-now, save-timeout
copy.
All five locales updated in parity.
## The fixes
The review found a pair of opposite bugs sharing one cause: the editors
reported *"a field is dirty"* and *"a save is in flight"* as the same
signal.
- A **failed line save** left an amber "unsaved" border while its
in-flight key cleared — so the editor read as quiet and Issue stayed
enabled, numbering the invoice at the pre-edit money.
- A **failed notes/terms save** left the field dirty forever, pinning
*"Saving changes… Issue unlocks when everything is saved"* over a save
that had already given up, with no way out and no pointer to the field.
The gate is now two signals: `savePending` (in flight, resolves on its
own → a click queues behind it) and `unsavedFieldLabel` (save failed and
the field is still dirty → the click is refused and the field is named).
That second signal is the **intersection** of "last attempt failed" and
"still differs from the server", and needs both halves. Failure alone
keeps blocking after the user reverts by hand — the commit path
short-circuits on an unchanged value, so no fresh attempt ever clears
the flag. Dirty alone fires during the round-trip between a successful
save and its refetch, refusing an Issue that is perfectly valid.
The same bug existed twice more on the quote side (`QuoteEditor` terms,
`QuoteHeaderMeta` title); both fixed identically. `QuoteActions` also
gains the failure nonce and the spinner rule it never received — its
queued Send fired on post-failure quiescence, and it spun forever on a
dirty field.
**Also**
- Queued Issue/Send capture `atFailureNonce` rather than relying on two
effects observing two props in a lucky order. The old comment credited
*"effects run in definition order"*; what actually protected it was
`savePending` lagging by one commit. Right code, wrong reason, one
refactor away from a race on an irreversible money action.
- The queue re-checks `hasVisibleLines` before firing — flushing the
deferred delete of the last visible line is itself what the click
triggered.
- A partial delete-flush reports what landed instead of only "canceled".
- `runScoped` no longer stamps "Saved 3:14 PM" on add-line validation
failures.
- `loadCatalog` guards its parse; an empty picker and a broken one now
read differently.
- `QuoteBlockCard`'s dirty/saved cue rendered **nothing** — `fieldRing`
emits border-color and the element carried no border width.
`seamless(state, invalid)` stops the error branch dropping the only
focus indicator on an invalid field. Five quote sites moved off
`transition-shadow`.
- `OrgCombobox`: the combobox role moves to the search input (the
element that holds focus), `aria-activedescendant` added,
`aria-selected` tracks the cursor — arrow navigation was silent to
assistive tech. The clone dialog's `<label>` wrapper became a `<div>`: a
click on the popover's own chrome forwarded to the trigger and closed it
mid-search. `orgComboboxOptions()` replaces a duplicated prepend and its
two unsound casts.
- The no-billing-contact hint deep-links to `#billing`; without it the
user landed on General with no field in sight.
- `ContractEditor` migrates onto `shared/saveCues`, dropping a third
divergent copy still on `ring-1 ring-warning` (~2.3:1, below the 3:1
non-text minimum).
- Comments asserting rationale the code didn't implement are corrected:
the border-width precondition, the `transition-colors` pairing, "one
place it evolves", the CatalogItemPicker claim.
## Testing
- **503 files / 4531 tests pass**, run twice to rule out flakes
- `tsc --noEmit` clean
- Locale parity: **1213 keys × 5 locales**, no drift
New: `shared/saveCues.test.tsx` (the 1500ms expiry and unmount teardown
shipped untested) and `QuoteHeaderMeta.title.test.tsx`. Added coverage
for the same-render failure+quiescence race, the failed-delete-flush
cancel, the quote 10s backstop, `DocumentWorkspace`'s slots, the margin
memory mirror under blocked storage, and the catalog error state.
**Reviewer note:** three existing tests encoded the old contract (dirty
⇒ "saving") and were rewritten rather than preserved. That's a
deliberate behavior change and the right place to push back if you
disagree with it.
Scope: `apps/web` only — no API, schema, migrations, or cascade lists
touched.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Todd Hebebrand <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>1 parent 83556c8 commit a393365
53 files changed
Lines changed: 4181 additions & 660 deletions
File tree
- apps/web/src
- components
- billing
- quotes
- contracts
- layout
- lib
- __tests__
- locales
- de-DE
- en
- es-419
- fr-CA
- fr-FR
- it-IT
- pt-BR
- pages/billing/invoices
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 217 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
0 commit comments