Skip to content
Merged
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 @@ -7,9 +7,16 @@ import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePolicy from '@hooks/usePolicy';
import usePolicyFeatureWriteAccess from '@hooks/usePolicyFeatureWriteAccess';
import useThemeStyles from '@hooks/useThemeStyles';

import {getBillableExpensesPendingAction, getCashExpenseReimbursableMode, setPolicyAttendeeTrackingEnabled, setWorkspaceEReceiptsEnabled} from '@libs/actions/Policy/Policy';
import {
getBillableExpensesPendingAction,
getCashExpenseReimbursableMode,
setPolicyAttendeeTrackingEnabled,
setPolicyRequireCompanyCardsEnabled,
setWorkspaceEReceiptsEnabled,
} from '@libs/actions/Policy/Policy';
import {openPolicyTagsPage} from '@libs/actions/Policy/Tag';
import Navigation from '@libs/Navigation/Navigation';
import {getTagListLabel, getTagLists, hasPerTagListRequired, isAttendeeTrackingEnabled, isCollectPolicy, isMaxExpenseAmountSet, tryNavigateToControlPolicyUpgrade} from '@libs/PolicyUtils';
Expand Down Expand Up @@ -62,8 +69,12 @@ function IndividualExpenseRulesSectionRevamp({policyID, canWriteRules}: Individu
const {translate} = useLocalize();
const styles = useThemeStyles();
const policy = usePolicy(policyID);
// Every toggle here owes a locked-out member the read-only modal, the way the pre-revamp section gave all four of
// them. Splitting this section out dropped it, so a member saw a lock with nothing explaining it. Only the modal is
// taken from the hook: its `canWrite` is the `canWriteRules` prop already.
const {withReadOnlyFallback} = usePolicyFeatureWriteAccess(policy, CONST.POLICY.POLICY_FEATURE.RULES);

@situchan situchan Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is this hook needed?

Is this switch toggle different from other rows regarding permission?

i.e.

eReceipts used this condition: disabledAction={isCollect && canWriteRules ? navigateToRulesControlUpgrade : undefined}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right that the row shouldn't be special, but the inconsistency ran the other way. Pre-revamp, all four toggles used withReadOnlyFallback(), and PublicReceiptVisibilityToggle took it as a prop. Splitting this section out dropped it from the other three, so read-only members got a lock with no explanation. I restored it on all four, they're consistent now.

const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`);
const icons = useMemoizedLazyExpensifyIcons(['CalendarSolid', 'Coins', 'Receipt', 'ReceiptCheck', 'Task', 'Cash', 'Users', 'Eye']);
const icons = useMemoizedLazyExpensifyIcons(['CalendarSolid', 'Coins', 'CreditCard', 'Receipt', 'ReceiptCheck', 'Task', 'Cash', 'Users', 'Eye']);

const policyCurrency = policy?.outputCurrency ?? CONST.CURRENCY.USD;

Expand Down Expand Up @@ -120,6 +131,16 @@ function IndividualExpenseRulesSectionRevamp({policyID, canWriteRules}: Individu
const areEReceiptsEnabled = policy?.eReceipts ?? false;
const isAttendeeTrackingEnabledForPolicy = isAttendeeTrackingEnabled(policy);

// There has to be a card to require before the rule means anything, and either card product counts. Three separate
// things can lock the row, so each gets the response that actually explains it: no write access opens the read-only
// modal, Collect opens the upgrade the other rules use, and only a missing card product earns the More features
// tooltip. The pre-revamp row showed that tooltip for all three, which told an auditor to enable a feature that was
// already on.
const requireCompanyCardsEnabled = policy?.requireCompanyCardsEnabled ?? false;
const areAnyCardsEnabled = !!policy?.areCompanyCardsEnabled || !!policy?.areExpensifyCardsEnabled;
const isRequireCompanyCardsLocked = !canWriteRules || isCollect || !areAnyCardsEnabled;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is the isCollect true? Do we need to change this based on the rules beta? (where rules are enabled for more than just control plans?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

More of a product question.

This is already consistent with other switches

Screen.Recording.2026-09-03.at.4.22.34.PM.mov

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

isCollect is only reachable because of the revamp beta, canPolicyAccessFeature gates Rules to Control unless it's on. Pre-revamp Collect couldn't open the Rules page, so no Collect workspace has this on today and the lock costs nothing. Same treatment as eReceipts and attendee tracking.

cc: @JmillsExpensify

@JmillsExpensify JmillsExpensify Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed. Let's lock this on Collect and make it an upgrade path.

const shouldExplainMissingCards = canWriteRules && !isCollect && !areAnyCardsEnabled;

useEffect(() => {
// The subtitle names the required tag lists, and only the Tags pages fetch them, so it would otherwise read
// stale until Tags is opened. This section mounts only while the General tab is active.
Expand Down Expand Up @@ -261,6 +282,20 @@ function IndividualExpenseRulesSectionRevamp({policyID, canWriteRules}: Individu
{renderMenuItems(policyControlItems)}
<View style={[styles.sectionDividerLine, styles.mv3]} />
{renderMenuItems(productDefaultItems)}
<ToggleSettingOptionRow
title={translate('workspace.rules.individualExpenseRules.requireCompanyCard')}
subtitle={translate('workspace.rules.individualExpenseRules.requireCompanyCardDescription')}
switchAccessibilityLabel={translate('workspace.rules.individualExpenseRules.requireCompanyCard')}
wrapperStyle={[styles.pv3]}
isActive={requireCompanyCardsEnabled}
disabled={isRequireCompanyCardsLocked}
showLockIcon={isRequireCompanyCardsLocked}
disabledText={shouldExplainMissingCards ? translate('workspace.rules.individualExpenseRules.requireCompanyCardDisabledTooltip') : undefined}
disabledAction={withReadOnlyFallback(isCollect ? navigateToRulesControlUpgrade : undefined)}
onToggle={() => (canWriteRules && policy ? setPolicyRequireCompanyCardsEnabled(policy, !requireCompanyCardsEnabled) : undefined)}
pendingAction={policy?.pendingFields?.requireCompanyCardsEnabled}
rowIcon={icons.CreditCard}
/>
<ToggleSettingOptionRow
title={translate('workspace.rules.individualExpenseRules.eReceipts')}
subtitle={translate('workspace.rules.individualExpenseRules.eReceiptsHint')}
Expand All @@ -270,7 +305,7 @@ function IndividualExpenseRulesSectionRevamp({policyID, canWriteRules}: Individu
isActive={areEReceiptsEnabled}
disabled={!canWriteRules || policyCurrency !== CONST.CURRENCY.USD || isCollect}
showLockIcon={!canWriteRules || policyCurrency !== CONST.CURRENCY.USD || isCollect}
disabledAction={isCollect && canWriteRules ? navigateToRulesControlUpgrade : undefined}
disabledAction={withReadOnlyFallback(isCollect ? navigateToRulesControlUpgrade : undefined)}
onToggle={() => (canWriteRules ? setWorkspaceEReceiptsEnabled(policyID, !areEReceiptsEnabled, policy?.eReceipts) : undefined)}
pendingAction={policy?.pendingFields?.eReceipts}
rowIcon={icons.Receipt}
Expand All @@ -283,14 +318,15 @@ function IndividualExpenseRulesSectionRevamp({policyID, canWriteRules}: Individu
isActive={isAttendeeTrackingEnabledForPolicy}
disabled={!canWriteRules || isCollect}
showLockIcon={!canWriteRules || isCollect}
disabledAction={isCollect && canWriteRules ? navigateToRulesControlUpgrade : undefined}
disabledAction={withReadOnlyFallback(isCollect ? navigateToRulesControlUpgrade : undefined)}
onToggle={() => (canWriteRules ? handleAttendeeTrackingToggle(!isAttendeeTrackingEnabledForPolicy) : undefined)}
pendingAction={policy?.pendingFields?.isAttendeeTrackingEnabled}
rowIcon={icons.Users}
/>
<PublicReceiptVisibilityToggle
policyID={policyID}
canWriteRules={canWriteRules}
withReadOnlyFallback={withReadOnlyFallback}
rowIcon={icons.Eye}
/>
</View>
Expand Down
Loading