Repository navigation
fix(invoice-schedule): validate the form before previewing an invoice - #1818
Open
gabrielseco wants to merge 1 commit into
Open
gabrielseco wants to merge 1 commit into
gabrielseco wants to merge 1 commit into
Conversation
Contributor
📦 Bundle Size Report
Size Limits
Largest Files (Top 5)
View All Files (307 total)
✅ Bundle size check passed |
Contributor
|
Deploy preview for remote-flows ready!
Deployed with vercel-action |
Contributor
|
Deploy preview for adp-cost-calculator ready!
Deployed with vercel-action |
Contributor
📊 Coverage Report
|
| Metric | Current | Previous | Change | Status |
|---|---|---|---|---|
| Lines | 90.17% | 90.15% | +0.02% | 🟢 |
| Statements | 90.05% | 90.03% | +0.02% | 🟢 |
| Functions | 89.04% | 89.03% | +0.01% | 🟢 |
| Branches | 81.61% | 81.66% | -0.05% | 🔴 |
Detailed Breakdown
Lines Coverage
- Covered: 5722 / 6346
- Coverage: 90.17%
- Change: +0.02% (20 lines)
Statements Coverage
- Covered: 5791 / 6431
- Coverage: 90.05%
- Change: +0.02% (20 statements)
Functions Coverage
- Covered: 1511 / 1697
- Coverage: 89.04%
- Change: +0.01% (2 functions)
Branches Coverage
- Covered: 3520 / 4313
- Coverage: 81.61%
- Change: -0.05% (6 branches)
✅ Coverage check passed
7 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Preview invoice button now validates the form first: missing required fields show their error messages, and no preview is requested until the form is valid.
Why
Preview built the invoice straight from the current values and skipped validation, so an empty form showed no field errors (only Continue did). Integrators reading
fieldState.errorto render errors saw nothing after clicking Preview.What changed
Toggle details
PreviewInvoiceButton(Contractor Onboarding) andInvoiceSchedulePreviewButton(Invoice Schedule) now submit the surrounding form, the same way Save Draft does. The form runs its normal validation and, only when valid, runs the preview with the validated values.Screenshots
Toggle screenshots
Create invoice schedule step, empty form, after clicking Preview invoice (Contractor Management, PRT, sandbox).
Filled form still opens the preview drawer:
Related Resources
Testing
Added a test per flow: with required fields empty, clicking Preview shows "Required field" and makes no preview request. Both fail with the fix removed (the request fires and no errors show) and pass with it.
Updated the existing Invoice Schedule preview tests to fill the form first, since Preview now validates.
Verified in the example app against sandbox: empty form shows 5 required-field errors and 0 preview requests (before: 1 request, 0 errors); a filled form opens the drawer.
Tested against the
example/app in a browserFeature flag: N/A
Note
Low Risk
Behavior change is localized to preview buttons and form submit handlers; no public API changes, and invalid previews are blocked rather than broadened.
Overview
Preview invoice now runs through the same form submit path as Continue/Save Draft, so react-hook-form validation runs first. Empty or invalid forms show Required field (and other) errors and do not call the preview API.
In Contractor Onboarding (
PreviewInvoiceButton) and Invoice Schedule (InvoiceSchedulePreviewButton), the click handler dispatches a syntheticsubmiton the flow form withisPreviewSubmissionand apreviewCallback.ContractorOnboardingFormandInvoiceScheduleFormdetect that flag, invoke the callback with validated values, and skip create/submit logic. Preview therefore uses current form values after full validation, including fields omitted from the preview payload (e.g. recurrence/end date).Tests assert missing required fields block the preview request; Invoice Schedule tests fill the form before exercising happy paths.
Reviewed by Cursor Bugbot for commit 30159f4. Bugbot is set up for automated code reviews on this repo. Configure here.