Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix - change maxExpenseAmountNoReceipt to maxAmountNoReceipt for policy… #52058

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
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @marcaaron @Beamanator do we need to rename the request param here from maxExpenseAmountNoReceipt to maxAmountNoReceipt too? Or we're still fine with request param

Copy link
Contributor Author

@FitseTLT FitseTLT Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also to note a more important thing:
the policyCategory. maxAmountNoReceipt is fixed and properly working but the policy. maxExpenseAmountNoReceipt is not saving changes in the database so when you change the value the API returns the updated value but after you clear cache the value get back to the default value. It is not directly related to this issue but want to report it if you guys want to handle the BE changes.

2024-11-06.14-48-11.mp4

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just keep with the current param name. It's still maxExpenseAmountNoReceipt in the BE, but the category field will be correct.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the policyCategory. maxAmountNoReceipt is fixed and properly working but the policy. maxExpenseAmountNoReceipt is not saving changes in the database so when you change the value the API returns the updated value but after you clear cache the value get back to the default value. It is not directly related to this issue but want to report it if you guys want to handle the BE changes.

Let's report this as a separate issue. As you said, it's not related.

};

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
Loading