Skip to content

Commit

Permalink
Merge pull request #51829 from Expensify/revert-51390-50563-fix-offli…
Browse files Browse the repository at this point in the history
…ne-category-update-gray-out-and-name-sync

Revert "fix ensure category is grayed out and name is updated when modified o…"

(cherry picked from commit 37dc393)

(CP triggered by yuwenmemon)
  • Loading branch information
yuwenmemon authored and OSBotify committed Oct 31, 2024
1 parent 284d637 commit a9cadde
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 23 deletions.
18 changes: 2 additions & 16 deletions src/libs/CategoryUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {LocaleContextProps} from '@components/LocaleContextProvider';
import CONST from '@src/CONST';
import type {Policy, TaxRate, TaxRatesWithDefault} from '@src/types/onyx';
import type {ApprovalRule, ExpenseRule, MccGroup} from '@src/types/onyx/Policy';
import type {ApprovalRule, ExpenseRule} from '@src/types/onyx/Policy';
import * as CurrencyUtils from './CurrencyUtils';

function formatDefaultTaxRateText(translate: LocaleContextProps['translate'], taxID: string, taxRate: TaxRate, policyTaxRates?: TaxRatesWithDefault) {
Expand Down Expand Up @@ -68,18 +68,4 @@ function getCategoryDefaultTaxRate(expenseRules: ExpenseRule[], categoryName: st
return categoryDefaultTaxRate;
}

function updateCategoryInMccGroup(mccGroups: Record<string, MccGroup>, oldCategoryName: string, newCategoryName: string) {
if (oldCategoryName === newCategoryName) {
return mccGroups;
}

const updatedGroups: Record<string, MccGroup> = {};

for (const [key, group] of Object.entries(mccGroups || {})) {
updatedGroups[key] = group.category === oldCategoryName ? {...group, category: newCategoryName, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE} : group;
}

return updatedGroups;
}

export {formatDefaultTaxRateText, formatRequireReceiptsOverText, getCategoryApproverRule, getCategoryExpenseRule, getCategoryDefaultTaxRate, updateCategoryInMccGroup};
export {formatDefaultTaxRateText, formatRequireReceiptsOverText, getCategoryApproverRule, getCategoryExpenseRule, getCategoryDefaultTaxRate};
7 changes: 1 addition & 6 deletions src/libs/actions/Policy/Category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import * as ReportUtils from '@libs/ReportUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Policy, PolicyCategories, PolicyCategory, RecentlyUsedCategories, Report} from '@src/types/onyx';
import type {ApprovalRule, CustomUnit, ExpenseRule, MccGroup} from '@src/types/onyx/Policy';
import type {ApprovalRule, CustomUnit, ExpenseRule} from '@src/types/onyx/Policy';
import type {PolicyCategoryExpenseLimitType} from '@src/types/onyx/PolicyCategory';
import type {OnyxData} from '@src/types/onyx/Request';

Expand Down Expand Up @@ -542,11 +542,8 @@ function renamePolicyCategory(policyID: string, policyCategory: {oldName: string
const policyCategoryExpenseRule = CategoryUtils.getCategoryExpenseRule(policy?.rules?.expenseRules ?? [], policyCategory.oldName);
const approvalRules = policy?.rules?.approvalRules ?? [];
const expenseRules = policy?.rules?.expenseRules ?? [];
const mccGroup = policy?.mccGroup ?? {};
const updatedApprovalRules: ApprovalRule[] = lodashCloneDeep(approvalRules);
const updatedExpenseRules: ExpenseRule[] = lodashCloneDeep(expenseRules);
const clonedMccGroup: Record<string, MccGroup> = lodashCloneDeep(mccGroup);
const updatedMccGroup = CategoryUtils.updateCategoryInMccGroup(clonedMccGroup, policyCategory.oldName, policyCategory.newName);

if (policyCategoryExpenseRule) {
const ruleIndex = updatedExpenseRules.findIndex((rule) => rule.id === policyCategoryExpenseRule.id);
Expand Down Expand Up @@ -599,7 +596,6 @@ function renamePolicyCategory(policyID: string, policyCategory: {oldName: string
approvalRules: updatedApprovalRules,
expenseRules: updatedExpenseRules,
},
mccGroup: updatedMccGroup,
},
},
],
Expand Down Expand Up @@ -643,7 +639,6 @@ function renamePolicyCategory(policyID: string, policyCategory: {oldName: string
rules: {
approvalRules,
},
mccGroup: updatedMccGroup,
},
},
],
Expand Down
1 change: 0 additions & 1 deletion src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1901,5 +1901,4 @@ export type {
ApprovalRule,
ExpenseRule,
NetSuiteConnectionConfig,
MccGroup,
};

0 comments on commit a9cadde

Please sign in to comment.