Skip to content

Commit 5c9517e

Browse files
authored
Merge pull request #49909 from Expensify/beaman-updateAutoApproveCopy
Update "automatically approved" report action copy
2 parents 41e97d7 + 05e2d8c commit 5c9517e

File tree

8 files changed

+137
-18
lines changed

8 files changed

+137
-18
lines changed

src/languages/en.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,11 @@ const translations = {
915915
managerApprovedAmount: ({manager, amount}: ManagerApprovedAmountParams) => `${manager} approved ${amount}`,
916916
payerSettled: ({amount}: PayerSettledParams) => `paid ${amount}`,
917917
payerSettledWithMissingBankAccount: ({amount}: PayerSettledParams) => `paid ${amount}. Add a bank account to receive your payment.`,
918+
automaticallyApprovedAmount: ({amount}: ApprovedAmountParams) =>
919+
`automatically approved ${amount} via <a href="${CONST.CONFIGURE_REIMBURSEMENT_SETTINGS_HELP_URL}">workspace rules</a>`,
918920
approvedAmount: ({amount}: ApprovedAmountParams) => `approved ${amount}`,
921+
automaticallyForwardedAmount: ({amount}: ForwardedAmountParams) =>
922+
`automatically approved ${amount} via <a href="${CONST.CONFIGURE_REIMBURSEMENT_SETTINGS_HELP_URL}">workspace rules</a>`,
919923
forwardedAmount: ({amount}: ForwardedAmountParams) => `approved ${amount}`,
920924
rejectedThisReport: 'rejected this report',
921925
waitingOnBankAccount: ({submitterDisplayName}: WaitingOnBankAccountParams) => `started settling up. Payment is on hold until ${submitterDisplayName} adds a bank account.`,

src/languages/es.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,11 @@ const translations = {
909909
managerApprovedAmount: ({manager, amount}: ManagerApprovedAmountParams) => `${manager} aprobó ${amount}`,
910910
payerSettled: ({amount}: PayerSettledParams) => `pagó ${amount}`,
911911
payerSettledWithMissingBankAccount: ({amount}: PayerSettledParams) => `pagó ${amount}. Agrega una cuenta bancaria para recibir tu pago.`,
912+
automaticallyApprovedAmount: ({amount}: ApprovedAmountParams) =>
913+
`aprobado automáticamente ${amount} según las <a href="${CONST.CONFIGURE_REIMBURSEMENT_SETTINGS_HELP_URL}">reglas del espacio de trabajo</a>`,
912914
approvedAmount: ({amount}: ApprovedAmountParams) => `aprobó ${amount}`,
915+
automaticallyForwardedAmount: ({amount}: ForwardedAmountParams) =>
916+
`aprobado automáticamente ${amount} según las <a href="${CONST.CONFIGURE_REIMBURSEMENT_SETTINGS_HELP_URL}">reglas del espacio de trabajo</a>`,
913917
forwardedAmount: ({amount}: ForwardedAmountParams) => `aprobó ${amount}`,
914918
rejectedThisReport: 'rechazó este informe',
915919
waitingOnBankAccount: ({submitterDisplayName}: WaitingOnBankAccountParams) => `inició el pago, pero no se procesará hasta que ${submitterDisplayName} añada una cuenta bancaria`,

src/libs/OptionsListUtils.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -717,10 +717,20 @@ function getLastMessageTextForReport(report: OnyxEntry<Report>, lastActorDetails
717717
} else {
718718
lastMessageTextFromReport = ReportUtils.getIOUSubmittedMessage(lastReportAction);
719719
}
720-
} else if (lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.APPROVED) {
721-
lastMessageTextFromReport = ReportUtils.getIOUApprovedMessage(lastReportAction);
722-
} else if (lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.FORWARDED) {
723-
lastMessageTextFromReport = ReportUtils.getIOUForwardedMessage(lastReportAction, report);
720+
} else if (ReportActionUtils.isActionOfType(lastReportAction, CONST.REPORT.ACTIONS.TYPE.APPROVED)) {
721+
const {automaticAction} = ReportActionUtils.getOriginalMessage(lastReportAction) ?? {};
722+
if (automaticAction) {
723+
lastMessageTextFromReport = ReportUtils.getReportAutomaticallyApprovedMessage(lastReportAction);
724+
} else {
725+
lastMessageTextFromReport = ReportUtils.getIOUApprovedMessage(lastReportAction);
726+
}
727+
} else if (ReportActionUtils.isActionOfType(lastReportAction, CONST.REPORT.ACTIONS.TYPE.FORWARDED)) {
728+
const {automaticAction} = ReportActionUtils.getOriginalMessage(lastReportAction) ?? {};
729+
if (automaticAction) {
730+
lastMessageTextFromReport = ReportUtils.getReportAutomaticallyForwardedMessage(lastReportAction, reportID);
731+
} else {
732+
lastMessageTextFromReport = ReportUtils.getIOUForwardedMessage(lastReportAction, report);
733+
}
724734
} else if (lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REJECTED) {
725735
lastMessageTextFromReport = ReportUtils.getRejectedReportMessage();
726736
} else if (ReportActionUtils.isActionableAddPaymentCard(lastReportAction)) {

src/libs/ReportUtils.ts

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3819,15 +3819,27 @@ function getReportName(
38193819
ReportActionsUtils.isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.SUBMITTED) ||
38203820
ReportActionsUtils.isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.SUBMITTED_AND_CLOSED)
38213821
) {
3822+
const {harvesting} = ReportActionsUtils.getOriginalMessage(parentReportAction) ?? {};
3823+
if (harvesting) {
3824+
return Parser.htmlToText(getReportAutomaticallySubmittedMessage(parentReportAction));
3825+
}
38223826
return getIOUSubmittedMessage(parentReportAction);
38233827
}
3824-
if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.FORWARDED) {
3828+
if (ReportActionsUtils.isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.FORWARDED)) {
3829+
const {automaticAction} = ReportActionsUtils.getOriginalMessage(parentReportAction) ?? {};
3830+
if (automaticAction) {
3831+
return Parser.htmlToText(getReportAutomaticallyForwardedMessage(parentReportAction, reportID));
3832+
}
38253833
return getIOUForwardedMessage(parentReportAction, report);
38263834
}
38273835
if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REJECTED) {
38283836
return getRejectedReportMessage();
38293837
}
3830-
if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.APPROVED) {
3838+
if (ReportActionsUtils.isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.APPROVED)) {
3839+
const {automaticAction} = ReportActionsUtils.getOriginalMessage(parentReportAction) ?? {};
3840+
if (automaticAction) {
3841+
return Parser.htmlToText(getReportAutomaticallyApprovedMessage(parentReportAction));
3842+
}
38313843
return getIOUApprovedMessage(parentReportAction);
38323844
}
38333845

@@ -4573,15 +4585,38 @@ function getIOUSubmittedMessage(reportAction: ReportAction<typeof CONST.REPORT.A
45734585
return Localize.translateLocal('iou.submittedAmount', {formattedAmount: getFormattedAmount(reportAction)});
45744586
}
45754587

4576-
function getIOUApprovedMessage(reportAction: ReportAction) {
4588+
function getReportAutomaticallyApprovedMessage(reportAction: ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.APPROVED>) {
4589+
return Localize.translateLocal('iou.automaticallyApprovedAmount', {amount: getFormattedAmount(reportAction)});
4590+
}
4591+
4592+
function getIOUApprovedMessage(reportAction: ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.APPROVED>) {
45774593
return Localize.translateLocal('iou.approvedAmount', {amount: getFormattedAmount(reportAction)});
45784594
}
45794595

45804596
/**
45814597
* We pass the reportID as older FORWARDED actions do not have the amount & currency stored in the message
45824598
* so we retrieve the amount from the report instead
45834599
*/
4584-
function getIOUForwardedMessage(reportAction: ReportAction, reportOrID: OnyxInputOrEntry<Report> | string) {
4600+
function getReportAutomaticallyForwardedMessage(reportAction: ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.FORWARDED>, reportOrID: OnyxInputOrEntry<Report> | string) {
4601+
const expenseReport = typeof reportOrID === 'string' ? getReport(reportOrID) : reportOrID;
4602+
const originalMessage = ReportActionsUtils.getOriginalMessage(reportAction) as OriginalMessageIOU;
4603+
let formattedAmount;
4604+
4605+
// Older FORWARDED action might not have the amount stored in the original message, we'll fallback to getting the amount from the report instead.
4606+
if (originalMessage?.amount) {
4607+
formattedAmount = getFormattedAmount(reportAction);
4608+
} else {
4609+
formattedAmount = CurrencyUtils.convertToDisplayString(getMoneyRequestSpendBreakdown(expenseReport).totalDisplaySpend, expenseReport?.currency);
4610+
}
4611+
4612+
return Localize.translateLocal('iou.automaticallyForwardedAmount', {amount: formattedAmount});
4613+
}
4614+
4615+
/**
4616+
* We pass the reportID as older FORWARDED actions do not have the amount & currency stored in the message
4617+
* so we retrieve the amount from the report instead
4618+
*/
4619+
function getIOUForwardedMessage(reportAction: ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.FORWARDED>, reportOrID: OnyxInputOrEntry<Report> | string) {
45854620
const expenseReport = typeof reportOrID === 'string' ? getReport(reportOrID) : reportOrID;
45864621
const originalMessage = ReportActionsUtils.getOriginalMessage(reportAction) as OriginalMessageIOU;
45874622
let formattedAmount;
@@ -7232,7 +7267,7 @@ function getIOUReportActionDisplayMessage(reportAction: OnyxEntry<ReportAction>,
72327267

72337268
const amount = TransactionUtils.getAmount(transaction, !isEmptyObject(iouReport) && isExpenseReport(iouReport)) ?? 0;
72347269
const formattedAmount = CurrencyUtils.convertToDisplayString(amount, TransactionUtils.getCurrency(transaction)) ?? '';
7235-
const isRequestSettled = isSettled(originalMessage?.IOUReportID);
7270+
const isRequestSettled = isSettled(IOUReportID);
72367271
const isApproved = isReportApproved(iouReport);
72377272
if (isRequestSettled) {
72387273
return Localize.translateLocal('iou.payerSettled', {
@@ -8172,7 +8207,9 @@ export {
81728207
getGroupChatName,
81738208
getIOUReportActionDisplayMessage,
81748209
getIOUReportActionMessage,
8210+
getReportAutomaticallyApprovedMessage,
81758211
getIOUApprovedMessage,
8212+
getReportAutomaticallyForwardedMessage,
81768213
getIOUForwardedMessage,
81778214
getRejectedReportMessage,
81788215
getWorkspaceNameUpdatedMessage,

src/pages/home/report/ContextMenu/ContextMenuActions.tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,31 @@ const ContextMenuActions: ContextMenuAction[] = [
443443
ReportActionsUtils.isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.SUBMITTED) ||
444444
ReportActionsUtils.isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.SUBMITTED_AND_CLOSED)
445445
) {
446-
const displayMessage = ReportUtils.getIOUSubmittedMessage(reportAction);
446+
const {harvesting} = ReportActionsUtils.getOriginalMessage(reportAction) ?? {};
447+
let displayMessage = '';
448+
if (harvesting) {
449+
displayMessage = ReportUtils.getReportAutomaticallySubmittedMessage(reportAction);
450+
} else {
451+
displayMessage = ReportUtils.getIOUSubmittedMessage(reportAction);
452+
}
447453
Clipboard.setString(displayMessage);
448-
} else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.APPROVED) {
449-
const displayMessage = ReportUtils.getIOUApprovedMessage(reportAction);
454+
} else if (ReportActionsUtils.isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.APPROVED)) {
455+
const {automaticAction} = ReportActionsUtils.getOriginalMessage(reportAction) ?? {};
456+
let displayMessage = '';
457+
if (automaticAction) {
458+
displayMessage = ReportUtils.getReportAutomaticallyApprovedMessage(reportAction);
459+
} else {
460+
displayMessage = ReportUtils.getIOUApprovedMessage(reportAction);
461+
}
450462
Clipboard.setString(displayMessage);
451-
} else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.FORWARDED) {
452-
const displayMessage = ReportUtils.getIOUForwardedMessage(reportAction, reportID);
463+
} else if (ReportActionsUtils.isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.FORWARDED)) {
464+
const {automaticAction} = ReportActionsUtils.getOriginalMessage(reportAction) ?? {};
465+
let displayMessage = '';
466+
if (automaticAction) {
467+
displayMessage = ReportUtils.getReportAutomaticallyForwardedMessage(reportAction, reportID);
468+
} else {
469+
displayMessage = ReportUtils.getIOUForwardedMessage(reportAction, reportID);
470+
}
453471
Clipboard.setString(displayMessage);
454472
} else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REJECTED) {
455473
const displayMessage = ReportUtils.getRejectedReportMessage();

src/pages/home/report/ReportActionItem.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -646,10 +646,28 @@ function ReportActionItem({
646646
} else {
647647
children = <ReportActionItemBasicMessage message={ReportUtils.getIOUSubmittedMessage(action)} />;
648648
}
649-
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.APPROVED) {
650-
children = <ReportActionItemBasicMessage message={ReportUtils.getIOUApprovedMessage(action)} />;
651-
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.FORWARDED) {
652-
children = <ReportActionItemBasicMessage message={ReportUtils.getIOUForwardedMessage(action, report)} />;
649+
} else if (ReportActionsUtils.isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.APPROVED)) {
650+
const wasAutoApproved = ReportActionsUtils.getOriginalMessage(action)?.automaticAction ?? false;
651+
if (wasAutoApproved) {
652+
children = (
653+
<ReportActionItemBasicMessage message="">
654+
<RenderHTML html={`<comment><muted-text>${ReportUtils.getReportAutomaticallyApprovedMessage(action)}</muted-text></comment>`} />
655+
</ReportActionItemBasicMessage>
656+
);
657+
} else {
658+
children = <ReportActionItemBasicMessage message={ReportUtils.getIOUApprovedMessage(action)} />;
659+
}
660+
} else if (ReportActionsUtils.isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.FORWARDED)) {
661+
const wasAutoForwarded = ReportActionsUtils.getOriginalMessage(action)?.automaticAction ?? false;
662+
if (wasAutoForwarded) {
663+
children = (
664+
<ReportActionItemBasicMessage message="">
665+
<RenderHTML html={`<comment><muted-text>${ReportUtils.getReportAutomaticallyForwardedMessage(action, reportID)}</muted-text></comment>`} />
666+
</ReportActionItemBasicMessage>
667+
);
668+
} else {
669+
children = <ReportActionItemBasicMessage message={ReportUtils.getIOUForwardedMessage(action, report)} />;
670+
}
653671
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.REJECTED) {
654672
children = <ReportActionItemBasicMessage message={translate('iou.rejectedThisReport')} />;
655673
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.HOLD) {

src/types/onyx/OriginalMessage.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ type OriginalMessageApproved = {
438438
/** Approved expense amount */
439439
amount: number;
440440

441+
/** Was the action created automatically, not by a human */
442+
automaticAction?: boolean;
443+
441444
/** Currency of the approved expense amount */
442445
currency: string;
443446

@@ -450,6 +453,9 @@ type OriginalMessageForwarded = {
450453
/** Forwarded expense amount */
451454
amount: number;
452455

456+
/** Was the action created automatically, not by a human */
457+
automaticAction?: boolean;
458+
453459
/** Currency of the forwarded expense amount */
454460
currency: string;
455461

tests/unit/ReportUtilsTest.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,28 @@ describe('ReportUtils', () => {
270270
});
271271
});
272272
});
273+
274+
describe('ParentReportAction is', () => {
275+
test('Manually Submitted Report Action', () => {
276+
const threadOfSubmittedReportAction = {
277+
...LHNTestUtils.getFakeReport(),
278+
type: CONST.REPORT.TYPE.EXPENSE,
279+
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
280+
statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
281+
parentReportID: '101',
282+
policyID: policy.id,
283+
};
284+
const submittedParentReportAction = {
285+
actionName: CONST.REPORT.ACTIONS.TYPE.SUBMITTED,
286+
originalMessage: {
287+
amount: 169,
288+
currency: 'USD',
289+
},
290+
} as ReportAction;
291+
292+
expect(ReportUtils.getReportName(threadOfSubmittedReportAction, policy, submittedParentReportAction)).toBe('submitted $1.69');
293+
});
294+
});
273295
});
274296

275297
describe('requiresAttentionFromCurrentUser', () => {

0 commit comments

Comments
 (0)