Skip to content

Commit

Permalink
Merge pull request Expensify#48385 from Expensify/youssef_reject_repo…
Browse files Browse the repository at this point in the history
…rt_changes

Add support for REJECTED report action
  • Loading branch information
carlosmiceli authored Sep 3, 2024
2 parents 163aa96 + b49d66f commit 2c04129
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 72 deletions.
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ const CONST = {
REIMBURSEMENT_REQUESTED: 'REIMBURSEMENTREQUESTED', // Deprecated OldDot Action
REIMBURSEMENT_SETUP: 'REIMBURSEMENTSETUP', // Deprecated OldDot Action
REIMBURSEMENT_SETUP_REQUESTED: 'REIMBURSEMENTSETUPREQUESTED', // Deprecated OldDot Action
REJECTED: 'REJECTED',
RENAMED: 'RENAMED',
REPORT_PREVIEW: 'REPORTPREVIEW',
SELECTED_FOR_RANDOM_AUDIT: 'SELECTEDFORRANDOMAUDIT', // OldDot Action
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ export default {
payerSettled: ({amount}: PayerSettledParams) => `paid ${amount}`,
approvedAmount: ({amount}: ApprovedAmountParams) => `approved ${amount}`,
forwardedAmount: ({amount}: ForwardedAmountParams) => `approved ${amount}`,
rejectedThisReport: 'rejected this report',
waitingOnBankAccount: ({submitterDisplayName}: WaitingOnBankAccountParams) => `started settling up. Payment is on hold until ${submitterDisplayName} adds a bank account.`,
adminCanceledRequest: ({manager, amount}: AdminCanceledRequestParams) => `${manager ? `${manager}: ` : ''}cancelled the ${amount} payment.`,
canceledRequest: ({amount, submitterDisplayName}: CanceledRequestParams) =>
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ export default {
payerSettled: ({amount}: PayerSettledParams) => `pagó ${amount}`,
approvedAmount: ({amount}: ApprovedAmountParams) => `aprobó ${amount}`,
forwardedAmount: ({amount}: ForwardedAmountParams) => `aprobó ${amount}`,
rejectedThisReport: 'rechazó este informe',
waitingOnBankAccount: ({submitterDisplayName}: WaitingOnBankAccountParams) => `inició el pago, pero no se procesará hasta que ${submitterDisplayName} añada una cuenta bancaria`,
adminCanceledRequest: ({manager, amount}: AdminCanceledRequestParams) => `${manager ? `${manager}: ` : ''}canceló el pago de ${amount}.`,
canceledRequest: ({amount, submitterDisplayName}: CanceledRequestParams) =>
Expand Down
4 changes: 3 additions & 1 deletion src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,9 @@ function getLastMessageTextForReport(report: OnyxEntry<Report>, lastActorDetails
} else if (lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.APPROVED) {
lastMessageTextFromReport = ReportUtils.getIOUApprovedMessage(lastReportAction);
} else if (lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.FORWARDED) {
lastMessageTextFromReport = ReportUtils.getIOUForwardedMessage(lastReportAction);
lastMessageTextFromReport = ReportUtils.getIOUForwardedMessage(lastReportAction, report);
} else if (lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REJECTED) {
lastMessageTextFromReport = ReportUtils.getRejectedReportMessage();
} else if (ReportActionUtils.isActionableAddPaymentCard(lastReportAction)) {
lastMessageTextFromReport = ReportActionUtils.getReportActionMessageText(lastReportAction);
} else if (lastReportAction?.actionName === 'EXPORTINTEGRATION') {
Expand Down
31 changes: 27 additions & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import lodashMaxBy from 'lodash/maxBy';
import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {SvgProps} from 'react-native-svg';
import type {OriginalMessageModifiedExpense} from 'src/types/onyx/OriginalMessage';
import type {OriginalMessageIOU, OriginalMessageModifiedExpense} from 'src/types/onyx/OriginalMessage';
import type {TupleToUnion, ValueOf} from 'type-fest';
import type {FileObject} from '@components/AttachmentModal';
import {FallbackAvatar, QBOCircle, XeroCircle} from '@components/Icon/Expensicons';
Expand Down Expand Up @@ -3678,7 +3678,10 @@ function getReportName(
return getIOUSubmittedMessage(parentReportAction);
}
if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.FORWARDED) {
return getIOUForwardedMessage(parentReportAction);
return getIOUForwardedMessage(parentReportAction, report);
}
if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REJECTED) {
return getRejectedReportMessage();
}
if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.APPROVED) {
return getIOUApprovedMessage(parentReportAction);
Expand Down Expand Up @@ -4404,8 +4407,27 @@ function getIOUApprovedMessage(reportAction: ReportAction) {
return Localize.translateLocal('iou.approvedAmount', {amount: getFormattedAmount(reportAction)});
}

function getIOUForwardedMessage(reportAction: ReportAction) {
return Localize.translateLocal('iou.forwardedAmount', {amount: getFormattedAmount(reportAction)});
/**
* We pass the reportID as older FORWARDED actions do not have the amount & currency stored in the message
* so we retrieve the amount from the report instead
*/
function getIOUForwardedMessage(reportAction: ReportAction, reportOrID: OnyxInputOrEntry<Report> | string) {
const expenseReport = typeof reportOrID === 'string' ? getReport(reportOrID) : reportOrID;
const originalMessage = ReportActionsUtils.getOriginalMessage(reportAction) as OriginalMessageIOU;
let formattedAmount;

// Older FORWARDED action might not have the amount stored in the original message, we'll fallback to getting the amount from the report instead.
if (originalMessage?.amount) {
formattedAmount = getFormattedAmount(reportAction);
} else {
formattedAmount = CurrencyUtils.convertToDisplayString(getMoneyRequestSpendBreakdown(expenseReport).totalDisplaySpend, expenseReport?.currency);
}

return Localize.translateLocal('iou.forwardedAmount', {amount: formattedAmount});
}

function getRejectedReportMessage() {
return Localize.translateLocal('iou.rejectedThisReport');
}

function getWorkspaceNameUpdatedMessage(action: ReportAction) {
Expand Down Expand Up @@ -7829,6 +7851,7 @@ export {
getIOUReportActionMessage,
getIOUApprovedMessage,
getIOUForwardedMessage,
getRejectedReportMessage,
getWorkspaceNameUpdatedMessage,
getIOUSubmittedMessage,
getIcons,
Expand Down
5 changes: 4 additions & 1 deletion src/pages/home/report/ContextMenu/ContextMenuActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,10 @@ const ContextMenuActions: ContextMenuAction[] = [
const displayMessage = ReportUtils.getIOUApprovedMessage(reportAction);
Clipboard.setString(displayMessage);
} else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.FORWARDED) {
const displayMessage = ReportUtils.getIOUForwardedMessage(reportAction);
const displayMessage = ReportUtils.getIOUForwardedMessage(reportAction, reportID);
Clipboard.setString(displayMessage);
} else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REJECTED) {
const displayMessage = ReportUtils.getRejectedReportMessage();
Clipboard.setString(displayMessage);
} else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.HOLD) {
Clipboard.setString(Localize.translateLocal('iou.heldExpense'));
Expand Down
4 changes: 3 additions & 1 deletion src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,9 @@ function ReportActionItem({
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.APPROVED) {
children = <ReportActionItemBasicMessage message={ReportUtils.getIOUApprovedMessage(action)} />;
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.FORWARDED) {
children = <ReportActionItemBasicMessage message={ReportUtils.getIOUForwardedMessage(action)} />;
children = <ReportActionItemBasicMessage message={ReportUtils.getIOUForwardedMessage(action, report)} />;
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.REJECTED) {
children = <ReportActionItemBasicMessage message={translate('iou.rejectedThisReport')} />;
} 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
67 changes: 2 additions & 65 deletions src/types/onyx/OriginalMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,142 +519,79 @@ type OriginalMessageExpensifyCard = {
};

/** The map type of original message */
/* eslint-disable jsdoc/require-jsdoc */
type OriginalMessageMap = {
/** */
[CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_ADD_PAYMENT_CARD]: OriginalMessageAddPaymentCard;
/** */
[CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_JOIN_REQUEST]: OriginalMessageJoinPolicyChangeLog;
/** */
[CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_MENTION_WHISPER]: OriginalMessageActionableMentionWhisper;
/** */
[CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_REPORT_MENTION_WHISPER]: OriginalMessageActionableReportMentionWhisper;
/** */
[CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_TRACK_EXPENSE_WHISPER]: OriginalMessageActionableTrackedExpenseWhisper;
/** */
[CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT]: OriginalMessageAddComment;
/** */
[CONST.REPORT.ACTIONS.TYPE.APPROVED]: OriginalMessageApproved;
/** */
[CONST.REPORT.ACTIONS.TYPE.CHANGE_FIELD]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.CHANGE_POLICY]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.CHANGE_TYPE]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.CHRONOS_OOO_LIST]: OriginalMessageChronosOOOList;
/** */
[CONST.REPORT.ACTIONS.TYPE.CLOSED]: OriginalMessageClosed;
/** */
[CONST.REPORT.ACTIONS.TYPE.CREATED]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.DELEGATE_SUBMIT]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.DISMISSED_VIOLATION]: OriginalMessageDismissedViolation;
/** */
[CONST.REPORT.ACTIONS.TYPE.EXPORTED_TO_CSV]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.EXPORTED_TO_INTEGRATION]: OriginalMessageExportIntegration;
/** */
[CONST.REPORT.ACTIONS.TYPE.FORWARDED]: OriginalMessageForwarded;
/** */
[CONST.REPORT.ACTIONS.TYPE.HOLD]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.HOLD_COMMENT]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.INTEGRATIONS_MESSAGE]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.IOU]: OriginalMessageIOU;
/** */
[CONST.REPORT.ACTIONS.TYPE.MANAGER_ATTACH_RECEIPT]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.MANAGER_DETACH_RECEIPT]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.MARK_REIMBURSED_FROM_INTEGRATION]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.MARKED_REIMBURSED]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.MERGED_WITH_CASH_TRANSACTION]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE]: OriginalMessageModifiedExpense;
/** */
[CONST.REPORT.ACTIONS.TYPE.MOVED]: OriginalMessageMoved;
/** */
[CONST.REPORT.ACTIONS.TYPE.OUTDATED_BANK_ACCOUNT]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_ACH_BOUNCE]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_ACH_CANCELLED]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_ACCOUNT_CHANGED]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_DEQUEUED]: OriginalMessageReimbursementDequeued;
/** */
[CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_DELAYED]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_QUEUED]: OriginalMessageReimbursementQueued;
/** */
[CONST.REPORT.ACTIONS.TYPE.RENAMED]: OriginalMessageRenamed;
/** */
[CONST.REPORT.ACTIONS.TYPE.REJECTED]: never;
[CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW]: OriginalMessageReportPreview;
/** */
[CONST.REPORT.ACTIONS.TYPE.SELECTED_FOR_RANDOM_AUDIT]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.SHARE]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.STRIPE_PAID]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.SUBMITTED]: OriginalMessageSubmitted;
/** */
[CONST.REPORT.ACTIONS.TYPE.TASK_CANCELLED]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.TASK_COMPLETED]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.TASK_EDITED]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.TASK_REOPENED]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.UNAPPROVED]: OriginalMessageUnapproved;
/** */
[CONST.REPORT.ACTIONS.TYPE.UNHOLD]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.UNSHARE]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.UPDATE_GROUP_CHAT_MEMBER_ROLE]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.TRIPPREVIEW]: OriginalMessageTripRoomPreview;
/** */
[CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_REQUESTED]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_SETUP]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.EXPORTED_TO_QUICK_BOOKS]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.DONATION]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.DELETED_ACCOUNT]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_REQUESTED]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_SETUP]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_SETUP_REQUESTED]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED]: OriginalMessageExpensifyCard;
/** */
[CONST.REPORT.ACTIONS.TYPE.CARD_MISSING_ADDRESS]: OriginalMessageExpensifyCard;
/** */
[CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED_VIRTUAL]: OriginalMessageExpensifyCard;
/** */
[CONST.REPORT.ACTIONS.TYPE.INTEGRATION_SYNC_FAILED]: OriginalMessageIntegrationSyncFailed;
} & OldDotOriginalMessageMap & {
[T in ValueOf<typeof CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG>]: OriginalMessageChangeLog;
} & {
[T in ValueOf<typeof CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG>]: OriginalMessageChangeLog;
};

/** */
type OriginalMessage<T extends ReportActionName> = OriginalMessageMap[T];

export default OriginalMessage;
Expand Down

0 comments on commit 2c04129

Please sign in to comment.