Skip to content

Commit

Permalink
Merge pull request #29344 from getusha/feat-payment-expired-handler
Browse files Browse the repository at this point in the history
Feat: update the report when a payment is refunded
  • Loading branch information
MariaHCD authored Dec 1, 2023
2 parents 6301426 + 75ad8c4 commit dad6391
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ const CONST = {
MODIFIEDEXPENSE: 'MODIFIEDEXPENSE',
MOVED: 'MOVED',
REIMBURSEMENTQUEUED: 'REIMBURSEMENTQUEUED',
REIMBURSEMENTDEQUEUED: 'REIMBURSEMENTDEQUEUED',
RENAMED: 'RENAMED',
REPORTPREVIEW: 'REPORTPREVIEW',
SUBMITTED: 'SUBMITTED',
Expand Down Expand Up @@ -1165,6 +1166,9 @@ const CONST = {
SVG: 'svg',
},
RECEIPT_ERROR: 'receiptError',
CANCEL_REASON: {
PAYMENT_EXPIRED: 'CANCEL_REASON_PAYMENT_EXPIRED',
},
},

GROWL: {
Expand Down
4 changes: 3 additions & 1 deletion src/components/ReportActionItem/MoneyRequestPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ function MoneyRequestPreview(props) {
message += ` • ${props.translate('iou.approved')}`;
} else if (props.iouReport.isWaitingOnBankAccount) {
message += ` • ${props.translate('iou.pending')}`;
} else if (props.iouReport.isCancelledIOU) {
message += ` • ${props.translate('iou.canceled')}`;
}
return message;
};
Expand Down Expand Up @@ -280,7 +282,7 @@ function MoneyRequestPreview(props) {
<View style={styles.moneyRequestPreviewBoxText}>
<View style={[styles.flexRow]}>
<Text style={[styles.textLabelSupporting, styles.flex1, styles.lh20, styles.mb1]}>
{getPreviewHeaderText() + (isSettled ? ` • ${getSettledMessage()}` : '')}
{getPreviewHeaderText() + (isSettled && !props.iouReport.isCancelledIOU ? ` • ${getSettledMessage()}` : '')}
</Text>
{hasFieldErrors && (
<Icon
Expand Down
8 changes: 7 additions & 1 deletion src/components/ReportActionItem/MoneyRequestView.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ function MoneyRequestView({report, parentReport, policyCategories, shouldShowHor

// Flags for allowing or disallowing editing a money request
const isSettled = ReportUtils.isSettled(moneyRequestReport.reportID);
const isCancelled = moneyRequestReport && moneyRequestReport.isCancelledIOU;
const canEdit = ReportUtils.canEditMoneyRequest(parentReportAction);
const canEditAmount = canEdit && !isSettled && !isCardTransaction;

Expand All @@ -133,11 +134,16 @@ function MoneyRequestView({report, parentReport, policyCategories, shouldShowHor
if (TransactionUtils.isPending(transaction)) {
amountDescription += ` • ${translate('iou.pending')}`;
}
if (isCancelled) {
amountDescription += ` • ${translate('iou.canceled')}`;
}
} else {
if (!isDistanceRequest) {
amountDescription += ` • ${translate('iou.cash')}`;
}
if (isSettled) {
if (isCancelled) {
amountDescription += ` • ${translate('iou.canceled')}`;
} else if (isSettled) {
amountDescription += ` • ${translate('iou.settledExpensify')}`;
} else if (report.isWaitingOnBankAccount) {
amountDescription += ` • ${translate('iou.pending')}`;
Expand Down
4 changes: 4 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
BeginningOfChatHistoryAnnounceRoomPartOneParams,
BeginningOfChatHistoryAnnounceRoomPartTwo,
BeginningOfChatHistoryDomainRoomPartOneParams,
CanceledRequestParams,
CharacterLimitParams,
ConfirmThatParams,
DateShouldBeAfterParams,
Expand Down Expand Up @@ -542,6 +543,7 @@ export default {
pay: 'Pay',
viewDetails: 'View details',
pending: 'Pending',
canceled: 'Canceled',
posted: 'Posted',
deleteReceipt: 'Delete receipt',
receiptScanning: 'Receipt scan in progress…',
Expand Down Expand Up @@ -572,6 +574,8 @@ export default {
managerApproved: ({manager}: ManagerApprovedParams) => `${manager} approved:`,
payerSettled: ({amount}: PayerSettledParams) => `paid ${amount}`,
waitingOnBankAccount: ({submitterDisplayName}: WaitingOnBankAccountParams) => `started settling up, payment is held until ${submitterDisplayName} adds a bank account`,
canceledRequest: ({amount, submitterDisplayName}: CanceledRequestParams) =>
`Canceled the ${amount} payment, because ${submitterDisplayName} did not enable their Expensify Wallet within 30 days`,
settledAfterAddedBankAccount: ({submitterDisplayName, amount}: SettledAfterAddedBankAccountParams) =>
`${submitterDisplayName} added a bank account. The ${amount} payment has been made.`,
paidElsewhereWithAmount: ({payer, amount}: PaidElsewhereWithAmountParams) => `${payer} paid ${amount} elsewhere`,
Expand Down
4 changes: 4 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
BeginningOfChatHistoryAnnounceRoomPartOneParams,
BeginningOfChatHistoryAnnounceRoomPartTwo,
BeginningOfChatHistoryDomainRoomPartOneParams,
CanceledRequestParams,
CharacterLimitParams,
ConfirmThatParams,
DateShouldBeAfterParams,
Expand Down Expand Up @@ -534,6 +535,7 @@ export default {
pay: 'Pagar',
viewDetails: 'Ver detalles',
pending: 'Pendiente',
canceled: 'Canceló',
posted: 'Contabilizado',
deleteReceipt: 'Eliminar recibo',
receiptScanning: 'Escaneo de recibo en curso…',
Expand Down Expand Up @@ -564,6 +566,8 @@ export default {
managerApproved: ({manager}: ManagerApprovedParams) => `${manager} aprobó:`,
payerSettled: ({amount}: PayerSettledParams) => `pagó ${amount}`,
waitingOnBankAccount: ({submitterDisplayName}: WaitingOnBankAccountParams) => `inicio el pago, pero no se procesará hasta que ${submitterDisplayName} añada una cuenta bancaria`,
canceledRequest: ({amount, submitterDisplayName}: CanceledRequestParams) =>
`Canceló el pago ${amount}, porque ${submitterDisplayName} no habilitó su billetera Expensify en un plazo de 30 días.`,
settledAfterAddedBankAccount: ({submitterDisplayName, amount}: SettledAfterAddedBankAccountParams) =>
`${submitterDisplayName} añadió una cuenta bancaria. El pago de ${amount} se ha realizado.`,
paidElsewhereWithAmount: ({payer, amount}: PaidElsewhereWithAmountParams) => `${payer} pagó ${amount} de otra forma`,
Expand Down
3 changes: 3 additions & 0 deletions src/languages/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ type PayerSettledParams = {amount: number | string};

type WaitingOnBankAccountParams = {submitterDisplayName: string};

type CanceledRequestParams = {amount: string; submitterDisplayName: string};

type SettledAfterAddedBankAccountParams = {submitterDisplayName: string; amount: string};

type PaidElsewhereWithAmountParams = {payer: string; amount: string};
Expand Down Expand Up @@ -282,6 +284,7 @@ export type {
ManagerApprovedParams,
PayerSettledParams,
WaitingOnBankAccountParams,
CanceledRequestParams,
SettledAfterAddedBankAccountParams,
PaidElsewhereWithAmountParams,
PaidWithExpensifyWithAmountParams,
Expand Down
2 changes: 2 additions & 0 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ function getLastMessageTextForReport(report) {
lastMessageTextFromReport = ReportUtils.getReportPreviewMessage(iouReport, lastIOUMoneyReport, true, ReportUtils.isChatReport(report));
} else if (ReportActionUtils.isReimbursementQueuedAction(lastReportAction)) {
lastMessageTextFromReport = ReportUtils.getReimbursementQueuedActionMessage(lastReportAction, report);
} else if (ReportActionUtils.isReimbursementDeQueuedAction(lastReportAction)) {
lastMessageTextFromReport = ReportUtils.getReimbursementDeQueuedActionMessage(report);
} else if (ReportActionUtils.isDeletedParentAction(lastReportAction) && ReportUtils.isChatReport(report)) {
lastMessageTextFromReport = ReportUtils.getDeletedParentActionMessageForChatReport(lastReportAction);
} else if (ReportUtils.isReportMessageAttachment({text: report.lastMessageText, html: report.lastMessageHtml, translationKey: report.lastMessageTranslationKey})) {
Expand Down
5 changes: 5 additions & 0 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ function isChannelLogMemberAction(reportAction: OnyxEntry<ReportAction>) {
);
}

function isReimbursementDeQueuedAction(reportAction: OnyxEntry<ReportAction>): boolean {
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENTDEQUEUED;
}

/**
* Returns whether the comment is a thread parent message/the first message in a thread
*/
Expand Down Expand Up @@ -698,6 +702,7 @@ export {
hasRequestFromCurrentAccount,
getFirstVisibleReportActionID,
isChannelLogMemberAction,
isReimbursementDeQueuedAction,
};

export type {LastVisibleMessage};
15 changes: 15 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,16 @@ function getReimbursementQueuedActionMessage(reportAction: OnyxEntry<ReportActio
return Localize.translateLocal(messageKey, {submitterDisplayName});
}

/**
* Returns the preview message for `REIMBURSEMENTDEQUEUED` action
*/
function getReimbursementDeQueuedActionMessage(report: OnyxEntry<Report>): string {
const submitterDisplayName = getDisplayNameForParticipant(report?.ownerAccountID, true) ?? '';
const amount = CurrencyUtils.convertToDisplayString(report?.total ?? 0, report?.currency);

return Localize.translateLocal('iou.canceledRequest', {submitterDisplayName, amount});
}

/**
* Returns the last visible message for a given report after considering the given optimistic actions
*
Expand Down Expand Up @@ -1692,6 +1702,10 @@ function getMoneyRequestReportName(report: OnyxEntry<Report>, policy: OnyxEntry<
return `${payerPaidAmountMessage}${Localize.translateLocal('iou.pending')}`;
}

if (report?.isCancelledIOU) {
return `${payerPaidAmountMessage}${Localize.translateLocal('iou.canceled')}`;
}

if (hasNonReimbursableTransactions(report?.reportID)) {
return Localize.translateLocal('iou.payerSpentAmount', {payer: payerName, amount: formattedAmount});
}
Expand Down Expand Up @@ -4404,6 +4418,7 @@ export {
shouldUseFullTitleToDisplay,
parseReportRouteParams,
getReimbursementQueuedActionMessage,
getReimbursementDeQueuedActionMessage,
getPersonalDetailsForAccountID,
getChannelLogMemberMessage,
getRoom,
Expand Down
6 changes: 6 additions & 0 deletions src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import withWindowDimensions, {windowDimensionsPropTypes} from '@components/withW
import usePrevious from '@hooks/usePrevious';
import compose from '@libs/compose';
import ControlSelection from '@libs/ControlSelection';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import focusTextInputAfterAnimation from '@libs/focusTextInputAfterAnimation';
import Navigation from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -415,6 +416,11 @@ function ReportActionItem(props) {
</>
</ReportActionItemBasicMessage>
);
} else if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENTDEQUEUED) {
const submitterDisplayName = PersonalDetailsUtils.getDisplayNameOrDefault(personalDetails, [props.report.ownerAccountID, 'displayName']);
const amount = CurrencyUtils.convertToDisplayString(props.report.total, props.report.currency);

children = <ReportActionItemBasicMessage message={props.translate('iou.canceledRequest', {submitterDisplayName, amount})} />;
} else if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE) {
children = <ReportActionItemBasicMessage message={ReportUtils.getModifiedExpenseMessage(props.action)} />;
} else {
Expand Down
6 changes: 6 additions & 0 deletions src/types/onyx/OriginalMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ type OriginalMessageReimbursementQueued = {
originalMessage: unknown;
};

type OriginalMessageReimbursementDequeued = {
actionName: typeof CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENTDEQUEUED;
originalMessage: unknown;
};

type OriginalMessageMoved = {
actionName: typeof CONST.REPORT.ACTIONS.TYPE.MOVED;
originalMessage: {
Expand All @@ -222,6 +227,7 @@ type OriginalMessage =
| OriginalMessagePolicyTask
| OriginalMessageModifiedExpense
| OriginalMessageReimbursementQueued
| OriginalMessageReimbursementDequeued
| OriginalMessageMoved;

export default OriginalMessage;
Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ type Report = {
/** Whether the report is waiting on a bank account */
isWaitingOnBankAccount?: boolean;

/** Whether the report is cancelled */
isCancelledIOU?: boolean;

/** Whether the last message was deleted */
isLastMessageDeletedParentAction?: boolean;

Expand Down

0 comments on commit dad6391

Please sign in to comment.