Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ function WorkspaceTravelInvoicingSection({policyID}: WorkspaceTravelInvoicingSec
* When turning OFF: show confirmation modal, then call deactivateTravelInvoicing.
*/
const handleToggle = (isEnabled: boolean) => {
// Block toggling while a card-settings request is in flight here rather than through `disabled`, which would flash the lock icon on the toggle.
if (isLoading) {
return;
}

// Check if user is on a public domain - Travel Invoicing requires a private domain
if (account?.isFromPublicDomain) {
const hasPolicyIDInActiveRoute = getSearchParamFromPath(Navigation.getActiveRoute(), CONST.SEARCH.SYNTAX_FILTER_KEYS.POLICY_ID) !== null;
Expand Down Expand Up @@ -418,7 +423,7 @@ function WorkspaceTravelInvoicingSection({policyID}: WorkspaceTravelInvoicingSec
switchAccessibilityLabel={translate('workspace.moreFeatures.travel.travelInvoicing.travelInvoicingSection.subtitle')}
onToggle={handleToggle}
isActive={isTravelInvoicingEnabled}
disabled={!canWriteMoreFeatures || isLoading || isOnWaitlist}
disabled={!canWriteMoreFeatures || isOnWaitlist}
disabledAction={getToggleDisabledAction()}
showLockIcon={!canWriteMoreFeatures || isOnWaitlist || hasOutstandingBalance}
pendingAction={togglePendingAction}
Expand Down
23 changes: 23 additions & 0 deletions tests/ui/WorkspaceTravelInvoicingSectionTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,29 @@ describe('WorkspaceTravelInvoicingSection', () => {

expect(screen.queryByTestId(CONST.SWITCH_LOCK_ICON_TEST_ID, {includeHiddenElements: true})).toBeNull();
});

it('does not show the toggle lock icon while card settings are loading', async () => {
// Given a configured, enabled workspace with no balance while a card-settings request is in flight
await act(async () => {
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, mockPolicy);
await Onyx.merge(cardSettingsKey, {
isLoading: true,
TRAVEL_US: {
isEnabled: true,
paymentBankAccountID: 12345,
currentBalance: 0,
pendingSettlementAmount: 0,
},
});
await waitForBatchedUpdatesWithAct();
});

renderWorkspaceTravelInvoicingSection();
await waitForBatchedUpdatesWithAct();

// Loading pulses (openPolicyTravelPage runs on every page focus) must not flash the lock icon
expect(screen.queryByTestId(CONST.SWITCH_LOCK_ICON_TEST_ID, {includeHiddenElements: true})).toBeNull();
});
});

describe('Currency Conversion Prompt', () => {
Expand Down
Loading