Skip to content
Merged
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 @@ -8,11 +8,13 @@ import useImportSpreadsheetConfirmModal from '@hooks/useImportSpreadsheetConfirm
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import usePermissions from '@hooks/usePermissions';
import usePolicy from '@hooks/usePolicy';

import {openPolicyCategoriesPage} from '@libs/actions/Policy/Category';
import type {ImportedMerchantRule} from '@libs/actions/Policy/Rules';
import {importMerchantRulesSpreadsheet} from '@libs/actions/Policy/Rules';
import Tab from '@libs/actions/Tab';
import {getDecodedCategoryName} from '@libs/CategoryUtils';
import {findDuplicate, generateColumnNames} from '@libs/importSpreadsheetUtils';
import Navigation from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -133,6 +135,8 @@ function ImportedMerchantRulesPage({route}: ImportedMerchantRulesPageProps) {
const policyID = route.params.policyID;
const policy = usePolicy(policyID);
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`);
const {isBetaEnabled} = usePermissions();
const isRulesRevampEnabled = isBetaEnabled(CONST.BETAS.RULES_REVAMP);

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

Expand Down
23 changes: 9 additions & 14 deletions src/pages/workspace/rules/PolicyRulesPageRevamp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,21 +291,16 @@ function PolicyRulesPageRevamp({route}: PolicyRulesPageRevampProps) {
return null;
}

if (activeTab !== RULES_TAB.EXPENSE_DEFAULTS) {
return (
<Button
variant={CONST.BUTTON_VARIANT.SUCCESS}
onPress={handleNewRule}
style={[shouldDisplayButtonsInSeparateLine && styles.w100]}
>
<Button.Icon src={icons.Plus} />
<Button.Text>{translate('workspace.rules.merchantRules.addRuleTitle')}</Button.Text>
</Button>
);
}

const moreOptions: Array<DropdownOption<DeepValueOf<typeof CONST.POLICY.SECONDARY_ACTIONS>>> = [
getImportMerchantRulesOption({policyID, canWriteRules, showReadOnlyModal, translate, icon: icons.Table}),
getImportMerchantRulesOption({
policyID,
canWriteRules,
showReadOnlyModal,
translate,
icon: icons.Table,
// Collect sees More on General, so gate it like New rule. backTo only applies after a successful upgrade.
tryNavigateToUpgrade: () => tryNavigateToControlPolicyUpgrade(policy, rulesUpgradeAlias, ROUTES.RULES_MERCHANT_IMPORT.getRoute(policyID)),
}),
];

return (
Expand Down
7 changes: 7 additions & 0 deletions src/pages/workspace/rules/getImportMerchantRulesOption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type ImportMerchantRulesOptionParams = {

/** Icon shown next to the option */
icon: IconAsset;

/** Sends plans without merchant rules to the upgrade flow. Returns true when it navigated. */
tryNavigateToUpgrade?: () => boolean;
};

/**
Expand All @@ -35,6 +38,7 @@ function getImportMerchantRulesOption({
showReadOnlyModal,
translate,
icon,
tryNavigateToUpgrade,
}: ImportMerchantRulesOptionParams): DropdownOption<DeepValueOf<typeof CONST.POLICY.SECONDARY_ACTIONS>> {
return {
icon,
Expand All @@ -45,6 +49,9 @@ function getImportMerchantRulesOption({
showReadOnlyModal();
return;
}
if (tryNavigateToUpgrade?.()) {
return;
}
Navigation.navigate(ROUTES.RULES_MERCHANT_IMPORT.getRoute(policyID));
},
};
Expand Down
Loading