Skip to content

Commit

Permalink
Merge pull request #41040 from Expensify/marco-updateSubmittedAdminMe…
Browse files Browse the repository at this point in the history
…ssage
  • Loading branch information
blimpich authored Jul 4, 2024
2 parents 6abb02b + 1e67f73 commit 21f74e9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 77 deletions.
87 changes: 10 additions & 77 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2007,7 +2007,7 @@ function getIcons(
if (isChatThread(report)) {
const parentReportAction = ReportActionsUtils.getParentReportAction(report);

const actorAccountID = parentReportAction?.actorAccountID;
const actorAccountID = getReportActionActorAccountID(parentReportAction, report);
const actorDisplayName = PersonalDetailsUtils.getDisplayNameOrDefault(allPersonalDetails?.[actorAccountID ?? -1], '', false);
const actorIcon = {
id: actorAccountID,
Expand Down Expand Up @@ -4029,77 +4029,11 @@ function buildOptimisticExpenseReport(chatReportID: string, policyID: string, pa
return expenseReport;
}

function getIOUSubmittedMessage(report: OnyxEntry<Report>) {
const policy = getPolicy(report?.policyID);

if (report?.ownerAccountID !== currentUserAccountID && policy?.role === CONST.POLICY.ROLE.ADMIN) {
const ownerPersonalDetail = getPersonalDetailsForAccountID(report?.ownerAccountID ?? -1);
const ownerDisplayName = `${ownerPersonalDetail.displayName ?? ''}${ownerPersonalDetail.displayName !== ownerPersonalDetail.login ? ` (${ownerPersonalDetail.login})` : ''}`;

return [
{
style: 'normal',
text: 'You (on behalf of ',
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
},
{
style: 'strong',
text: ownerDisplayName,
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
},
{
style: 'normal',
text: ' via admin-submit)',
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
},
{
style: 'normal',
text: ' submitted this report',
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
},
{
style: 'normal',
text: ' to ',
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
},
{
style: 'strong',
text: 'you',
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
},
];
}

const submittedToPersonalDetail = getPersonalDetailsForAccountID(PolicyUtils.getSubmitToAccountID(policy, report?.ownerAccountID ?? 0));
let submittedToDisplayName = `${submittedToPersonalDetail.displayName ?? ''}${
submittedToPersonalDetail.displayName !== submittedToPersonalDetail.login ? ` (${submittedToPersonalDetail.login})` : ''
}`;
if (submittedToPersonalDetail?.accountID === currentUserAccountID) {
submittedToDisplayName = 'yourself';
}

return [
{
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
style: 'strong',
text: 'You',
},
{
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
style: 'normal',
text: ' submitted this report',
},
{
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
style: 'normal',
text: ' to ',
},
{
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
style: 'strong',
text: submittedToDisplayName,
},
];
function getIOUSubmittedMessage(reportID: string) {
const report = getReportOrDraftReport(reportID);
const linkedReport = isChatThread(report) ? getParentReport(report) : report;
const formattedAmount = CurrencyUtils.convertToDisplayString(Math.abs(linkedReport?.total ?? 0), linkedReport?.currency);
return Localize.translateLocal('iou.submittedAmount', {formattedAmount});
}

/**
Expand All @@ -4113,11 +4047,6 @@ function getIOUSubmittedMessage(report: OnyxEntry<Report>) {
*/
function getIOUReportActionMessage(iouReportID: string, type: string, total: number, comment: string, currency: string, paymentType = '', isSettlingUp = false): Message[] {
const report = getReportOrDraftReport(iouReportID);

if (type === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) {
return getIOUSubmittedMessage(!isEmptyObject(report) ? report : undefined);
}

const amount =
type === CONST.IOU.REPORT_ACTION_TYPE.PAY && !isEmptyObject(report)
? CurrencyUtils.convertToDisplayString(getMoneyRequestSpendBreakdown(report).totalDisplaySpend, currency)
Expand Down Expand Up @@ -4154,6 +4083,9 @@ function getIOUReportActionMessage(iouReportID: string, type: string, total: num
case CONST.IOU.REPORT_ACTION_TYPE.PAY:
iouMessage = isSettlingUp ? `paid ${amount}${paymentMethodMessage}` : `sent ${amount}${comment && ` for ${comment}`}${paymentMethodMessage}`;
break;
case CONST.REPORT.ACTIONS.TYPE.SUBMITTED:
iouMessage = Localize.translateLocal('iou.submittedAmount', {formattedAmount: amount});
break;
default:
break;
}
Expand Down Expand Up @@ -7216,6 +7148,7 @@ export {
getGroupChatName,
getIOUReportActionDisplayMessage,
getIOUReportActionMessage,
getIOUSubmittedMessage,
getIcons,
getIconsForParticipants,
getIndicatedMissingPaymentMethod,
Expand Down
3 changes: 3 additions & 0 deletions src/pages/home/report/ContextMenu/ContextMenuActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,9 @@ const ContextMenuActions: ContextMenuAction[] = [
setClipboardMessage(mentionWhisperMessage);
} else if (ReportActionsUtils.isActionableTrackExpense(reportAction)) {
setClipboardMessage(CONST.ACTIONABLE_TRACK_EXPENSE_WHISPER_MESSAGE);
} else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) {
const displayMessage = ReportUtils.getIOUSubmittedMessage(reportID);
Clipboard.setString(displayMessage);
} else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.HOLD) {
Clipboard.setString(Localize.translateLocal('iou.heldExpense'));
} else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.UNHOLD) {
Expand Down
2 changes: 2 additions & 0 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,8 @@ function ReportActionItem({
} else if (ReportActionsUtils.isOldDotReportAction(action)) {
// This handles all historical actions from OldDot that we just want to display the message text
children = <ReportActionItemBasicMessage message={ReportActionsUtils.getMessageOfOldDotReportAction(action)} />;
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) {
children = <ReportActionItemBasicMessage message={ReportUtils.getIOUSubmittedMessage(report.reportID)} />;
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.HOLD) {
children = <ReportActionItemBasicMessage message={translate('iou.heldExpense')} />;
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.HOLD_COMMENT) {
Expand Down

0 comments on commit 21f74e9

Please sign in to comment.