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 system message for custom tags on expense report #30917

Merged
merged 3 commits into from
Nov 14, 2023
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
20 changes: 17 additions & 3 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as defaultWorkspaceAvatars from '@components/Icon/WorkspaceDefaultAvata
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import * as IOU from './actions/IOU';
import * as CurrencyUtils from './CurrencyUtils';
import DateUtils from './DateUtils';
import isReportMessageAttachment from './isReportMessageAttachment';
Expand All @@ -19,6 +20,7 @@ import linkingConfig from './Navigation/linkingConfig';
import Navigation from './Navigation/Navigation';
import * as NumberUtils from './NumberUtils';
import Permissions from './Permissions';
import * as PolicyUtils from './PolicyUtils';
import * as ReportActionsUtils from './ReportActionsUtils';
import * as TransactionUtils from './TransactionUtils';
import * as Url from './Url';
Expand Down Expand Up @@ -1863,13 +1865,14 @@ function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceip
* @param {String} oldValue
* @param {String} valueName
* @param {Boolean} valueInQuotes
* @param {Boolean} shouldConvertToLowercase
* @returns {String}
*/

function getProperSchemaForModifiedExpenseMessage(newValue, oldValue, valueName, valueInQuotes) {
function getProperSchemaForModifiedExpenseMessage(newValue, oldValue, valueName, valueInQuotes, shouldConvertToLowercase = true) {
const newValueToDisplay = valueInQuotes ? `"${newValue}"` : newValue;
const oldValueToDisplay = valueInQuotes ? `"${oldValue}"` : oldValue;
const displayValueName = valueName.toLowerCase();
const displayValueName = shouldConvertToLowercase ? valueName.toLowerCase() : valueName;

if (!oldValue) {
return Localize.translateLocal('iou.setTheRequest', {valueName: displayValueName, newValueToDisplay});
Expand Down Expand Up @@ -1916,6 +1919,11 @@ function getModifiedExpenseMessage(reportAction) {
if (_.isEmpty(reportActionOriginalMessage)) {
return Localize.translateLocal('iou.changedTheRequest');
}
const reportID = lodashGet(reportAction, 'reportID', '');
const policyID = lodashGet(getReport(reportID), 'policyID', '');
const policyTags = IOU.getPolicyTags(policyID);
const policyTag = PolicyUtils.getTag(policyTags);
const policyTagListName = lodashGet(policyTag, 'name', Localize.translateLocal('common.tag'));

const hasModifiedAmount =
_.has(reportActionOriginalMessage, 'oldAmount') &&
Expand Down Expand Up @@ -1964,7 +1972,13 @@ function getModifiedExpenseMessage(reportAction) {

const hasModifiedTag = _.has(reportActionOriginalMessage, 'oldTag') && _.has(reportActionOriginalMessage, 'tag');
if (hasModifiedTag) {
return getProperSchemaForModifiedExpenseMessage(reportActionOriginalMessage.tag, reportActionOriginalMessage.oldTag, Localize.translateLocal('common.tag'), true);
return getProperSchemaForModifiedExpenseMessage(
reportActionOriginalMessage.tag,
reportActionOriginalMessage.oldTag,
policyTagListName,
true,
policyTagListName === Localize.translateLocal('common.tag'),
);
}

const hasModifiedBillable = _.has(reportActionOriginalMessage, 'oldBillable') && _.has(reportActionOriginalMessage, 'billable');
Expand Down
5 changes: 5 additions & 0 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -2953,6 +2953,10 @@ function getIOUReportID(iou, route) {
return lodashGet(route, 'params.reportID') || lodashGet(iou, 'participants.0.reportID', '');
}

function getPolicyTags(policyID) {
return lodashGet(allPolicyTags, `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`, {});
}

export {
createDistanceRequest,
editMoneyRequest,
Expand Down Expand Up @@ -2989,4 +2993,5 @@ export {
replaceReceipt,
detachReceipt,
getIOUReportID,
getPolicyTags,
};
Loading