You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(refunds): preserve approval selection during loading - #1413
Fixes an approver-selection race condition in RefundModal when fetching approvers while an approver is already selected or during parent order refreshes, and isolates server-app-ordering.spec.ts in test runners to avoid request rate-limiting on batch runs.
Changes
RefundModal.tsx: Retain selectedApproverId and PIN during approver re-fetch if previously selected approver remains valid in the newly fetched list.
scheduled-orders.spec.ts: Synchronize approver selection with approver fetch completion before entering manager credentials.
package.json: Split server-app-ordering.spec.ts into a separate Playwright test invocation under test:e2e:browser to protect the backend rate limiter during single-process test runs.
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.
The following are alternative approaches to this PR:
1. Refetch approvers at each time-tier change
➕ Would pick up staff configuration changes without waiting for submission.
➖ Adds requests and reintroduces asynchronous selection races that require careful reconciliation.
Recommendation: Locally reevaluating the loaded approvers is appropriate for the time-tier transition: it preserves valid input without another fetch, while submission still refreshes approvers and the backend remains authoritative. Keep the loading and identity guards because readiness must not expose stale credentials.
Files changed (4) +170 / -56
Bug fix (1) +40 / -21
RefundModal.tsxKeep refund approval state stable across time ticks+40/-21
Keep refund approval state stable across time ticks
• Stops refetching approvers when the order's time tier changes and clears the PIN only when the selected approver becomes ineligible. Tracks which user the loaded approvers belong to and disables PIN entry and submission until loading succeeds.
scheduled-orders.spec.tsExercise refund approver loading and time-tier transitions+124/-34
Exercise refund approver loading and time-tier transitions
• Uses disposable manager fixtures and waits for approvers before entering credentials. Adds coverage for stale responses, failed or empty loads, PIN retention, and clearing an invalid selection.
1. Cashiers cannot refund after tier change✓ Resolved
Description
The interval in RefundModal selects a new default only when approverId is nonempty and no longer
eligible. If the modal starts with multiple approvers and no selection, then crosses into the
owner-only tier with one owner available, it displays that owner but leaves PIN entry and submission
disabled until the modal is reopened.
ⓘ Recommendations generated based on similar findings in past PRs
Evidence
The interval skips its update when approverId is empty. The render-time fallback displays the sole
eligible owner without updating that state; both submission and PIN entry require the fallback ID to
equal the stateful ID.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
When the refund tier changes, an empty approver selection is never replaced, even if exactly one eligible owner remains. The displayed owner cannot receive a PIN or submit the refund.
## Fix Focus Areas
- frontend/src/components/orders/RefundModal.tsx[150-158]
## Recommended Fix
On each eligibility check, also set the approver ID when it is empty and there is exactly one eligible approver. Preserve the existing behavior for a selected approver that remains eligible, and clear the PIN when the selected approver becomes ineligible.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
2. Refund timing hint can lag after approver changes 🐞 Bug☼ Reliability
Description
The 30-second interval that updates now and re-checks approver eligibility is now torn down and
recreated every time approvers or approverId changes, unlike the old timer with empty
dependencies. Each time a cashier switches approvers (or submit reloads approvers), the next tick
starts over, so the late-tier hint and the auto-clear of an ineligible approver or PIN fire later
than the 30-second cadence the comment above now promises.
ⓘ Recommendations generated based on similar findings in past PRs
Evidence
The effect's dependency array includes approverId and approvers, so a dropdown change or the
submit path's setApprovers(configuredApprovers) clears and restarts the interval. The comment at
lines 79-80 says the timer ticks while the modal is open. The backend still checks the approver at
submit, so the impact is limited to the UI being out of date for a while.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
The RefundModal interval is recreated whenever `approvers`/`approverId` change, so the 30s tick that updates `now` restarts and the late-tier re-check is pushed back.
## Fix Focus Areas
- frontend/src/components/orders/RefundModal.tsx[146-161]
## Recommended Fix
Go back to a single `setInterval(() => setNow(Date.now()), 30000)` with `[]` deps. Move the eligibility reconciliation into a separate effect keyed on `[isLikelyLate, approvers]`, or do it during render with a synced-value guard. That effect clears `approverId` and the PIN and picks the preferred default when the selected approver is no longer eligible. Keep reading `approverId` through state or a ref so the timer doesn't have to restart.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
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
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
Fixes an approver-selection race condition in
RefundModalwhen fetching approvers while an approver is already selected or during parent order refreshes, and isolatesserver-app-ordering.spec.tsin test runners to avoid request rate-limiting on batch runs.Changes
RefundModal.tsx: RetainselectedApproverIdand PIN during approver re-fetch if previously selected approver remains valid in the newly fetched list.scheduled-orders.spec.ts: Synchronize approver selection with approver fetch completion before entering manager credentials.package.json: Splitserver-app-ordering.spec.tsinto a separate Playwright test invocation undertest:e2e:browserto protect the backend rate limiter during single-process test runs.docs/architecture/order-lifecycle.md: Clarify refund approval selection persistence semantics.Stack
Verification
npm run test:refunds: Passednpm run test:scheduled-orders: Passed