From 48953d024d0bd7f5ea06fe36c02f398e429fbf01 Mon Sep 17 00:00:00 2001 From: Vit Horacek <36083550+mountiny@users.noreply.github.com> Date: Mon, 25 Dec 2023 22:42:02 +0100 Subject: [PATCH] Revert "Create Cancel Payment command" --- src/CONST.ts | 3 - src/components/MoneyReportHeader.js | 30 +------ src/languages/en.ts | 5 -- src/languages/es.ts | 5 -- src/languages/types.ts | 3 - src/libs/OptionsListUtils.js | 2 +- src/libs/ReportUtils.ts | 49 +--------- src/libs/actions/IOU.js | 103 ---------------------- src/pages/home/report/ReportActionItem.js | 6 +- src/types/onyx/OriginalMessage.ts | 6 -- src/types/onyx/ReportAction.ts | 3 - 11 files changed, 12 insertions(+), 203 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index aca59bd831e6..edfea995ed9b 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -594,9 +594,6 @@ const CONST = { }, }, }, - CANCEL_PAYMENT_REASONS: { - ADMIN: 'CANCEL_REASON_ADMIN', - }, ARCHIVE_REASON: { DEFAULT: 'default', ACCOUNT_CLOSED: 'accountClosed', diff --git a/src/components/MoneyReportHeader.js b/src/components/MoneyReportHeader.js index e72f7d3576f5..3e6ce7e5be52 100644 --- a/src/components/MoneyReportHeader.js +++ b/src/components/MoneyReportHeader.js @@ -1,6 +1,6 @@ import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; -import React, {useCallback, useMemo, useState} from 'react'; +import React, {useMemo} from 'react'; import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; @@ -24,9 +24,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import Button from './Button'; -import ConfirmModal from './ConfirmModal'; import HeaderWithBackButton from './HeaderWithBackButton'; -import * as Expensicons from './Icon/Expensicons'; import MoneyReportHeaderStatusBar from './MoneyReportHeaderStatusBar'; import participantPropTypes from './participantPropTypes'; import SettlementButton from './SettlementButton'; @@ -76,9 +74,9 @@ const defaultProps = { }; function MoneyReportHeader({session, personalDetails, policy, chatReport, nextStep, report: moneyRequestReport, isSmallScreenWidth}) { - const {windowWidth} = useWindowDimensions(); const styles = useThemeStyles(); const {translate} = useLocalize(); + const {windowWidth} = useWindowDimensions(); const reimbursableTotal = ReportUtils.getMoneyRequestReimbursableTotal(moneyRequestReport); const isApproved = ReportUtils.isReportApproved(moneyRequestReport); const isSettled = ReportUtils.isSettled(moneyRequestReport.reportID); @@ -91,13 +89,6 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt isPolicyAdmin && (isApproved || isManager) : isPolicyAdmin || (ReportUtils.isMoneyRequestReport(moneyRequestReport) && isManager); const isDraft = ReportUtils.isDraftExpenseReport(moneyRequestReport); - const [isConfirmModalVisible, setIsConfirmModalVisible] = useState(false); - - const cancelPayment = useCallback(() => { - IOU.cancelPayment(moneyRequestReport, chatReport); - setIsConfirmModalVisible(false); - }, [moneyRequestReport, chatReport]); - const shouldShowPayButton = useMemo( () => isPayer && !isDraft && !isSettled && !moneyRequestReport.isWaitingOnBankAccount && reimbursableTotal !== 0 && !ReportUtils.isArchivedRoom(chatReport), [isPayer, isDraft, isSettled, moneyRequestReport, reimbursableTotal, chatReport], @@ -118,13 +109,6 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt const isMoreContentShown = shouldShowNextSteps || (shouldShowAnyButton && isSmallScreenWidth); const threeDotsMenuItems = [HeaderUtils.getPinMenuItem(moneyRequestReport)]; - if (isPayer && isSettled) { - threeDotsMenuItems.push({ - icon: Expensicons.Trashcan, - text: 'Cancel payment', - onSelected: () => setIsConfirmModalVisible(true), - }); - } if (!ReportUtils.isArchivedRoom(chatReport)) { threeDotsMenuItems.push({ icon: ZoomIcon, @@ -222,16 +206,6 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt )} - setIsConfirmModalVisible(false)} - prompt={translate('iou.cancelPaymentConfirmation')} - confirmText={translate('iou.cancelPayment')} - cancelText={translate('common.dismiss')} - danger - /> ); } diff --git a/src/languages/en.ts b/src/languages/en.ts index 2ed4cf1b257c..71d27e341cac 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -2,7 +2,6 @@ import {CONST as COMMON_CONST} from 'expensify-common/lib/CONST'; import CONST from '@src/CONST'; import type { AddressLineParams, - AdminCanceledRequestParams, AlreadySignedInParams, AmountEachParams, ApprovedAmountParams, @@ -97,7 +96,6 @@ type AllCountries = Record; export default { common: { cancel: 'Cancel', - dismiss: 'Dismiss', yes: 'Yes', no: 'No', ok: 'OK', @@ -551,8 +549,6 @@ export default { requestMoney: 'Request money', sendMoney: 'Send money', pay: 'Pay', - cancelPayment: 'Cancel payment', - cancelPaymentConfirmation: 'Are you sure that you want to cancel this payment?', viewDetails: 'View details', pending: 'Pending', canceled: 'Canceled', @@ -589,7 +585,6 @@ export default { payerSettled: ({amount}: PayerSettledParams) => `paid ${amount}`, approvedAmount: ({amount}: ApprovedAmountParams) => `approved ${amount}`, waitingOnBankAccount: ({submitterDisplayName}: WaitingOnBankAccountParams) => `started settling up, payment is held until ${submitterDisplayName} adds a bank account`, - adminCanceledRequest: ({amount}: AdminCanceledRequestParams) => `The ${amount} payment has been cancelled by the admin.`, canceledRequest: ({amount, submitterDisplayName}: CanceledRequestParams) => `Canceled the ${amount} payment, because ${submitterDisplayName} did not enable their Expensify Wallet within 30 days`, settledAfterAddedBankAccount: ({submitterDisplayName, amount}: SettledAfterAddedBankAccountParams) => diff --git a/src/languages/es.ts b/src/languages/es.ts index a0de1f8ce18e..85223c559f81 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -1,7 +1,6 @@ import CONST from '@src/CONST'; import type { AddressLineParams, - AdminCanceledRequestParams, AlreadySignedInParams, AmountEachParams, ApprovedAmountParams, @@ -87,7 +86,6 @@ import type { export default { common: { cancel: 'Cancelar', - dismiss: 'Descartar', yes: 'Sí', no: 'No', ok: 'OK', @@ -544,8 +542,6 @@ export default { requestMoney: 'Pedir dinero', sendMoney: 'Enviar dinero', pay: 'Pagar', - cancelPayment: 'Cancelar el pago', - cancelPaymentConfirmation: '¿Estás seguro de que quieres cancelar este pago?', viewDetails: 'Ver detalles', pending: 'Pendiente', canceled: 'Canceló', @@ -582,7 +578,6 @@ export default { payerSettled: ({amount}: PayerSettledParams) => `pagó ${amount}`, approvedAmount: ({amount}: ApprovedAmountParams) => `aprobó ${amount}`, waitingOnBankAccount: ({submitterDisplayName}: WaitingOnBankAccountParams) => `inicio el pago, pero no se procesará hasta que ${submitterDisplayName} añada una cuenta bancaria`, - adminCanceledRequest: ({amount}: AdminCanceledRequestParams) => `El pago de ${amount} ha sido cancelado por el administrador.`, 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) => diff --git a/src/languages/types.ts b/src/languages/types.ts index 1a4b833b4122..8e72c700a9cc 100644 --- a/src/languages/types.ts +++ b/src/languages/types.ts @@ -131,8 +131,6 @@ type WaitingOnBankAccountParams = {submitterDisplayName: string}; type CanceledRequestParams = {amount: string; submitterDisplayName: string}; -type AdminCanceledRequestParams = {amount: string}; - type SettledAfterAddedBankAccountParams = {submitterDisplayName: string; amount: string}; type PaidElsewhereWithAmountParams = {payer: string; amount: string}; @@ -295,7 +293,6 @@ export type { PayerSettledParams, WaitingOnBankAccountParams, CanceledRequestParams, - AdminCanceledRequestParams, SettledAfterAddedBankAccountParams, PaidElsewhereWithAmountParams, PaidWithExpensifyWithAmountParams, diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 1c2899f14c94..6e84ef4dca27 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -402,7 +402,7 @@ function getLastMessageTextForReport(report) { } else if (ReportActionUtils.isReimbursementQueuedAction(lastReportAction)) { lastMessageTextFromReport = ReportUtils.getReimbursementQueuedActionMessage(lastReportAction, report); } else if (ReportActionUtils.isReimbursementDeQueuedAction(lastReportAction)) { - lastMessageTextFromReport = ReportUtils.getReimbursementDeQueuedActionMessage(lastReportAction, report); + 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})) { diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8e0ff19bf3dc..e88e81aacaab 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -15,7 +15,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import {Beta, Login, PersonalDetails, PersonalDetailsList, Policy, Report, ReportAction, Session, Transaction} from '@src/types/onyx'; import {Errors, Icon, PendingAction} from '@src/types/onyx/OnyxCommon'; -import {IOUMessage, OriginalMessageActionName, OriginalMessageCreated, ReimbursementDeQueuedMessage} from '@src/types/onyx/OriginalMessage'; +import {IOUMessage, OriginalMessageActionName, OriginalMessageCreated} from '@src/types/onyx/OriginalMessage'; import {NotificationPreference} from '@src/types/onyx/Report'; import {Message, ReportActionBase, ReportActions} from '@src/types/onyx/ReportAction'; import {Receipt, WaypointCollection} from '@src/types/onyx/Transaction'; @@ -176,11 +176,6 @@ type OptimisticSubmittedReportAction = Pick< 'actionName' | 'actorAccountID' | 'automatic' | 'avatar' | 'isAttachment' | 'originalMessage' | 'message' | 'person' | 'reportActionID' | 'shouldShow' | 'created' | 'pendingAction' >; -type OptimisticCancelPaymentReportAction = Pick< - ReportAction, - 'actionName' | 'actorAccountID' | 'message' | 'originalMessage' | 'person' | 'reportActionID' | 'shouldShow' | 'created' | 'pendingAction' ->; - type OptimisticEditedTaskReportAction = Pick< ReportAction, 'reportActionID' | 'actionName' | 'pendingAction' | 'actorAccountID' | 'automatic' | 'avatar' | 'created' | 'shouldShow' | 'message' | 'person' @@ -1540,13 +1535,10 @@ function getReimbursementQueuedActionMessage(reportAction: OnyxEntry, report: OnyxEntry): string { - const amount = CurrencyUtils.convertToDisplayString(Math.abs(report?.total ?? 0), report?.currency); - const originalMessage = reportAction?.originalMessage as ReimbursementDeQueuedMessage | undefined; - if (originalMessage?.cancellationReason === CONST.REPORT.CANCEL_PAYMENT_REASONS.ADMIN) { - return Localize.translateLocal('iou.adminCanceledRequest', {amount}); - } +function getReimbursementDeQueuedActionMessage(report: OnyxEntry): string { const submitterDisplayName = getDisplayNameForParticipant(report?.ownerAccountID, true) ?? ''; + const amount = CurrencyUtils.convertToDisplayString(report?.total ?? 0, report?.currency); + return Localize.translateLocal('iou.canceledRequest', {submitterDisplayName, amount}); } @@ -2795,38 +2787,6 @@ function buildOptimisticSubmittedReportAction(amount: number, currency: string, }; } -/** - * Builds an optimistic REIMBURSEMENTDEQUEUED report action with a randomly generated reportActionID. - * - */ -function buildOptimisticCancelPaymentReportAction(): OptimisticCancelPaymentReportAction { - return { - actionName: CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENTDEQUEUED, - actorAccountID: currentUserAccountID, - message: [ - { - cancellationReason: CONST.REPORT.CANCEL_PAYMENT_REASONS.ADMIN, - type: CONST.REPORT.MESSAGE.TYPE.COMMENT, - text: '', - }, - ], - originalMessage: { - cancellationReason: CONST.REPORT.CANCEL_PAYMENT_REASONS.ADMIN, - }, - person: [ - { - style: 'strong', - text: currentUserPersonalDetails?.displayName ?? currentUserEmail, - type: 'TEXT', - }, - ], - reportActionID: NumberUtils.rand64(), - shouldShow: true, - created: DateUtils.getDBTime(), - pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - }; -} - /** * Builds an optimistic report preview action with a randomly generated reportActionID. * @@ -4303,7 +4263,6 @@ export { buildOptimisticApprovedReportAction, buildOptimisticMovedReportAction, buildOptimisticSubmittedReportAction, - buildOptimisticCancelPaymentReportAction, buildOptimisticExpenseReport, buildOptimisticIOUReportAction, buildOptimisticReportPreview, diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 2eae5fe9be84..b4d9424ecb00 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -3117,108 +3117,6 @@ function submitReport(expenseReport) { ); } -/** - * @param {Object} expenseReport - * @param {Object} chatReport - */ -function cancelPayment(expenseReport, chatReport) { - const optimisticReportAction = ReportUtils.buildOptimisticCancelPaymentReportAction(); - const policy = ReportUtils.getPolicy(chatReport.policyID); - const isFree = policy && policy.type === CONST.POLICY.TYPE.FREE; - const optimisticData = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`, - value: { - [optimisticReportAction.reportActionID]: { - ...optimisticReportAction, - pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - }, - }, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`, - value: { - ...expenseReport, - lastMessageText: lodashGet(optimisticReportAction, 'message.0.text', ''), - lastMessageHtml: lodashGet(optimisticReportAction, 'message.0.html', ''), - state: isFree ? CONST.REPORT.STATE.SUBMITTED : CONST.REPORT.STATE.OPEN, - stateNum: isFree ? CONST.REPORT.STATE_NUM.PROCESSING : CONST.REPORT.STATE.OPEN, - statusNum: isFree ? CONST.REPORT.STATUS.SUBMITTED : CONST.REPORT.STATE.OPEN, - }, - }, - ...(chatReport.reportID - ? [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, - value: { - ...chatReport, - hasOutstandingIOU: true, - hasOutstandingChildRequest: true, - iouReportID: expenseReport.reportID, - }, - }, - ] - : []), - ]; - - const successData = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`, - value: { - [optimisticReportAction.reportActionID]: { - pendingAction: null, - }, - }, - }, - ]; - - const failureData = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`, - value: { - [expenseReport.reportActionID]: { - errors: ErrorUtils.getMicroSecondOnyxError('iou.error.other'), - }, - }, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`, - value: { - statusNum: CONST.REPORT.STATUS.REIMBURSED, - }, - }, - ...(chatReport.reportID - ? [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, - value: { - hasOutstandingIOU: false, - hasOutstandingChildRequest: false, - iouReportID: 0, - }, - }, - ] - : []), - ]; - - API.write( - 'CancelPayment', - { - reportID: expenseReport.reportID, - managerAccountID: expenseReport.managerID, - reportActionID: optimisticReportAction.reportActionID, - }, - {optimisticData, successData, failureData}, - ); -} - /** * @param {String} paymentType * @param {Object} chatReport @@ -3536,5 +3434,4 @@ export { detachReceipt, getIOUReportID, editMoneyRequest, - cancelPayment, }; diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index a5d2aece9808..57627d819197 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -37,6 +37,7 @@ import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; 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 ModifiedExpenseMessage from '@libs/ModifiedExpenseMessage'; @@ -421,7 +422,10 @@ function ReportActionItem(props) { ); } else if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENTDEQUEUED) { - children = ; + const submitterDisplayName = PersonalDetailsUtils.getDisplayNameOrDefault(lodashGet(personalDetails, [props.report.ownerAccountID, 'displayName'])); + const amount = CurrencyUtils.convertToDisplayString(props.report.total, props.report.currency); + + children = ; } else if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE) { children = ; } else { diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index 5ed696a9019b..767f724dd571 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -43,15 +43,10 @@ type IOUMessage = { participantAccountIDs?: number[]; type: ValueOf; paymentType?: DeepValueOf; - cancellationReason?: string; /** Only exists when we are sending money */ IOUDetails?: IOUDetails; }; -type ReimbursementDeQueuedMessage = { - cancellationReason: string; -}; - type OriginalMessageIOU = { actionName: typeof CONST.REPORT.ACTIONS.TYPE.IOU; originalMessage: IOUMessage; @@ -265,7 +260,6 @@ export type { Reaction, ActionName, IOUMessage, - ReimbursementDeQueuedMessage, Closed, OriginalMessageActionName, ChangeLog, diff --git a/src/types/onyx/ReportAction.ts b/src/types/onyx/ReportAction.ts index cea5a5a570b5..a881b63fbb95 100644 --- a/src/types/onyx/ReportAction.ts +++ b/src/types/onyx/ReportAction.ts @@ -52,9 +52,6 @@ type Message = { /** ID of a task report */ taskReportID?: string; - - /** Reason pf payment cancellation */ - cancellationReason?: string; }; type ImageMetadata = {