-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathModifiedExpenseMessage.ts
More file actions
494 lines (437 loc) · 24 KB
/
ModifiedExpenseMessage.ts
File metadata and controls
494 lines (437 loc) · 24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
import isEmpty from 'lodash/isEmpty';
import type {OnyxEntry} from 'react-native-onyx';
import type {Entries, ValueOf} from 'type-fest';
import type {LocalizedTranslate} from '@components/LocaleContextProvider';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type {Policy, PolicyTagLists, Report, ReportAction, ReportAttributesDerivedValue} from '@src/types/onyx';
import type {PersonalRulesModifiedFields, PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage';
import ObjectUtils from '@src/types/utils/ObjectUtils';
import {getDecodedCategoryName, isCategoryMissing} from './CategoryUtils';
import {convertToDisplayString} from './CurrencyUtils';
import DateUtils from './DateUtils';
import {getEnvironmentURL} from './Environment/Environment';
import {formatList} from './Localize';
import Log from './Log';
import Parser from './Parser';
import {getPersonalDetailByEmail} from './PersonalDetailsUtils';
import {getCleanedTagName, getCommaSeparatedTagNameWithSanitizedColons, getSortedTagKeys, isPolicyAdmin} from './PolicyUtils';
import {getOriginalMessage, isModifiedExpenseAction} from './ReportActionsUtils';
// This cycle import is safe because ReportNameUtils was extracted from ReportUtils to separate report name computation logic.
// The functions imported here are pure utility functions that don't create initialization-time dependencies.
// ReportNameUtils imports helper functions from ReportUtils, and ReportUtils imports name generation functions from ReportNameUtils.
// eslint-disable-next-line import/no-cycle
import {buildReportNameFromParticipantNames, getPolicyExpenseChatName, getReportName} from './ReportNameUtils';
// eslint-disable-next-line import/no-cycle
import {getPolicyName, getRootParentReport, isPolicyExpenseChat, isSelfDM} from './ReportUtils';
import {getFormattedAttendees, getTagArrayFromName} from './TransactionUtils';
import {isInvalidMerchantValue} from './ValidationUtils';
let environmentURL: string;
getEnvironmentURL().then((url: string) => (environmentURL = url));
/**
* Builds the partial message fragment for a modified field on the expense.
*/
function buildMessageFragmentForValue(
translate: LocalizedTranslate,
newValue: string,
oldValue: string,
valueName: string,
valueInQuotes: boolean,
setFragments: string[],
removalFragments: string[],
changeFragments: string[],
shouldConvertToLowercase = true,
) {
const newValueToDisplay = valueInQuotes ? `"${newValue}"` : newValue;
const oldValueToDisplay = valueInQuotes ? `"${oldValue}"` : oldValue;
const isCategoryField = valueName.includes(translate('common.category').toLowerCase());
const displayValueName = shouldConvertToLowercase ? valueName.toLowerCase() : valueName;
const isOldMerchantInvalid = valueName === translate('common.merchant') && isInvalidMerchantValue(oldValue);
const isOldCategoryMissing = isCategoryField && isCategoryMissing(oldValue);
const isNewCategoryMissing = isCategoryField && isCategoryMissing(newValue);
if (!oldValue || isOldMerchantInvalid || isOldCategoryMissing) {
if (!(isOldCategoryMissing && isNewCategoryMissing)) {
const fragment = translate('iou.setTheRequest', displayValueName, newValueToDisplay);
setFragments.push(fragment);
}
} else if (!newValue || newValue === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT) {
const fragment = translate('iou.removedTheRequest', displayValueName, oldValueToDisplay);
removalFragments.push(fragment);
} else {
const fragment = translate('iou.updatedTheRequest', {valueName: displayValueName, newValueToDisplay, oldValueToDisplay});
changeFragments.push(fragment);
}
}
/**
* Get the absolute value for a tax amount.
*/
function getTaxAmountAbsValue(taxAmount: number): number {
// IOU requests cannot have negative values but they can be stored as negative values, let's return absolute value
return Math.abs(taxAmount ?? 0);
}
/**
* Get the message line for a modified expense.
*/
function getMessageLine(translate: LocalizedTranslate, prefix: string, messageFragments: string[]): string {
if (messageFragments.length === 0) {
return '';
}
return messageFragments.reduce((acc, value, index) => {
if (index === messageFragments.length - 1) {
if (messageFragments.length === 1) {
return `${acc} ${value}`;
}
if (messageFragments.length === 2) {
return `${acc} ${translate('common.and')} ${value}`;
}
return `${acc}, ${translate('common.and')} ${value}`;
}
if (index === 0) {
return `${acc} ${value}`;
}
return `${acc}, ${value}`;
}, prefix);
}
function getForDistanceRequest(translate: LocalizedTranslate, newMerchant: string, oldMerchant: string, newAmount: string, oldAmount: string): string {
let changedField: 'distance' | 'rate' = 'distance';
if (CONST.REGEX.DISTANCE_MERCHANT.test(newMerchant) && CONST.REGEX.DISTANCE_MERCHANT.test(oldMerchant)) {
const oldValues = oldMerchant.split('@');
const oldDistance = oldValues.at(0)?.trim() ?? '';
const oldRate = oldValues.at(1)?.trim() ?? '';
const newValues = newMerchant.split('@');
const newDistance = newValues.at(0)?.trim() ?? '';
const newRate = newValues.at(1)?.trim() ?? '';
if (oldDistance === newDistance && oldRate !== newRate) {
changedField = 'rate';
}
} else {
Log.hmmm("Distance request merchant doesn't match NewDot format. Defaulting to showing as distance changed.", {newMerchant, oldMerchant});
}
const translatedChangedField = translate(`common.${changedField}`).toLowerCase();
if (!oldMerchant.length) {
return translate('iou.setTheDistanceMerchant', translatedChangedField, newMerchant, newAmount);
}
return translate('iou.updatedTheDistanceMerchant', {
translatedChangedField,
newMerchant,
oldMerchant,
newAmountToDisplay: newAmount,
oldAmountToDisplay: oldAmount,
});
}
function getForExpenseMovedFromSelfDM(translate: LocalizedTranslate, destinationReport: OnyxEntry<Report>, currentUserLogin: string) {
const rootParentReport = getRootParentReport({report: destinationReport});
// In OldDot, expenses could be moved to a self-DM. Return the corresponding message for this case.
if (isSelfDM(rootParentReport)) {
return translate('iou.movedToPersonalSpace');
}
// In NewDot, the "Move report" flow only supports moving expenses from self-DM to:
// - A policy expense chat
// - A 1:1 DM
const currentUserAccountID = getPersonalDetailByEmail(currentUserLogin)?.accountID;
const reportName = isPolicyExpenseChat(rootParentReport)
? getPolicyExpenseChatName({report: rootParentReport})
: buildReportNameFromParticipantNames({report: rootParentReport, currentUserAccountID});
const policyName = getPolicyName({report: rootParentReport, returnEmptyIfNotFound: true});
// If we can't determine either the report name or policy name, return the default message
if (isEmpty(policyName) && !reportName) {
return translate('iou.changedTheExpense');
}
return translate('iou.movedFromPersonalSpace', {reportName, workspaceName: !isEmpty(policyName) ? policyName : undefined});
}
function getMovedReportID(reportAction: OnyxEntry<ReportAction>, type: ValueOf<typeof CONST.REPORT.MOVE_TYPE>): string | undefined {
if (!isModifiedExpenseAction(reportAction)) {
return undefined;
}
const reportActionOriginalMessage = getOriginalMessage(reportAction);
return type === CONST.REPORT.MOVE_TYPE.TO ? reportActionOriginalMessage?.movedToReportID : reportActionOriginalMessage?.movedFromReport;
}
function getMovedFromOrToReportMessage(
translate: LocalizedTranslate,
movedFromReport: OnyxEntry<Report> | undefined,
movedToReport: OnyxEntry<Report> | undefined,
currentUserLogin: string,
reportAttributes?: ReportAttributesDerivedValue['reports'],
): string | undefined {
if (movedToReport) {
return getForExpenseMovedFromSelfDM(translate, movedToReport, currentUserLogin);
}
if (movedFromReport) {
const originReportName = getReportName(movedFromReport, reportAttributes);
return translate('iou.movedFromReport', originReportName ?? '');
}
}
function getRulesModifiedMessage(
translate: LocalizedTranslate,
fields: PolicyRulesModifiedFields | PersonalRulesModifiedFields,
isPersonalRules: boolean,
policyID?: string,
hasPolicyRuleAccess?: boolean,
) {
const entries = ObjectUtils.typedEntries(fields);
// reportName ("moved to report X"), reimbursable/billable ("marked the expense as reimbursable/billable"), are standalone clauses with their own verb.
// They must not be mixed into the "set ... and ..." list produced by the other field fragments.
const {standaloneFragments, listEntries} = entries.reduce<{standaloneFragments: string[]; listEntries: Entries<PolicyRulesModifiedFields>}>(
(acc, entry) => {
const [key, value] = entry;
if (key === 'reportName') {
acc.standaloneFragments.push(translate('iou.rulesModifiedFields.reportName', value as string));
} else if (key === 'reimbursable') {
acc.standaloneFragments.push(translate('iou.rulesModifiedFields.reimbursable', value as boolean));
} else if (key === 'billable') {
acc.standaloneFragments.push(translate('iou.rulesModifiedFields.billable', value as boolean));
} else {
acc.listEntries.push(entry as Entries<PolicyRulesModifiedFields>[number]);
}
return acc;
},
{standaloneFragments: [], listEntries: []},
);
const listFragment = listEntries.map(([key, value], i) => {
const isFirst = i === 0;
if (key === 'tax') {
const taxEntry = value as PolicyRulesModifiedFields['tax'];
const taxRateName = taxEntry?.field_id_TAX.name ?? '';
return translate('iou.rulesModifiedFields.tax', taxRateName, isFirst);
}
const updatedValue = value as string;
if (key === 'category') {
return translate('iou.rulesModifiedFields.common', key, getDecodedCategoryName(updatedValue), isFirst);
}
if (key === 'tag') {
return translate('iou.rulesModifiedFields.common', key, getCommaSeparatedTagNameWithSanitizedColons(updatedValue), isFirst);
}
// The backend saves the description field as `comment` key, but we need to display it as `description` key.
if (key === 'comment') {
return translate('iou.rulesModifiedFields.common', 'description', Parser.htmlToMarkdown(updatedValue), isFirst);
}
return translate('iou.rulesModifiedFields.common', key, updatedValue, isFirst);
});
const fragments = [...standaloneFragments, ...listFragment];
let route = policyID && hasPolicyRuleAccess ? `${environmentURL}/${ROUTES.WORKSPACE_RULES.getRoute(policyID)}` : CONST.CONFIGURE_EXPENSE_REPORT_RULES_HELP_URL;
if (isPersonalRules) {
route = `${environmentURL}/${ROUTES.SETTINGS_RULES}`;
}
return fragments.length > 0 ? translate(isPersonalRules ? 'iou.rulesModifiedFields.formatPersonalRules' : 'iou.rulesModifiedFields.formatPolicyRules', formatList(fragments), route) : '';
}
/**
* Get the report action message when expense has been modified.
*
* ModifiedExpense::getNewDotComment in Web-Expensify should match this.
* If we change this function be sure to update the backend as well.
*/
function getForReportAction({
translate,
reportAction,
policy,
movedFromReport,
movedToReport,
policyTags,
currentUserLogin,
reportAttributes,
}: {
translate: LocalizedTranslate;
reportAction: OnyxEntry<ReportAction>;
policy?: OnyxEntry<Policy>;
movedFromReport?: OnyxEntry<Report>;
movedToReport?: OnyxEntry<Report>;
// Optional because the deprecated getReportName in ReportUtils.ts calls this without policyTags.
// getReportName itself will be migrated away from Onyx.connect in a follow-up PR.
// See https://github.com/Expensify/App/pull/75562
policyTags?: OnyxEntry<PolicyTagLists>;
currentUserLogin: string;
reportAttributes?: ReportAttributesDerivedValue['reports'];
}): string {
if (!isModifiedExpenseAction(reportAction)) {
return '';
}
const movedFromOrToReportMessage = getMovedFromOrToReportMessage(translate, movedFromReport, movedToReport, currentUserLogin, reportAttributes);
if (movedFromOrToReportMessage) {
return movedFromOrToReportMessage;
}
const reportActionOriginalMessage = getOriginalMessage(reportAction);
const removalFragments: string[] = [];
const setFragments: string[] = [];
const changeFragments: string[] = [];
const isReportActionOriginalMessageAnObject = reportActionOriginalMessage && typeof reportActionOriginalMessage === 'object';
const hasModifiedAmount =
isReportActionOriginalMessageAnObject &&
'oldAmount' in reportActionOriginalMessage &&
'oldCurrency' in reportActionOriginalMessage &&
'amount' in reportActionOriginalMessage &&
'currency' in reportActionOriginalMessage;
const hasModifiedMerchant = isReportActionOriginalMessageAnObject && 'oldMerchant' in reportActionOriginalMessage && 'merchant' in reportActionOriginalMessage;
if (hasModifiedAmount) {
const oldCurrency = reportActionOriginalMessage?.oldCurrency;
const oldAmountValue = reportActionOriginalMessage?.oldAmount ?? 0;
const oldAmount = convertToDisplayString(oldAmountValue, oldCurrency);
const currency = reportActionOriginalMessage?.currency;
const amount = convertToDisplayString(reportActionOriginalMessage?.amount ?? 0, currency);
// Only Distance edits should modify amount and merchant (which stores distance) in a single transaction.
// We check the merchant is in distance format (includes @) as a sanity check
if (hasModifiedMerchant && (reportActionOriginalMessage?.merchant ?? '').includes('@')) {
return getForDistanceRequest(translate, reportActionOriginalMessage?.merchant ?? '', reportActionOriginalMessage?.oldMerchant ?? '', amount, oldAmount);
}
buildMessageFragmentForValue(translate, amount, oldAmount, translate('iou.amount'), false, setFragments, removalFragments, changeFragments);
}
const hasModifiedComment = isReportActionOriginalMessageAnObject && 'oldComment' in reportActionOriginalMessage && 'newComment' in reportActionOriginalMessage;
if (hasModifiedComment) {
let descriptionLabel = translate('common.description');
// Add attribution suffix based on AI-generated descriptions
if (reportActionOriginalMessage?.aiGenerated) {
descriptionLabel += ` ${translate('iou.basedOnAI')}`;
}
buildMessageFragmentForValue(
translate,
Parser.htmlToMarkdown(reportActionOriginalMessage?.newComment ?? ''),
Parser.htmlToMarkdown(reportActionOriginalMessage?.oldComment ?? ''),
descriptionLabel,
true,
setFragments,
removalFragments,
changeFragments,
);
}
if (reportActionOriginalMessage?.oldCreated && reportActionOriginalMessage?.created) {
const formattedOldCreated = DateUtils.formatWithUTCTimeZone(reportActionOriginalMessage.oldCreated, CONST.DATE.FNS_FORMAT_STRING);
buildMessageFragmentForValue(translate, reportActionOriginalMessage.created, formattedOldCreated, translate('common.date'), false, setFragments, removalFragments, changeFragments);
}
if (hasModifiedMerchant) {
buildMessageFragmentForValue(
translate,
reportActionOriginalMessage?.merchant ?? '',
reportActionOriginalMessage?.oldMerchant ?? '',
translate('common.merchant'),
true,
setFragments,
removalFragments,
changeFragments,
);
}
const hasModifiedCategory = isReportActionOriginalMessageAnObject && 'oldCategory' in reportActionOriginalMessage && 'category' in reportActionOriginalMessage;
if (hasModifiedCategory) {
let categoryLabel = translate('common.category').toLowerCase();
// Add attribution suffix based on source
if (reportActionOriginalMessage?.source === CONST.CATEGORY_SOURCE.AI) {
categoryLabel += ` ${translate('iou.basedOnAI')}`;
} else if (reportActionOriginalMessage?.source === CONST.CATEGORY_SOURCE.MCC) {
const isAdmin = isPolicyAdmin(policy, currentUserLogin);
// For admins, create a hyperlink to the workspace rules page
if (isAdmin && policy?.id) {
const rulesLink = `${environmentURL}/${ROUTES.WORKSPACE_RULES.getRoute(policy.id)}`;
categoryLabel += ` ${translate('iou.basedOnMCC', {rulesLink})}`;
} else {
categoryLabel += ` ${translate('iou.basedOnMCC', {rulesLink: ''})}`;
}
}
buildMessageFragmentForValue(
translate,
getDecodedCategoryName(reportActionOriginalMessage?.category ?? ''),
getDecodedCategoryName(reportActionOriginalMessage?.oldCategory ?? ''),
categoryLabel,
true,
setFragments,
removalFragments,
changeFragments,
// Don't convert to lowercase when we have source attribution (to preserve any HTML links)
false,
);
}
const hasModifiedTag = isReportActionOriginalMessageAnObject && 'oldTag' in reportActionOriginalMessage && 'tag' in reportActionOriginalMessage;
if (hasModifiedTag) {
const policyTagsToUse = policyTags ?? CONST.POLICY.DEFAULT_TAG_LIST;
const transactionTag = reportActionOriginalMessage?.tag ?? '';
const oldTransactionTag = reportActionOriginalMessage?.oldTag ?? '';
const splittedTag = getTagArrayFromName(transactionTag);
const splittedOldTag = getTagArrayFromName(oldTransactionTag);
const localizedTagListName = translate('common.tag');
const sortedTagKeys = getSortedTagKeys(policyTagsToUse);
for (const [index, policyTagKey] of sortedTagKeys.entries()) {
const policyTagListName = policyTagsToUse[policyTagKey].name || localizedTagListName;
const newTag = splittedTag.at(index) ?? '';
const oldTag = splittedOldTag.at(index) ?? '';
if (newTag !== oldTag) {
buildMessageFragmentForValue(
translate,
getCleanedTagName(newTag),
getCleanedTagName(oldTag),
policyTagListName,
true,
setFragments,
removalFragments,
changeFragments,
policyTagListName === localizedTagListName,
);
}
}
}
const hasModifiedTaxAmount = isReportActionOriginalMessageAnObject && 'oldTaxAmount' in reportActionOriginalMessage && 'taxAmount' in reportActionOriginalMessage;
if (hasModifiedTaxAmount) {
const currency = reportActionOriginalMessage?.currency;
const taxAmount = convertToDisplayString(getTaxAmountAbsValue(reportActionOriginalMessage?.taxAmount ?? 0), currency);
const oldTaxAmountValue = getTaxAmountAbsValue(reportActionOriginalMessage?.oldTaxAmount ?? 0);
const oldTaxAmount = convertToDisplayString(oldTaxAmountValue, currency);
buildMessageFragmentForValue(translate, taxAmount, oldTaxAmount, translate('iou.taxAmount'), false, setFragments, removalFragments, changeFragments);
}
const hasModifiedTaxRate = isReportActionOriginalMessageAnObject && 'oldTaxRate' in reportActionOriginalMessage && 'taxRate' in reportActionOriginalMessage;
if (hasModifiedTaxRate) {
buildMessageFragmentForValue(
translate,
reportActionOriginalMessage?.taxRate ?? '',
reportActionOriginalMessage?.oldTaxRate ?? '',
translate('iou.taxRate'),
false,
setFragments,
removalFragments,
changeFragments,
);
}
const hasModifiedBillable = isReportActionOriginalMessageAnObject && 'oldBillable' in reportActionOriginalMessage && 'billable' in reportActionOriginalMessage;
if (hasModifiedBillable) {
const oldBillable = reportActionOriginalMessage?.oldBillable === 'billable' ? translate('common.billable').toLowerCase() : translate('common.nonBillable').toLowerCase();
const newBillable = reportActionOriginalMessage?.billable === 'billable' ? translate('common.billable').toLowerCase() : translate('common.nonBillable').toLowerCase();
buildMessageFragmentForValue(translate, newBillable, oldBillable, translate('iou.expense'), true, setFragments, removalFragments, changeFragments);
}
const hasModifiedReimbursable = isReportActionOriginalMessageAnObject && 'oldReimbursable' in reportActionOriginalMessage && 'reimbursable' in reportActionOriginalMessage;
if (hasModifiedReimbursable) {
const oldReimbursable =
reportActionOriginalMessage?.oldReimbursable === 'reimbursable' ? translate('iou.reimbursable').toLowerCase() : translate('iou.nonReimbursable').toLowerCase();
const newReimbursable = reportActionOriginalMessage?.reimbursable === 'reimbursable' ? translate('iou.reimbursable').toLowerCase() : translate('iou.nonReimbursable').toLowerCase();
buildMessageFragmentForValue(translate, newReimbursable, oldReimbursable, translate('iou.expense'), true, setFragments, removalFragments, changeFragments);
}
const hasModifiedAttendees = isReportActionOriginalMessageAnObject && 'oldAttendees' in reportActionOriginalMessage && 'newAttendees' in reportActionOriginalMessage;
if (hasModifiedAttendees) {
const [oldAttendees, attendees] = getFormattedAttendees(reportActionOriginalMessage.newAttendees, reportActionOriginalMessage.oldAttendees);
buildMessageFragmentForValue(translate, oldAttendees, attendees, translate('iou.attendees'), false, setFragments, removalFragments, changeFragments);
}
const hasPersonalRulesModifiedFields = isReportActionOriginalMessageAnObject && 'personalRulesModifiedFields' in reportActionOriginalMessage;
if (hasPersonalRulesModifiedFields) {
const personalRulesModifiedFields = reportActionOriginalMessage.personalRulesModifiedFields;
if (personalRulesModifiedFields) {
return getRulesModifiedMessage(translate, personalRulesModifiedFields, true);
}
}
const hasPolicyRulesModifiedFields = isReportActionOriginalMessageAnObject && 'policyRulesModifiedFields' in reportActionOriginalMessage && 'policyID' in reportActionOriginalMessage;
if (hasPolicyRulesModifiedFields) {
const policyRulesModifiedFields = reportActionOriginalMessage.policyRulesModifiedFields;
if (policyRulesModifiedFields && policy?.id) {
const hasPolicyRuleAccess = !!policy?.areRulesEnabled && isPolicyAdmin(policy, currentUserLogin);
return getRulesModifiedMessage(translate, policyRulesModifiedFields, false, policy?.id, hasPolicyRuleAccess);
}
}
const message =
getMessageLine(translate, `\n${translate('iou.changed')}`, changeFragments) +
getMessageLine(translate, `\n${translate('iou.set')}`, setFragments) +
getMessageLine(translate, `\n${translate('iou.removed')}`, removalFragments);
if (message === '') {
// If we don't have enough structured information to build a detailed message but we
// know the change was AI-generated, fall back to an AI-attributed generic summary so
// users can still understand that Concierge updated the expense automatically.
if (reportActionOriginalMessage?.aiGenerated) {
return `${translate('iou.changedTheExpense')} ${translate('iou.basedOnAI')}`;
}
return translate('iou.changedTheExpense');
}
return `${message.substring(1, message.length)}`;
}
export {getForReportAction, getMovedReportID, getMovedFromOrToReportMessage};