Skip to content

Commit 7ca98c9

Browse files
authored
Merge pull request #98056 from Krishna2323/krishna2323/issue-98040-global-more-option
Show the More option on every Rules tab
2 parents cb2e17a + 65e1ba2 commit 7ca98c9

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

src/pages/workspace/rules/MerchantRules/ImportedMerchantRulesPage.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import useImportSpreadsheetConfirmModal from '@hooks/useImportSpreadsheetConfirm
88
import useLocalize from '@hooks/useLocalize';
99
import useNetwork from '@hooks/useNetwork';
1010
import useOnyx from '@hooks/useOnyx';
11+
import usePermissions from '@hooks/usePermissions';
1112
import usePolicy from '@hooks/usePolicy';
1213

1314
import {openPolicyCategoriesPage} from '@libs/actions/Policy/Category';
1415
import type {ImportedMerchantRule} from '@libs/actions/Policy/Rules';
1516
import {importMerchantRulesSpreadsheet} from '@libs/actions/Policy/Rules';
17+
import Tab from '@libs/actions/Tab';
1618
import {getDecodedCategoryName} from '@libs/CategoryUtils';
1719
import {findDuplicate, generateColumnNames} from '@libs/importSpreadsheetUtils';
1820
import Navigation from '@libs/Navigation/Navigation';
@@ -133,6 +135,8 @@ function ImportedMerchantRulesPage({route}: ImportedMerchantRulesPageProps) {
133135
const policyID = route.params.policyID;
134136
const policy = usePolicy(policyID);
135137
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`);
138+
const {isBetaEnabled} = usePermissions();
139+
const isRulesRevampEnabled = isBetaEnabled(CONST.BETAS.RULES_REVAMP);
136140

137141
// Fetch categories if they're not loaded (e.g. after a cache clear) so imported category cells are
138142
// validated against the policy's real category list instead of an empty one
@@ -193,6 +197,10 @@ function ImportedMerchantRulesPage({route}: ImportedMerchantRulesPageProps) {
193197
const closeImportPageAndModal = () => {
194198
setIsClosing(true);
195199
setIsImportingRules(false);
200+
if (isRulesRevampEnabled) {
201+
// Import can start from any tab, so land on the one holding the imported rules.
202+
Tab.setSelectedTab(CONST.TAB.RULES_TAB_TYPE, CONST.TAB.RULES.EXPENSE_DEFAULTS);
203+
}
196204
Navigation.goBack(ROUTES.WORKSPACE_RULES.getRoute(policyID));
197205
};
198206

src/pages/workspace/rules/PolicyRulesPageRevamp.tsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -291,21 +291,16 @@ function PolicyRulesPageRevamp({route}: PolicyRulesPageRevampProps) {
291291
return null;
292292
}
293293

294-
if (activeTab !== RULES_TAB.EXPENSE_DEFAULTS) {
295-
return (
296-
<Button
297-
variant={CONST.BUTTON_VARIANT.SUCCESS}
298-
onPress={handleNewRule}
299-
style={[shouldDisplayButtonsInSeparateLine && styles.w100]}
300-
>
301-
<Button.Icon src={icons.Plus} />
302-
<Button.Text>{translate('workspace.rules.merchantRules.addRuleTitle')}</Button.Text>
303-
</Button>
304-
);
305-
}
306-
307294
const moreOptions: Array<DropdownOption<DeepValueOf<typeof CONST.POLICY.SECONDARY_ACTIONS>>> = [
308-
getImportMerchantRulesOption({policyID, canWriteRules, showReadOnlyModal, translate, icon: icons.Table}),
295+
getImportMerchantRulesOption({
296+
policyID,
297+
canWriteRules,
298+
showReadOnlyModal,
299+
translate,
300+
icon: icons.Table,
301+
// Collect sees More on General, so gate it like New rule. backTo only applies after a successful upgrade.
302+
tryNavigateToUpgrade: () => tryNavigateToControlPolicyUpgrade(policy, rulesUpgradeAlias, ROUTES.RULES_MERCHANT_IMPORT.getRoute(policyID)),
303+
}),
309304
];
310305

311306
return (

src/pages/workspace/rules/getImportMerchantRulesOption.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ type ImportMerchantRulesOptionParams = {
2323

2424
/** Icon shown next to the option */
2525
icon: IconAsset;
26+
27+
/** Sends plans without merchant rules to the upgrade flow. Returns true when it navigated. */
28+
tryNavigateToUpgrade?: () => boolean;
2629
};
2730

2831
/**
@@ -35,6 +38,7 @@ function getImportMerchantRulesOption({
3538
showReadOnlyModal,
3639
translate,
3740
icon,
41+
tryNavigateToUpgrade,
3842
}: ImportMerchantRulesOptionParams): DropdownOption<DeepValueOf<typeof CONST.POLICY.SECONDARY_ACTIONS>> {
3943
return {
4044
icon,
@@ -45,6 +49,9 @@ function getImportMerchantRulesOption({
4549
showReadOnlyModal();
4650
return;
4751
}
52+
if (tryNavigateToUpgrade?.()) {
53+
return;
54+
}
4855
Navigation.navigate(ROUTES.RULES_MERCHANT_IMPORT.getRoute(policyID));
4956
},
5057
};

0 commit comments

Comments
 (0)