Repository navigation
feat: add require company cards toggle to rules revamp #100241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3df269a
a71de4c
8c681a0
f654498
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'; | ||
|
|
@@ -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); | ||
| 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; | ||
|
|
||
|
|
@@ -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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
cc: @JmillsExpensify
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
|
@@ -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')} | ||
|
|
@@ -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} | ||
|
|
@@ -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> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.
eReceiptsused this condition:disabledAction={isCollect && canWriteRules ? navigateToRulesControlUpgrade : undefined}There was a problem hiding this comment.
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(), andPublicReceiptVisibilityToggletook 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.