Skip to content

fix(invoice-schedule): prefill the occurrence count with 1 when end after is picked - #1756

Open
gabrielseco wants to merge 13 commits into
pbyr-5291-end-date-choicefrom
feat/reveal-field-defaults
Open

gabrielseco wants to merge 13 commits into
pbyr-5291-end-date-choicefrom
feat/reveal-field-defaults

Conversation

@gabrielseco

@gabrielseco gabrielseco commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Picking "End after a number of occurrences" on an invoice schedule now fills "Number of occurrences" with 1, the same as on the Remote platform.

Why

The count showed an empty field and a required error until the user typed a number. The schema can already carry a default, and flows such as Contractor Onboarding apply it, but the standalone Invoice Schedule flow builds its form before the schema loads and never read it.

What changed

Toggle details
  • nr_occurrences gets default: 1 in the invoice schedule schema. Contractor Onboarding shares the schema and already applies defaults through getInitialValues, so it picks the value up with no change there.
  • InvoiceScheduleForm now creates the form itself instead of reading one from the context. Its starting values come from the bag's initialValues, which the hook builds with getInitialValues from the loaded fields and the flow's defaultValues, so a schema default is applied the same way as in Contractor Onboarding. Before, the form was created in InvoiceScheduleFlow before the schema loaded. The form has to be mounted once isLoading is false, as in the README example: mounted earlier, it starts with no values.
  • The flow keeps only the bag and the form id. The bag gains initialValues and fieldValues (the latest values, fed by the form through checkFieldUpdates), and the preview button reads them from there. useInvoiceSchedule also takes the flow's defaultValues as an option.
  • InvoiceScheduleFlow is keyed by employmentId, so a different contractor starts from a fresh form.
  • The Contractor of Record frequency reset is removed. The schema already rejects a frequency it no longer offers, and the onboarding step has no such reset.
  • The count is set while the field is still hidden, so revealing it shows 1. It is not sent when "No end date" is chosen (checked through onboarding with a monthly schedule: the request has no `nr_occurrences`).
  • A count the user empties is not refilled when the radio is toggled.
  • No exported component or prop changes. The bag gains initialValues and fieldValues, and UseInvoiceScheduleOptions gains an optional defaultValues; all additive. Stacked on feat(invoice-schedule): choose how a recurring schedule ends #1744; retarget to main once it merges.

Screenshots

Toggle screenshots

Before (#1744): the count is empty with a required error after picking "End after". After:

End after count defaults to 1
End after count defaults to 1

Related Resources

Testing

InvoiceScheduleFlow.test.tsx checks the count is 1 after picking "End after". Bypassing `getInitialValues` makes it fail.

  • Tested against the example/ app in a browser (sandbox, PRT contractor) count is 1 on first pick and a typed value survives toggling the radio
  • Feature flag: N/A

🤖 Generated with Claude Code


Note

Medium Risk
Refactors form lifecycle and shared context for invoice schedules; behavior changes around mount timing, preview values, and CoR frequency handling without API changes.

Overview
Choosing End after a number of occurrences now shows Number of occurrences prefilled with 1, matching the Remote platform. The invoice schedule JSON schema adds default: 1 on nr_occurrences.

The standalone flow no longer builds the form at the flow level before the schema loads. InvoiceScheduleForm owns useJSONSchemaForm and seeds it from the bag’s initialValues, which useInvoiceSchedule builds with getInitialValues once fields are ready (including flow defaultValues). Consumers should mount the form only after isLoading is false; docs and tests follow that pattern.

InvoiceScheduleFlow is keyed by employmentId so switching contractors remounts a clean form. Context drops the shared form instance; preview uses fieldValues from checkFieldUpdates. The client-side effect that cleared recurring periodicity when Contractor of Record loaded is removed.

Reviewed by Cursor Bugbot for commit 7872561. Bugbot is set up for automated code reviews on this repo. Configure here.

A field with a schema default that becomes visible after the form mounts is filled with that default if it is still empty. Fields visible on first render, read-only and forced-value fields are left alone. Uses it for the invoice schedule occurrence count, which now starts at 1 once "End after a number of occurrences" is picked.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

📦 Bundle Size Report

Metric Current Previous Change Status
Total (gzip) 231.92 kB 231.89 kB +32 B (+0.0%) 🔴
Total (raw) 645.89 kB 645.74 kB +149 B (+0.0%) 🔴
CSS (gzip) 21.95 kB 21.95 kB 0 B (0%) 🟢
CSS (raw) 114.51 kB 114.51 kB 0 B (0%) 🟢

Size Limits

  • ✅ Total gzipped: 231.92 kB / 350 kB (66.3%)
  • ✅ Total raw: 645.89 kB / 850 kB (76.0%)
  • ✅ CSS gzipped: 21.95 kB / 25 kB (87.8%)

Largest Files (Top 5)

  1. index.esm-wIkXrqU6.js - 11.4 kB (0 B (0%))
  2. styles.css - 10.97 kB (0 B (0%))
  3. index.css - 10.97 kB (0 B (0%))
  4. internals-Cdk22Zh1.js - 6.13 kB (0 B (0%))
  5. hooks-wa9PHHsM.js - 5.76 kB (new)
View All Files (291 total)
File Size (gzip) Change
index.esm-wIkXrqU6.js 11.4 kB 0 B (0%)
styles.css 10.97 kB 0 B (0%)
index.css 10.97 kB 0 B (0%)
internals-Cdk22Zh1.js 6.13 kB 0 B (0%)
hooks-wa9PHHsM.js 5.76 kB new
sdk.gen-BRPiw4M1.js 5.58 kB 0 B (0%)
index.js 5.51 kB 0 B (0%)
flows/Onboarding/hooks.js 4.67 kB 0 B (0%)
utils-Bc1UgCXy.js 4.26 kB 0 B (0%)
FieldSetField-IPPOYf7r.js 4.11 kB 0 B (0%)

✅ Bundle size check passed

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Deploy preview for adp-cost-calculator ready!

Project:adp-cost-calculator
Status: ✅  Deploy successful!
Preview URL:https://adp-cost-calculator-f9d2i3l9h-remotecom.vercel.app
Latest Commit:7872561

Deployed with vercel-action

… revealed

The form can render with no fields while its schema loads. The empty list was recorded as the baseline, so every field that then appeared with a default was filled in. The baseline now starts at the first render that has fields.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Deploy preview for remote-flows ready!

Project:remote-flows
Status: ✅  Deploy successful!
Preview URL:https://remote-flows-9x425p5cj-remotecom.vercel.app
Latest Commit:7872561

Deployed with vercel-action

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

📊 Coverage Report

✅ Coverage increased! 🎉

Metric Current Previous Change Status
Lines 89.69% 89.68% +0.01% 🟢
Statements 89.56% 89.55% +0.01% 🟢
Functions 88.59% 88.56% +0.03% 🟢
Branches 81.51% 81.53% -0.01% 🔴

Detailed Breakdown

Lines Coverage
  • Covered: 5443 / 6069
  • Coverage: 89.69%
  • Change: +0.01% (6 lines)
Statements Coverage
  • Covered: 5508 / 6150
  • Coverage: 89.56%
  • Change: +0.01% (6 statements)
Functions Coverage
  • Covered: 1444 / 1630
  • Coverage: 88.59%
  • Change: +0.03% (4 functions)
Branches Coverage
  • Covered: 3382 / 4149
  • Coverage: 81.51%
  • Change: -0.01% (-7 branches)

✅ Coverage check passed

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread src/components/form/useApplyRevealDefaults.ts Outdated
…ds instead of a form-wide hook

The standalone flow builds its form before the schema loads, so a schema default was never read. It now runs the same initial-values helper the other flows use once its fields arrive, and fills only values that are still empty. The generic reveal-time hook is removed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@gabrielseco gabrielseco changed the title feat(forms): apply a schema default when a conditional field is revealed fix(invoice-schedule): prefill the occurrence count with 1 when end after is picked Oct 27, 2026

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

}
},
);
}, [fields, form]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reveal defaults only seed one flow

Medium Severity

Removing useApplyRevealDefaults from JSONSchemaFormFields drops the reveal-default behavior for every other consumer of the shared invoice-schedule schema. CreateInvoiceScheduleStep still has default: 1 on nr_occurrences but never writes it, so picking “End after a number of occurrences” in contractor onboarding leaves the count empty and required. Headless useInvoiceSchedule callers that build their own form miss it too.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by project rule: Code Review Guidelines

Reviewed by Cursor Bugbot for commit 9ce60f5. Configure here.

gabrielseco and others added 2 commits October 27, 2026 14:04
…m like the other flows

The form was created in InvoiceScheduleFlow before the schema loaded, so schema defaults could not feed its initial values. InvoiceScheduleForm now mounts once the fields exist and builds its values with getInitialValues, as the onboarding and termination forms do. The flow keeps the bag, the form id and a ref the preview button reads the live values from. The one-off seeding effect is removed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…eRefObject

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4291211. Configure here.

Comment thread src/flows/InvoiceSchedule/InvoiceScheduleForm.tsx Outdated
gabrielseco and others added 8 commits October 27, 2026 14:13
…ecord reset

The preview button now reads the latest values from the bag, which the form reports through checkFieldUpdates, so the form no longer registers itself in a ref. The flow is keyed by employmentId, so a different contractor starts from a fresh form. The frequency reset for a Contractor of Record is removed: the schema already rejects a frequency it no longer offers, and onboarding has no such reset.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…er from InvoiceScheduleFlow

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…nt wrapper from InvoiceScheduleFlow"

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…e them on the bag

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…form on isLoading like the other flows

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… already-cached contractor

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… bag members, tidy leftovers

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…alues

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant