Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
a0076bb
Support multiple conditions on an expense default rule
Krishna2323 Oct 15, 2026
f707380
Fix the condition text, validation and duplicate prompt for multi-con…
Krishna2323 Oct 15, 2026
6bbcb67
Support category, tag and amount in expense default rules
Krishna2323 Oct 15, 2026
6668c23
Follow the existing picker patterns for the new rule condition and am…
Krishna2323 Oct 15, 2026
1c24c39
Require a tag before offering the tag condition
Krishna2323 Oct 15, 2026
f92c9e2
Require a tag before offering the tag condition
Krishna2323 Oct 15, 2026
f8b9603
Gate the category condition row on a category to match
Krishna2323 Oct 15, 2026
0634260
Keep a deleted category or tag listed in the condition pickers
Krishna2323 Oct 15, 2026
4c2cd5b
remove unused translations keys.
Krishna2323 Oct 15, 2026
5289f2f
Remove dead exports left by the category tax default deletion
Krishna2323 Oct 15, 2026
5cee48a
Preview every condition, and rename the merchant-only rule API
Krishna2323 Oct 15, 2026
d7fdd05
fix knip check.
Krishna2323 Oct 15, 2026
34f595f
Merge remote-tracking branch 'upstream/main' into krishna2323/issue-1…
Krishna2323 Oct 19, 2026
82e33fc
update translations.
Krishna2323 Oct 19, 2026
00eb6e9
Merge remote-tracking branch 'upstream/main' into krishna2323/issue-1…
Krishna2323 Oct 20, 2026
b972724
Fix the category settings expense default flow
Krishna2323 Oct 20, 2026
e13a245
Open a rule that also fires when an expense is edited
Krishna2323 Oct 20, 2026
27db57e
Rewrite a renamed category inside the rules that match on it
Krishna2323 Oct 20, 2026
66f63ad
Pass the coding rules through the inline category rename in tests
Krishna2323 Oct 20, 2026
c483c29
Merge remote-tracking branch 'upstream/main' into krishna2323/issue-1…
Krishna2323 Oct 20, 2026
10be6f0
Merge remote-tracking branch 'upstream/main' into krishna2323/issue-1…
Krishna2323 Oct 21, 2026
468f4b9
Stop rewriting a renamed category inside the rules that match on it
Krishna2323 Oct 21, 2026
7bdbc49
Tell a contains rule apart from an exact match in the rules table
Krishna2323 Oct 21, 2026
a3c1518
Keep the rule being edited when picking a category
Krishna2323 Oct 22, 2026
1e9243e
Stop offering a rule that is being deleted
Krishna2323 Oct 22, 2026
483a907
Compare every condition when skipping imported duplicates
Krishna2323 Oct 22, 2026
11041f9
Merge branch 'main' into krishna2323/issue-102277-expense-defaults
Krishna2323 Oct 22, 2026
d0d4d6b
Translate the new merchant condition strings
Krishna2323 Oct 22, 2026
55333e5
Stop predicting a category's tax on the client
Krishna2323 Oct 22, 2026
eca47ee
Merge branch 'main' into krishna2323/issue-102277-expense-defaults
Krishna2323 Oct 27, 2026
5812fe3
Fix the category rule lookup and clear the review's dead code
Krishna2323 Oct 27, 2026
18ce3d9
Show every expense default a category has
Krishna2323 Oct 27, 2026
2e7be52
Keep category settings to the category's own rule
Krishna2323 Oct 27, 2026
21e336f
Address a category's rule by ID so settings can list them all
Krishna2323 Oct 27, 2026
99ca6c0
Create a rule from a category the way the Rules page does
Krishna2323 Oct 27, 2026
ec81311
List a rule on every category it matches on its own
Krishna2323 Oct 27, 2026
aeb2001
Let a described rule use a category that already has one
Krishna2323 Oct 27, 2026
48f1ff2
List any rule matching a category on its page
Krishna2323 Oct 27, 2026
947b628
Merge branch 'Expensify:main' into krishna2323/issue-102277-expense-d…
Krishna2323 Oct 27, 2026
3dd7627
Merge branch 'main' into krishna2323/issue-102277-expense-defaults
Krishna2323 Oct 28, 2026
d0321a8
Apply Polyglot Parrot translations for the expense defaults copy
Krishna2323 Oct 28, 2026
7a9be64
Give tag-only rules their own section and show rule conditions in cat…
Krishna2323 Oct 29, 2026
e699e67
Add the Tags section translations
Krishna2323 Oct 29, 2026
32208ad
Merge remote-tracking branch 'upstream/main' into krishna2323/issue-1…
Krishna2323 Oct 30, 2026
e0b3e66
Reset the expense default draft when opening a new rule
Krishna2323 Oct 30, 2026
e388cdf
Drop a stale JSDoc above getCategoryExpenseDefaultRules
Krishna2323 Oct 30, 2026
fcba229
List a multi-condition expense default under its own section
Krishna2323 Oct 30, 2026
c832105
update translations.
Krishna2323 Oct 30, 2026
6f69db2
Resolve a category's tax default from the rules collection
Krishna2323 Nov 1, 2026
07ce9a8
Apply a category's tax rule when the category changes
Krishna2323 Nov 2, 2026
7c9aa63
Fix the useTaxAmount tests for the rules collection lookup
Krishna2323 Nov 2, 2026
c1578fc
Keep a category change pending until the rules can resolve it
Krishna2323 Nov 2, 2026
72c9267
Resolve a split's category tax from the rules collection
Krishna2323 Nov 2, 2026
9a6a6b6
Carry an expense default through a category rename
Krishna2323 Nov 2, 2026
4d20fd6
Treat a timed out rules fetch as an attempt made
Krishna2323 Nov 2, 2026
3cb9aef
Keep expense defaults resolving through tax code and operator changes
Krishna2323 Nov 2, 2026
249b3f9
Apply a category rule to every category it names
Krishna2323 Nov 2, 2026
eddc788
Reset a split's tax when its new category has no rule
Krishna2323 Nov 2, 2026
c7f2024
Fix the inline rename test for the rules collection argument
Krishna2323 Nov 2, 2026
b9434ba
Leave a stale expense default rule stale
Krishna2323 Nov 2, 2026
f3992ae
Reset a split's tax only for a rule the category owns
Krishna2323 Nov 2, 2026
3c1a2a8
Merge remote-tracking branch 'upstream/main' into krishna2323/issue-1…
Krishna2323 Nov 2, 2026
dddf358
Complete the workspace review task when an expense default is saved
Krishna2323 Nov 2, 2026
5300cc2
Keep a saved default's row visible when its feature is off
Krishna2323 Nov 2, 2026
6706583
Label the copied rules as expense defaults
Krishna2323 Nov 2, 2026
cdeaa40
Keep a rule listed while its category is being deleted
Krishna2323 Nov 2, 2026
a632dc8
Stop the vendor default opening a page that cannot load
Krishna2323 Nov 2, 2026
5604af4
update translations.
Krishna2323 Nov 2, 2026
27413d1
Address review on the expense default rule helpers
Krishna2323 Nov 2, 2026
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
4 changes: 2 additions & 2 deletions config/oxlint/oxlint.seatbelt.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -2026,10 +2026,10 @@
"../../src/pages/workspace/rules/FlagForReviewRules/FlagForReviewRulePageBase.tsx" "@typescript-eslint/no-deprecated/MenuItemWithTopDescription" 1
"../../src/pages/workspace/rules/IndividualExpenseRulesSectionRevamp.tsx" "@typescript-eslint/no-deprecated/MenuItem" 1
"../../src/pages/workspace/rules/MerchantRules/AddMerchantRulePage.tsx" "rulesdir/no-onyx-loading-status" 1
"../../src/pages/workspace/rules/MerchantRules/ExpenseDefaultRulePageBase.tsx" "@typescript-eslint/no-deprecated/MenuItemWithTopDescription" 1
"../../src/pages/workspace/rules/MerchantRules/ExpenseDefaultRulePageBase.tsx" "rulesdir/no-onyx-loading-status" 1
"../../src/pages/workspace/rules/MerchantRules/ExpenseDefaultTypePage.tsx" "@typescript-eslint/no-deprecated/MenuItem" 1
"../../src/pages/workspace/rules/MerchantRules/ImportedMerchantRulesPage.tsx" "rulesdir/no-onyx-loading-status" 1
"../../src/pages/workspace/rules/MerchantRules/MerchantRulePageBase.tsx" "@typescript-eslint/no-deprecated/MenuItemWithTopDescription" 1
"../../src/pages/workspace/rules/MerchantRules/MerchantRulePageBase.tsx" "rulesdir/no-onyx-loading-status" 1
"../../src/pages/workspace/rules/MerchantTypeRules/MerchantTypeRulePageBase.tsx" "@typescript-eslint/no-deprecated/MenuItemWithTopDescription" 1
"../../src/pages/workspace/rules/RulesNewPage.tsx" "@typescript-eslint/no-deprecated/MenuItem" 1
"../../src/pages/workspace/rules/SpendRules/SpendRulePageBase.tsx" "@typescript-eslint/no-deprecated/MenuItemWithTopDescription" 1
Expand Down
9 changes: 4 additions & 5 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5057,14 +5057,11 @@ const CONST = {
/** Subsections of the Rules > Expense defaults table, listed in the order they render. */
EXPENSE_DEFAULTS_SECTION: {
CATEGORIES: 'categories',
TAGS: 'tags',
MERCHANTS: 'merchants',
MULTIPLE_CONDITIONS: 'multipleConditions',
MERCHANT_TYPES: 'merchantTypes',
},
/** What an expense default rule matches on, chosen before the editor opens and kept in its draft. */
EXPENSE_DEFAULT_RULE_TYPE: {
MERCHANT: 'merchant',
CATEGORY: 'category',
},
DEFAULT_REPORT_NAME_PATTERN: '{report:type} {report:startdate}',
DEFAULT_FIELD_LIST_TYPE: 'formula',
DEFAULT_FIELD_LIST_TARGET: 'expense',
Expand Down Expand Up @@ -9618,6 +9615,7 @@ const CONST = {
EXPENSE_DEFAULT: {
/** Expense fields a `Set` action can write to */
FIELD: {
AMOUNT: 'amount',
BILLABLE: 'billable',
CATEGORY: 'category',
COMMENT: 'comment',
Expand Down Expand Up @@ -10876,6 +10874,7 @@ const CONST = {
INDIVIDUAL_EXPENSES_MENU_ITEM: 'WorkspaceRules-IndividualExpensesMenuItem',
SPEND_RULE_ITEM: 'WorkspaceRules-SpendRuleItem',
MERCHANT_RULE_ITEM: 'WorkspaceRules-MerchantRuleItem',
TAG_RULE_ITEM: 'WorkspaceRules-TagRuleItem',
REQUIRE_FIELDS_RULE_ITEM: 'WorkspaceRules-RequireFieldsRuleItem',
REQUIRE_FIELDS_RULE_SAVE: 'WorkspaceRules-RequireFieldsRuleSave',
REQUIRE_FIELDS_RULE_DESCRIBE: 'WorkspaceRules-RequireFieldsRuleDescribe',
Expand Down
72 changes: 43 additions & 29 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ const ENABLE_GLOBAL_REIMBURSEMENTS_ENTRY_SCREENS = [
SCREENS.WORKSPACE.WORKFLOWS,
] as const;

// Every step of the expense default editor is reachable from the workspace Rules flow and from category settings,
// which enters through its own dynamic route, so each step has to accept both as an entry.
const EXPENSE_DEFAULT_RULE_STEP_ENTRY_SCREENS = [
SCREENS.WORKSPACE.DYNAMIC_RULES_MERCHANT_NEW,
SCREENS.WORKSPACE.DYNAMIC_CATEGORY_TAX_RULE_NEW,
SCREENS.WORKSPACE.DYNAMIC_CATEGORY_TAX_RULE_EDIT,
] as const;

const DYNAMIC_ROUTES = {
VERIFY_ACCOUNT: {
path: 'verify-account',
Expand Down Expand Up @@ -1105,10 +1113,6 @@ const DYNAMIC_ROUTES = {
path: 'gl-code',
entryScreens: [SCREENS.WORKSPACE.DYNAMIC_CATEGORY_SETTINGS],
},
WORKSPACE_CATEGORY_DEFAULT_TAX_RATE: {
path: 'tax-rate',
entryScreens: [SCREENS.WORKSPACE.DYNAMIC_CATEGORY_SETTINGS, SCREENS.SETTINGS_CATEGORIES.DYNAMIC_SETTINGS_CATEGORY_SETTINGS],
},
WORKSPACE_CATEGORY_FLAG_AMOUNTS_OVER: {
path: 'flag-amounts',
entryScreens: [SCREENS.WORKSPACE.DYNAMIC_CATEGORY_SETTINGS, SCREENS.SETTINGS_CATEGORIES.DYNAMIC_SETTINGS_CATEGORY_SETTINGS],
Expand Down Expand Up @@ -1162,8 +1166,11 @@ const DYNAMIC_ROUTES = {
entryScreens: [SCREENS.WORKSPACE.DYNAMIC_CATEGORY_RULES_NEW],
},
WORKSPACE_CATEGORY_RULES_TAX_EDIT: {
path: 'rules/tax',
// A category can hold more than one rule, so the row carries the rule it opens rather than letting the
// category name stand in for it.
path: 'rules/tax/:ruleID',
entryScreens: [SCREENS.WORKSPACE.DYNAMIC_CATEGORY_SETTINGS, SCREENS.SETTINGS_CATEGORIES.DYNAMIC_SETTINGS_CATEGORY_SETTINGS],
getRoute: (ruleID: string) => `rules/tax/${ruleID}` as const,
},
RULES_MERCHANT_NEW_FROM_EXPENSE: {
path: 'merchant-rule/new',
Expand All @@ -1173,48 +1180,60 @@ const DYNAMIC_ROUTES = {
},
RULES_MERCHANT_MERCHANT_TO_MATCH_FROM_EXPENSE: {
path: 'rule-merchant-to-match',
entryScreens: [SCREENS.WORKSPACE.DYNAMIC_RULES_MERCHANT_NEW],
entryScreens: EXPENSE_DEFAULT_RULE_STEP_ENTRY_SCREENS,
},
RULES_MERCHANT_MATCH_TYPE_FROM_EXPENSE: {
path: 'rule-match-type',
entryScreens: [SCREENS.WORKSPACE.DYNAMIC_RULES_MERCHANT_MERCHANT_TO_MATCH],
},
RULES_MERCHANT_MERCHANT_FROM_EXPENSE: {
path: 'rule-merchant',
entryScreens: [SCREENS.WORKSPACE.DYNAMIC_RULES_MERCHANT_NEW],
entryScreens: EXPENSE_DEFAULT_RULE_STEP_ENTRY_SCREENS,
},
RULES_MERCHANT_CATEGORY_FROM_EXPENSE: {
path: 'rule-category',
entryScreens: [SCREENS.WORKSPACE.DYNAMIC_RULES_MERCHANT_NEW],
entryScreens: EXPENSE_DEFAULT_RULE_STEP_ENTRY_SCREENS,
},
RULES_MERCHANT_TAG_FROM_EXPENSE: {
path: 'rule-tag/:orderWeight',
entryScreens: [SCREENS.WORKSPACE.DYNAMIC_RULES_MERCHANT_NEW],
entryScreens: EXPENSE_DEFAULT_RULE_STEP_ENTRY_SCREENS,
getRoute: (orderWeight: number) => `rule-tag/${orderWeight}` as const,
},
RULES_MERCHANT_TAX_FROM_EXPENSE: {
path: 'rule-tax',
entryScreens: [SCREENS.WORKSPACE.DYNAMIC_RULES_MERCHANT_NEW, SCREENS.WORKSPACE.DYNAMIC_CATEGORY_TAX_RULE_NEW, SCREENS.WORKSPACE.DYNAMIC_CATEGORY_TAX_RULE_EDIT],
entryScreens: EXPENSE_DEFAULT_RULE_STEP_ENTRY_SCREENS,
},
RULES_MERCHANT_VENDOR_FROM_EXPENSE: {
path: 'rule-vendor',
entryScreens: [SCREENS.WORKSPACE.DYNAMIC_RULES_MERCHANT_NEW],
entryScreens: EXPENSE_DEFAULT_RULE_STEP_ENTRY_SCREENS,
},
RULES_MERCHANT_DESCRIPTION_FROM_EXPENSE: {
path: 'rule-description',
entryScreens: [SCREENS.WORKSPACE.DYNAMIC_RULES_MERCHANT_NEW],
entryScreens: EXPENSE_DEFAULT_RULE_STEP_ENTRY_SCREENS,
},
RULES_MERCHANT_REIMBURSABLE_FROM_EXPENSE: {
path: 'rule-reimbursable',
entryScreens: [SCREENS.WORKSPACE.DYNAMIC_RULES_MERCHANT_NEW],
entryScreens: EXPENSE_DEFAULT_RULE_STEP_ENTRY_SCREENS,
},
RULES_MERCHANT_BILLABLE_FROM_EXPENSE: {
path: 'rule-billable',
entryScreens: [SCREENS.WORKSPACE.DYNAMIC_RULES_MERCHANT_NEW],
entryScreens: EXPENSE_DEFAULT_RULE_STEP_ENTRY_SCREENS,
},
RULES_MERCHANT_AMOUNT_FROM_EXPENSE: {
path: 'rule-amount',
entryScreens: EXPENSE_DEFAULT_RULE_STEP_ENTRY_SCREENS,
},
RULES_CATEGORY_TO_MATCH_FROM_EXPENSE: {
path: 'rule-category-to-match',
entryScreens: EXPENSE_DEFAULT_RULE_STEP_ENTRY_SCREENS,
},
RULES_TAG_TO_MATCH_FROM_EXPENSE: {
path: 'rule-tag-to-match',
entryScreens: EXPENSE_DEFAULT_RULE_STEP_ENTRY_SCREENS,
},
RULES_MERCHANT_PREVIEW_MATCHES_FROM_EXPENSE: {
path: 'rule-matches',
entryScreens: [SCREENS.WORKSPACE.DYNAMIC_RULES_MERCHANT_NEW],
entryScreens: EXPENSE_DEFAULT_RULE_STEP_ENTRY_SCREENS,
},
NOTIFICATION_PREFERENCES: {
// `reportID` is intentionally carried as a distinct path param (`notificationReportID`) rather than
Expand Down Expand Up @@ -4481,10 +4500,6 @@ const ROUTES = {
route: 'workspaces/:policyID/rules/new',
getRoute: (policyID: string, categoryName?: string) => `workspaces/${policyID}/rules/new${getOptionalCategoryNameQuery(categoryName)}` as const,
},
RULES_EXPENSE_DEFAULT_TYPE: {
route: 'workspaces/:policyID/rules/expense-defaults/new',
getRoute: (policyID: string) => `workspaces/${policyID}/rules/expense-defaults/new` as const,
},
RULES_MERCHANT_NEW: {
route: 'workspaces/:policyID/rules/merchant-rules/new',
getRoute: (policyID: string, categoryName?: string) => `workspaces/${policyID}/rules/merchant-rules/new${getOptionalCategoryNameQuery(categoryName)}` as const,
Expand Down Expand Up @@ -4551,10 +4566,7 @@ const ROUTES = {
},
RULES_MERCHANT_TAX: {
route: 'workspaces/:policyID/rules/merchant-rules/:ruleID/tax',
// `categoryName` is set when editing a category tax default, which is identified by its category rather than a
// ruleID. It tells the picker to return to that editor instead of the create page.
getRoute: (policyID: string, ruleID?: string, categoryName?: string) =>
`workspaces/${policyID}/rules/merchant-rules/${ruleID ?? 'new'}/tax${getOptionalCategoryNameQuery(categoryName)}` as const,
getRoute: (policyID: string, ruleID?: string) => `workspaces/${policyID}/rules/merchant-rules/${ruleID ?? 'new'}/tax` as const,
},
RULES_MERCHANT_VENDOR: {
route: 'workspaces/:policyID/rules/merchant-rules/:ruleID/vendor',
Expand All @@ -4572,6 +4584,10 @@ const ROUTES = {
route: 'workspaces/:policyID/rules/merchant-rules/:ruleID/billable',
getRoute: (policyID: string, ruleID?: string) => `workspaces/${policyID}/rules/merchant-rules/${ruleID ?? 'new'}/billable` as const,
},
RULES_MERCHANT_AMOUNT: {
route: 'workspaces/:policyID/rules/merchant-rules/:ruleID/amount',
getRoute: (policyID: string, ruleID?: string) => `workspaces/${policyID}/rules/merchant-rules/${ruleID ?? 'new'}/amount` as const,
},
RULES_MERCHANT_EDIT: {
route: 'workspaces/:policyID/rules/merchant-rules/:ruleID',
getRoute: (policyID: string, ruleID: string) => `workspaces/${policyID}/rules/merchant-rules/${ruleID}` as const,
Expand All @@ -4582,13 +4598,11 @@ const ROUTES = {
},
RULES_CATEGORY_TO_MATCH: {
route: 'workspaces/:policyID/rules/merchant-rules/:ruleID/category-to-match',
// A category tax default has no ruleID, so editing one passes its category for the way back.
getRoute: (policyID: string, ruleID?: string, categoryName?: string) =>
`workspaces/${policyID}/rules/merchant-rules/${ruleID ?? 'new'}/category-to-match${getOptionalCategoryNameQuery(categoryName)}` as const,
getRoute: (policyID: string, ruleID?: string) => `workspaces/${policyID}/rules/merchant-rules/${ruleID ?? 'new'}/category-to-match` as const,
},
RULES_CATEGORY_TAX_EDIT: {
route: 'workspaces/:policyID/rules/category-tax-rules/edit/:categoryName',
getRoute: (policyID: string, categoryName: string) => `workspaces/${policyID}/rules/category-tax-rules/edit/${encodeURIComponent(categoryName)}` as const,
RULES_TAG_TO_MATCH: {
route: 'workspaces/:policyID/rules/merchant-rules/:ruleID/tag-to-match',
getRoute: (policyID: string, ruleID?: string) => `workspaces/${policyID}/rules/merchant-rules/${ruleID ?? 'new'}/tag-to-match` as const,
},
RULES_AGENT_NEW: {
route: 'workspaces/:policyID/rules/agent-rules/new',
Expand Down
8 changes: 5 additions & 3 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,6 @@ const SCREENS = {
DYNAMIC_CATEGORY_PAYROLL_CODE: 'Dynamic_Category_Payroll_Code',
DYNAMIC_CATEGORY_GL_CODE: 'Dynamic_Category_GL_Code',
DYNAMIC_CATEGORY_SETTINGS: 'Dynamic_Category_Settings',
DYNAMIC_CATEGORY_DEFAULT_TAX_RATE: 'Dynamic_Category_Default_Tax_Rate',
DYNAMIC_CATEGORY_FLAG_AMOUNTS_OVER: 'Dynamic_Category_Flag_Amounts_Over',
DYNAMIC_EXPENSE_LIMIT_TYPE_SELECTOR: 'Dynamic_Expense_Limit_Type_Selector',
DYNAMIC_IMPORTED_MEMBERS_ROLE: 'Dynamic_Imported_Members_Role',
Expand Down Expand Up @@ -1049,7 +1048,6 @@ const SCREENS = {
RULES_CUSTOM: 'Rules_Custom',
RULES_PROHIBITED_DEFAULT: 'Rules_Prohibited_Default',
RULES_NEW: 'Rules_New',
RULES_EXPENSE_DEFAULT_TYPE: 'Rules_Expense_Default_Type',
RULES_MERCHANT_NEW: 'Rules_Merchant_New',
RULES_MERCHANT_IMPORT: 'Rules_Merchant_Import',
RULES_MERCHANT_IMPORTED: 'Rules_Merchant_Imported',
Expand Down Expand Up @@ -1083,9 +1081,10 @@ const SCREENS = {
RULES_MERCHANT_DESCRIPTION: 'Rules_Merchant_Description',
RULES_MERCHANT_REIMBURSABLE: 'Rules_Merchant_Reimbursable',
RULES_MERCHANT_BILLABLE: 'Rules_Merchant_Billable',
RULES_MERCHANT_AMOUNT: 'Rules_Merchant_Amount',
RULES_MERCHANT_PREVIEW_MATCHES: 'Rules_Merchant_Preview_Matches',
RULES_CATEGORY_TO_MATCH: 'Rules_Category_To_Match',
RULES_CATEGORY_TAX_EDIT: 'Rules_Category_Tax_Edit',
RULES_TAG_TO_MATCH: 'Rules_Tag_To_Match',
RULES_MERCHANT_EDIT: 'Rules_Merchant_Edit',
DYNAMIC_RULES_MERCHANT_NEW: 'Dynamic_Rules_Merchant_New',
DYNAMIC_RULES_MERCHANT_MERCHANT_TO_MATCH: 'Dynamic_Rules_Merchant_Merchant_To_Match',
Expand All @@ -1098,6 +1097,9 @@ const SCREENS = {
DYNAMIC_RULES_MERCHANT_DESCRIPTION: 'Dynamic_Rules_Merchant_Description',
DYNAMIC_RULES_MERCHANT_REIMBURSABLE: 'Dynamic_Rules_Merchant_Reimbursable',
DYNAMIC_RULES_MERCHANT_BILLABLE: 'Dynamic_Rules_Merchant_Billable',
DYNAMIC_RULES_MERCHANT_AMOUNT: 'Dynamic_Rules_Merchant_Amount',
DYNAMIC_RULES_CATEGORY_TO_MATCH: 'Dynamic_Rules_Category_To_Match',
DYNAMIC_RULES_TAG_TO_MATCH: 'Dynamic_Rules_Tag_To_Match',
DYNAMIC_RULES_MERCHANT_PREVIEW_MATCHES: 'Dynamic_Rules_Merchant_Preview_Matches',
RULES_SPEND_MERCHANTS: 'Rules_Spend_Merchants',
RULES_SPEND_MERCHANT_EDIT: 'Rules_Spend_Merchant_Edit',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {useCurrencyListActions} from '@hooks/useCurrencyList';

import {setMoneyRequestCategory, setMoneyRequestTag} from '@libs/actions/IOU/MoneyRequest';
import {insertTagIntoTransactionTagsString} from '@libs/IOUUtils';
import {getTag} from '@libs/TransactionUtils';
Expand Down Expand Up @@ -59,17 +57,16 @@ function FieldAutoSelector({
iouCategory,
isMovingTransactionFromTrackExpense,
}: FieldAutoSelectorProps) {
const {getCurrencyDecimals} = useCurrencyListActions();
// Auto select the category if there is only one enabled category and it is required
useEffect(() => {
const enabledCategories = Object.values(policyCategories ?? {}).filter((category) => category.enabled);
if (!transactionID || iouCategory || !shouldShowCategories || enabledCategories.length !== 1 || !isCategoryRequired) {
return;
}
setMoneyRequestCategory(transactionID, enabledCategories.at(0)?.name ?? '', policy, getCurrencyDecimals, isMovingTransactionFromTrackExpense);
setMoneyRequestCategory(transactionID, enabledCategories.at(0)?.name ?? '', policy, isMovingTransactionFromTrackExpense);
// Keep 'transaction' out to ensure that we auto select the option only once
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [shouldShowCategories, policyCategories, isCategoryRequired, policy?.id, getCurrencyDecimals]);
}, [shouldShowCategories, policyCategories, isCategoryRequired, policy?.id]);

// Auto select the tag if there is only one enabled tag and it is required
useEffect(() => {
Expand Down
23 changes: 18 additions & 5 deletions src/components/MoneyRequestConfirmationList/TaxController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function TaxController({

const previousTransactionCurrency = usePrevious(transaction?.currency);

const {defaultTaxCode, defaultTaxValue, shouldKeepCurrentTaxSelection, taxAmountInSmallestCurrencyUnits} = useTaxAmount({
const {defaultTaxCode, defaultTaxValue, shouldKeepCurrentTaxSelection, taxAmountInSmallestCurrencyUnits, areRulesLoading} = useTaxAmount({
transaction,
policy,
policyForMovingExpenses,
Expand All @@ -80,7 +80,9 @@ function TaxController({
});

useEffect(() => {
if (!transactionID || isReadOnly || !shouldShowTax || isMovingTransactionFromTrackExpense) {
// Writing the workspace default before the rules arrive would read as a tax the user picked, and
// `shouldKeepCurrentTaxSelection` would then hold it in place once the category's rule does land.
if (!transactionID || isReadOnly || !shouldShowTax || isMovingTransactionFromTrackExpense || areRulesLoading) {
return;
}

Expand All @@ -95,14 +97,25 @@ function TaxController({
taxAmount: transactionTaxAmount ?? null,
});
// trigger this useEffect also when policyID changes - the defaultTaxCode may stay the same
}, [defaultTaxCode, defaultTaxValue, isMovingTransactionFromTrackExpense, isReadOnly, transactionID, policyID, shouldShowTax, shouldKeepCurrentTaxSelection, transactionTaxAmount]);
}, [
defaultTaxCode,
defaultTaxValue,
isMovingTransactionFromTrackExpense,
isReadOnly,
transactionID,
policyID,
shouldShowTax,
shouldKeepCurrentTaxSelection,
transactionTaxAmount,
areRulesLoading,
]);

useEffect(() => {
if (!transactionID || isReadOnly || !shouldShowTax || isMovingTransactionFromTrackExpense) {
if (!transactionID || isReadOnly || !shouldShowTax || isMovingTransactionFromTrackExpense || areRulesLoading) {
return;
}
setMoneyRequestTaxAmount(transactionID, taxAmountInSmallestCurrencyUnits);
}, [transactionID, taxAmountInSmallestCurrencyUnits, isReadOnly, shouldShowTax, isMovingTransactionFromTrackExpense]);
}, [transactionID, taxAmountInSmallestCurrencyUnits, isReadOnly, shouldShowTax, isMovingTransactionFromTrackExpense, areRulesLoading]);

return null;
}
Expand Down
Loading
Loading