Skip to content

Commit

Permalink
Merge pull request #52058 from FitseTLT/fix-update-maxExpenseAmountNo…
Browse files Browse the repository at this point in the history
…Receipt-to-maxAmountNoReceipt

Fix - change `maxExpenseAmountNoReceipt` to `maxAmountNoReceipt` for policy…
  • Loading branch information
marcaaron authored Nov 7, 2024
2 parents 2040408 + faa48b6 commit e3e4e53
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/libs/CategoryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ function formatDefaultTaxRateText(translate: LocaleContextProps['translate'], ta
return `${taxRateText}${suffix ? ` ${CONST.DOT_SEPARATOR} ${suffix}` : ``}`;
}

function formatRequireReceiptsOverText(translate: LocaleContextProps['translate'], policy: Policy, categoryMaxExpenseAmountNoReceipt?: number | null) {
const isAlwaysSelected = categoryMaxExpenseAmountNoReceipt === 0;
const isNeverSelected = categoryMaxExpenseAmountNoReceipt === CONST.DISABLED_MAX_EXPENSE_VALUE;
function formatRequireReceiptsOverText(translate: LocaleContextProps['translate'], policy: Policy, categoryMaxAmountNoReceipt?: number | null) {
const isAlwaysSelected = categoryMaxAmountNoReceipt === 0;
const isNeverSelected = categoryMaxAmountNoReceipt === CONST.DISABLED_MAX_EXPENSE_VALUE;

if (isAlwaysSelected) {
return translate(`workspace.rules.categoryRules.requireReceiptsOverList.always`);
Expand Down
32 changes: 16 additions & 16 deletions src/libs/actions/Policy/Category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ function setPolicyCategoryDescriptionRequired(policyID: string, categoryName: st
API.write(WRITE_COMMANDS.SET_POLICY_CATEGORY_DESCRIPTION_REQUIRED, parameters, onyxData);
}

function setPolicyCategoryReceiptsRequired(policyID: string, categoryName: string, maxExpenseAmountNoReceipt: number) {
const originalMaxExpenseAmountNoReceipt = allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`]?.[categoryName]?.maxExpenseAmountNoReceipt;
function setPolicyCategoryReceiptsRequired(policyID: string, categoryName: string, maxAmountNoReceipt: number) {
const originalMaxAmountNoReceipt = allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`]?.[categoryName]?.maxAmountNoReceipt;

const onyxData: OnyxData = {
optimisticData: [
Expand All @@ -402,9 +402,9 @@ function setPolicyCategoryReceiptsRequired(policyID: string, categoryName: strin
[categoryName]: {
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
pendingFields: {
maxExpenseAmountNoReceipt: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
maxAmountNoReceipt: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
maxExpenseAmountNoReceipt,
maxAmountNoReceipt,
},
},
},
Expand All @@ -417,9 +417,9 @@ function setPolicyCategoryReceiptsRequired(policyID: string, categoryName: strin
[categoryName]: {
pendingAction: null,
pendingFields: {
maxExpenseAmountNoReceipt: null,
maxAmountNoReceipt: null,
},
maxExpenseAmountNoReceipt,
maxAmountNoReceipt,
},
},
},
Expand All @@ -433,9 +433,9 @@ function setPolicyCategoryReceiptsRequired(policyID: string, categoryName: strin
errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'),
pendingAction: null,
pendingFields: {
maxExpenseAmountNoReceipt: null,
maxAmountNoReceipt: null,
},
maxExpenseAmountNoReceipt: originalMaxExpenseAmountNoReceipt,
maxAmountNoReceipt: originalMaxAmountNoReceipt,
},
},
},
Expand All @@ -445,14 +445,14 @@ function setPolicyCategoryReceiptsRequired(policyID: string, categoryName: strin
const parameters: SetPolicyCategoryReceiptsRequiredParams = {
policyID,
categoryName,
maxExpenseAmountNoReceipt,
maxExpenseAmountNoReceipt: maxAmountNoReceipt,
};

API.write(WRITE_COMMANDS.SET_POLICY_CATEGORY_RECEIPTS_REQUIRED, parameters, onyxData);
}

function removePolicyCategoryReceiptsRequired(policyID: string, categoryName: string) {
const originalMaxExpenseAmountNoReceipt = allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`]?.[categoryName]?.maxExpenseAmountNoReceipt;
const originalMaxAmountNoReceipt = allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`]?.[categoryName]?.maxAmountNoReceipt;

const onyxData: OnyxData = {
optimisticData: [
Expand All @@ -463,9 +463,9 @@ function removePolicyCategoryReceiptsRequired(policyID: string, categoryName: st
[categoryName]: {
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
pendingFields: {
maxExpenseAmountNoReceipt: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
maxAmountNoReceipt: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
maxExpenseAmountNoReceipt: null,
maxAmountNoReceipt: null,
},
},
},
Expand All @@ -478,9 +478,9 @@ function removePolicyCategoryReceiptsRequired(policyID: string, categoryName: st
[categoryName]: {
pendingAction: null,
pendingFields: {
maxExpenseAmountNoReceipt: null,
maxAmountNoReceipt: null,
},
maxExpenseAmountNoReceipt: null,
maxAmountNoReceipt: null,
},
},
},
Expand All @@ -494,9 +494,9 @@ function removePolicyCategoryReceiptsRequired(policyID: string, categoryName: st
errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'),
pendingAction: null,
pendingFields: {
maxExpenseAmountNoReceipt: null,
maxAmountNoReceipt: null,
},
maxExpenseAmountNoReceipt: originalMaxExpenseAmountNoReceipt,
maxAmountNoReceipt: originalMaxAmountNoReceipt,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ function CategoryRequireReceiptsOverPage({
const policy = usePolicy(policyID);
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`);

const isAlwaysSelected = policyCategories?.[categoryName]?.maxExpenseAmountNoReceipt === 0;
const isNeverSelected = policyCategories?.[categoryName]?.maxExpenseAmountNoReceipt === CONST.DISABLED_MAX_EXPENSE_VALUE;
const isAlwaysSelected = policyCategories?.[categoryName]?.maxAmountNoReceipt === 0;
const isNeverSelected = policyCategories?.[categoryName]?.maxAmountNoReceipt === CONST.DISABLED_MAX_EXPENSE_VALUE;
const maxExpenseAmountToDisplay = policy?.maxExpenseAmount === CONST.DISABLED_MAX_EXPENSE_VALUE ? 0 : policy?.maxExpenseAmount;

const requireReceiptsOverListData = [
Expand Down
6 changes: 3 additions & 3 deletions src/pages/workspace/categories/CategorySettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ function CategorySettingsPage({
if (!policy) {
return '';
}
return CategoryUtils.formatRequireReceiptsOverText(translate, policy, policyCategory?.maxExpenseAmountNoReceipt);
}, [policy, policyCategory?.maxExpenseAmountNoReceipt, translate]);
return CategoryUtils.formatRequireReceiptsOverText(translate, policy, policyCategory?.maxAmountNoReceipt);
}, [policy, policyCategory?.maxAmountNoReceipt, translate]);

if (!policyCategory) {
return <NotFoundPage />;
Expand Down Expand Up @@ -308,7 +308,7 @@ function CategorySettingsPage({
shouldShowRightIcon
/>
</OfflineWithFeedback>
<OfflineWithFeedback pendingAction={policyCategory.pendingFields?.maxExpenseAmountNoReceipt}>
<OfflineWithFeedback pendingAction={policyCategory.pendingFields?.maxAmountNoReceipt}>
<MenuItemWithTopDescription
title={requireReceiptsOverText}
description={translate(`workspace.rules.categoryRules.requireReceiptsOver`)}
Expand Down
2 changes: 1 addition & 1 deletion src/types/onyx/PolicyCategory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type PolicyCategory = OnyxCommon.OnyxValueWithOfflineFeedback<{
expenseLimitType?: PolicyCategoryExpenseLimitType;

/** Max expense amount with no receipt violation */
maxExpenseAmountNoReceipt?: number | null;
maxAmountNoReceipt?: number | null;
}>;

/** Record of policy categories, indexed by their name */
Expand Down

0 comments on commit e3e4e53

Please sign in to comment.