Skip to content

fix: prevent auto-approval banner from showing before eligibility check#1387

Open
rlho wants to merge 3 commits intomainfrom
fix/auto-approval-banner-initial-state
Open

fix: prevent auto-approval banner from showing before eligibility check#1387
rlho wants to merge 3 commits intomainfrom
fix/auto-approval-banner-initial-state

Conversation

@rlho
Copy link
Copy Markdown
Collaborator

@rlho rlho commented Apr 7, 2026

Summary of Changes

The "Yay! This request is eligible for automatic approval" banner was briefly shown for all rooms regardless of auto-approval eligibility. The root cause was useState(true) as the initial value for isAutoApproval in useCheckAutoApproval. This meant the banner displayed immediately on render, before the useEffect could check actual room eligibility.

Changed the initial state to useState(false) so the banner only appears after the eligibility check confirms auto-approval.

Checklist

  • I linked relevant issue(s) in the Development section
  • I checked for existing implementations and confirmed there is no duplication
  • I thoroughly tested this feature locally
  • I added or updated unit tests (or explained why not in the PR description)
  • I attached screenshots or a video demonstrating the feature (or explained why not in the PR description)
  • I incorporated Copilot's feedback (or explained why not in the PR description), and marked conversations as resolved
  • I confirmed my PR passed all unit and end-to-end (E2E) tests
  • I confirmed there are no conflicts
  • I requested a code review from at least one other teammate

Screenshots / Video

N/A — One-line state initialization fix. Before: banner flashes on load for all rooms. After: banner only appears when eligibility is confirmed.

The auto-approval banner was shown immediately on page load because
useState(true) was used as the initial value. This caused the "eligible
for automatic approval" banner to flash for all rooms before the
useEffect ran to check actual eligibility. Changed to useState(false)
so the banner only appears after eligibility is confirmed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 7, 2026 19:51
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 UI flash in the booking flow where the “eligible for automatic approval” banner could briefly render before auto-approval eligibility is actually computed.

Changes:

  • Initialize isAutoApproval to false in useCheckAutoApproval to avoid showing the success banner on first render.
  • Add a unit test intended to validate the hook’s initial isAutoApproval state.

Reviewed changes

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

File Description
booking-app/components/src/client/routes/booking/hooks/useCheckAutoApproval.tsx Changes the initial isAutoApproval state to false so the success banner can’t appear pre-check.
booking-app/tests/unit/auto-approval-initial-state.unit.test.tsx Adds a regression test for the hook’s initial auto-approval state (needs adjustment to truly validate pre-effect initial render).

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

Address Copilot review:
- Use BookingContext.Provider wrapper instead of _currentValue mock
- Capture renderValues[] to assert the first render is false, not just
  the final state (verified: test fails with useState(true))

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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

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


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

Add an explicit "checking" state so BookingStatusBar does not render
approval/rejection banners before the eligibility check completes.
Also remove unused imports (act, beforeEach) from the test file.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

2 participants