Skip to content

fix: wire up Add Employee screen#1694

Merged
jeffredodd merged 3 commits intomainfrom
fix/wire-add-employees-to-policy-transition
May 6, 2026
Merged

fix: wire up Add Employee screen#1694
jeffredodd merged 3 commits intomainfrom
fix/wire-add-employees-to-policy-transition

Conversation

@jeffredodd
Copy link
Copy Markdown
Contributor

@jeffredodd jeffredodd commented May 6, 2026

Summary

Reworks the Add Employees screen reached from a Time-Off policy detail page so a single round-trip can manage the policy's roster end-to-end. Previously the user landed on a list of every non-terminated employee with no indication of who was already on the policy — re-submitting an existing assignee was easy and removing one was a separate flow on the detail page.

Two parts:

  1. State machine wiring (already on this branch): viewTimeOffPolicyDetail now transitions to addEmployeesToPolicy on TIME_OFF_ADD_EMPLOYEES_TO_POLICY, reducing the payload's policyId into context. Round-trip back via the existing TIME_OFF_ADD_EMPLOYEES_DONE transition.
  2. Manage-membership UX (new): the Add Employees screen now pre-selects existing assignees, shows their current balance read-only, diffs the selection at submit time, and gates removals behind a destructive confirm dialog.

Behavior details on (2):

  • useSelectEmployeesData accepts initialSelectedUuids to seed the selection set.
  • For originally-on-policy rows, the balance cell renders as read-only text (their current saved balance). Editable balance + carry-over pre-fill remains for newly-added rows.
  • At submit, compute the diff against policy.employees. toAdd calls useTimeOffPoliciesAddEmployeesMutation; toRemove calls useTimeOffPoliciesRemoveEmployeesMutation. Unchanged rows are skipped — balances for existing assignees are owned by the dedicated edit-balance flow on the detail page.
  • When toRemove.length > 0 a destructive confirm dialog gates the submit. On confirm, run remove first, then add, then invalidate the policy cache.
  • Empty diff is a pure no-op: emits TIME_OFF_ADD_EMPLOYEES_DONE without an API call so navigation still works.
  • Wizard mode is unchanged (no policy fetched, still emits employeeUuids).

This is PR 9 in the time-off bug-fix slate captured in ~/.claude/plans/ok-i-want-to-partitioned-balloon.md. Plan for the membership UX work: ~/.claude/plans/we-were-just-working-memoized-island.md.

Test plan

  • npm run test -- --run src/components/UNSTABLE_TimeOff — 305/305 passing (added 6 new tests covering pre-select, read-only balance, no-op diff, add-only path, dialog-gated submit, remove-then-add ordering, cache invalidation)
  • npx tsc --noEmit — clean
  • npm run lint — clean
  • Storybook: verify WithExistingAssignees, ExistingAssigneesWithNewSelections, and RemoveConfirmDialogOpen render correctly (npm run storybook)
  • Manual e2e via SDK dev app (npm run sdk-app):
    • Open a Time-Off policy detail page that already has assignees → click "Add employees" → existing assignees appear pre-selected with their balance shown read-only
    • Uncheck one existing assignee, check one new employee → click Continue → confirm dialog appears → confirm → roster reflects both add and remove
    • Open the same screen and click Continue without changing anything → no API call, navigation returns to the detail page

🤖 Generated with Claude Code

@jeffredodd jeffredodd force-pushed the fix/wire-add-employees-to-policy-transition branch from 6b9c545 to acc8e8b Compare May 6, 2026 02:36
@jeffredodd jeffredodd marked this pull request as ready for review May 6, 2026 02:45
Copilot AI review requested due to automatic review settings May 6, 2026 02:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a missing state-machine transition in the UNSTABLE Time Off flow so the “Add Employee” action from the policy detail screen actually navigates into the add-employees step and preserves the selected policyId in machine context.

Changes:

  • Added a TIME_OFF_ADD_EMPLOYEES_TO_POLICY transition from viewTimeOffPolicyDetailaddEmployeesToPolicy, reducing policyId into context.
  • Added unit tests covering the new transition and the round-trip back to viewTimeOffPolicyDetail via TIME_OFF_ADD_EMPLOYEES_DONE.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/components/UNSTABLE_TimeOff/TimeOffFlow/timeOffStateMachine.ts Wires the previously-unhandled TIME_OFF_ADD_EMPLOYEES_TO_POLICY event to transition into addEmployeesToPolicy while updating context with policyId.
src/components/UNSTABLE_TimeOff/TimeOffFlow/timeOffStateMachine.test.ts Adds regression tests validating the new transition and that policyId is preserved after returning from the add-employees step.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/components/UNSTABLE_TimeOff/TimeOffFlow/timeOffStateMachine.ts
@jeffredodd jeffredodd changed the title fix: wire TIME_OFF_ADD_EMPLOYEES_TO_POLICY into the state machine fix: make Add Employees to Policy a manage-membership screen May 6, 2026
@jeffredodd jeffredodd changed the title fix: make Add Employees to Policy a manage-membership screen fix: wire up Add Employee screen May 6, 2026
@jeffredodd
Copy link
Copy Markdown
Contributor Author

@copilot can you fix tests?

Copy link
Copy Markdown
Contributor

Copilot AI commented May 6, 2026

@copilot can you fix tests?

Added the two missing state-machine transitions in viewTimeOffPolicyDetail (commit 8d2a2de):

  • TIME_OFF_EDIT_POLICYpolicyDetailsForm (sets policyId in context)
  • TIME_OFF_CHANGE_SETTINGSpolicySettings (sets policyId in context)

Also renamed the shared { policyId } payload type from AddEmployeesToPolicyPayloadPolicyIdPayload for clarity, and added two new unit tests covering both transitions. Suite is now 307/307 passing.

jeffredodd and others added 3 commits May 6, 2026 09:11
The Add Employee button on the time-off policy detail screen emitted
TIME_OFF_ADD_EMPLOYEES_TO_POLICY, but viewTimeOffPolicyDetail had no
matching transition — so the event was swallowed and the button
appeared to do nothing.

Add a transition from viewTimeOffPolicyDetail → addEmployeesToPolicy
that reduces the payload's policyId into context. The existing
addEmployeesToPolicy → viewTimeOffPolicyDetail transition (on
TIME_OFF_ADD_EMPLOYEES_DONE) preserves ctx, so the round trip lands
back on the same policy detail with the new employees attached.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The Add Employees button now lands on a "manage membership" screen:
existing assignees are pre-checked with their current balance shown
read-only, and unchecking one queues a removal. On submit, the screen
diffs the selection against the policy's current roster and runs the
add and/or remove mutations as needed (remove first, then add). When
removals are queued, a destructive confirm dialog gates the submit.

Behavior:
- Pre-select via `useSelectEmployeesData(companyId, originalUuids)`.
- Read-only balance text for originally-on-policy rows; new selections
  keep the editable input with the carry-over pre-fill.
- Diff at submit: skip unchanged rows so balances are not re-submitted
  (the dedicated edit-balance flow on the detail page owns those).
- No-op diff just emits TIME_OFF_ADD_EMPLOYEES_DONE without an API call.
- Cache invalidation matches the detail page's pattern.
- Wizard mode is unchanged: still emits employeeUuids without fetching
  the policy.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jeffredodd jeffredodd enabled auto-merge (squash) May 6, 2026 16:11
@jeffredodd jeffredodd force-pushed the fix/wire-add-employees-to-policy-transition branch from 8d2a2de to a67611b Compare May 6, 2026 16:11
@jeffredodd jeffredodd merged commit 6d6b647 into main May 6, 2026
19 checks passed
@jeffredodd jeffredodd deleted the fix/wire-add-employees-to-policy-transition branch May 6, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants