From 528ff66d8f460e99fb753c2ea1739bc53d9a50e4 Mon Sep 17 00:00:00 2001 From: Alberto Date: Wed, 6 Dec 2023 12:19:28 +0100 Subject: [PATCH 01/33] show option in menu --- src/components/MoneyReportHeader.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/components/MoneyReportHeader.js b/src/components/MoneyReportHeader.js index 880e46b2592a..472d955c89c4 100644 --- a/src/components/MoneyReportHeader.js +++ b/src/components/MoneyReportHeader.js @@ -23,6 +23,9 @@ import MoneyReportHeaderStatusBar from './MoneyReportHeaderStatusBar'; import participantPropTypes from './participantPropTypes'; import SettlementButton from './SettlementButton'; import withWindowDimensions, {windowDimensionsPropTypes} from './withWindowDimensions'; +import * as TransactionUtils from "@libs/TransactionUtils"; +import * as Expensicons from "@components/Icon/Expensicons"; +import * as HeaderUtils from "@libs/HeaderUtils"; const propTypes = { /** The report currently being looked at */ @@ -78,6 +81,15 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt const isManager = ReportUtils.isMoneyRequestReport(moneyRequestReport) && lodashGet(session, 'accountID', null) === moneyRequestReport.managerID; const isPayer = policyType === CONST.POLICY.TYPE.CORPORATE ? isPolicyAdmin && isApproved : isPolicyAdmin || (ReportUtils.isMoneyRequestReport(moneyRequestReport) && isManager); const isDraft = ReportUtils.isDraftExpenseReport(moneyRequestReport); + + const threeDotsMenuItems = []; + if (isPayer && isSettled) { + threeDotsMenuItems.push({ + icon: Expensicons.Trashcan, + text: 'Cancel payment', + }); + } + const shouldShowThreeDotsButton = !!threeDotsMenuItems.length; const shouldShowSettlementButton = useMemo( () => isPayer && !isDraft && !isSettled && !moneyRequestReport.isWaitingOnBankAccount && reimbursableTotal !== 0 && !ReportUtils.isArchivedRoom(chatReport), [isPayer, isDraft, isSettled, moneyRequestReport, reimbursableTotal, chatReport], @@ -101,6 +113,8 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt Date: Wed, 6 Dec 2023 12:22:41 +0100 Subject: [PATCH 02/33] display menu in the right spot --- src/components/MoneyReportHeader.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/MoneyReportHeader.js b/src/components/MoneyReportHeader.js index 472d955c89c4..e188731671ea 100644 --- a/src/components/MoneyReportHeader.js +++ b/src/components/MoneyReportHeader.js @@ -26,6 +26,7 @@ import withWindowDimensions, {windowDimensionsPropTypes} from './withWindowDimen import * as TransactionUtils from "@libs/TransactionUtils"; import * as Expensicons from "@components/Icon/Expensicons"; import * as HeaderUtils from "@libs/HeaderUtils"; +import useWindowDimensions from "@hooks/useWindowDimensions"; const propTypes = { /** The report currently being looked at */ @@ -71,6 +72,7 @@ const defaultProps = { }; function MoneyReportHeader({session, personalDetails, policy, chatReport, nextStep, report: moneyRequestReport, isSmallScreenWidth}) { + const {windowWidth} = useWindowDimensions(); const styles = useThemeStyles(); const {translate} = useLocalize(); const reimbursableTotal = ReportUtils.getMoneyRequestReimbursableTotal(moneyRequestReport); @@ -115,6 +117,7 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt shouldEnableDetailPageNavigation shouldShowThreeDotsButton = {shouldShowThreeDotsButton} threeDotsMenuItems = {threeDotsMenuItems} + threeDotsAnchorPosition={styles.threeDotsPopoverOffset(windowWidth)} shouldShowPinButton={false} report={moneyRequestReport} policy={policy} From af4693730ed397fd6fdcaacc856b25ab5e636fb5 Mon Sep 17 00:00:00 2001 From: Alberto Date: Wed, 6 Dec 2023 12:23:19 +0100 Subject: [PATCH 03/33] extra imports --- src/components/MoneyReportHeader.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/components/MoneyReportHeader.js b/src/components/MoneyReportHeader.js index e188731671ea..4744a276c417 100644 --- a/src/components/MoneyReportHeader.js +++ b/src/components/MoneyReportHeader.js @@ -23,10 +23,8 @@ import MoneyReportHeaderStatusBar from './MoneyReportHeaderStatusBar'; import participantPropTypes from './participantPropTypes'; import SettlementButton from './SettlementButton'; import withWindowDimensions, {windowDimensionsPropTypes} from './withWindowDimensions'; -import * as TransactionUtils from "@libs/TransactionUtils"; -import * as Expensicons from "@components/Icon/Expensicons"; -import * as HeaderUtils from "@libs/HeaderUtils"; -import useWindowDimensions from "@hooks/useWindowDimensions"; +import * as Expensicons from '@components/Icon/Expensicons'; +import useWindowDimensions from '@hooks/useWindowDimensions'; const propTypes = { /** The report currently being looked at */ From a76ca3cb8c56fe63337186ac423a47332d0dc171 Mon Sep 17 00:00:00 2001 From: Alberto Date: Wed, 6 Dec 2023 13:08:40 +0100 Subject: [PATCH 04/33] changing branch --- src/components/MoneyReportHeader.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/components/MoneyReportHeader.js b/src/components/MoneyReportHeader.js index 4744a276c417..c4c6b9ed8974 100644 --- a/src/components/MoneyReportHeader.js +++ b/src/components/MoneyReportHeader.js @@ -25,6 +25,7 @@ import SettlementButton from './SettlementButton'; import withWindowDimensions, {windowDimensionsPropTypes} from './withWindowDimensions'; import * as Expensicons from '@components/Icon/Expensicons'; import useWindowDimensions from '@hooks/useWindowDimensions'; +import {useCallback, useState} from "@types/react"; const propTypes = { /** The report currently being looked at */ @@ -81,6 +82,12 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt const isManager = ReportUtils.isMoneyRequestReport(moneyRequestReport) && lodashGet(session, 'accountID', null) === moneyRequestReport.managerID; const isPayer = policyType === CONST.POLICY.TYPE.CORPORATE ? isPolicyAdmin && isApproved : isPolicyAdmin || (ReportUtils.isMoneyRequestReport(moneyRequestReport) && isManager); const isDraft = ReportUtils.isDraftExpenseReport(moneyRequestReport); + const [isConfirmModalVisible, setIsConfirmModalVisible] = useState(false); + + const cancelPayment = useCallback(() => { + // IOU.CancelPayment + setIsConfirmModalVisible(false); + }, [setIsConfirmModalVisible]); const threeDotsMenuItems = []; if (isPayer && isSettled) { From 8912f19231a4cb8c3a5aaf13f7774f3db7b853cc Mon Sep 17 00:00:00 2001 From: Alberto Date: Wed, 6 Dec 2023 14:06:35 +0100 Subject: [PATCH 05/33] Add confirm modal --- src/components/MoneyReportHeader.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/MoneyReportHeader.js b/src/components/MoneyReportHeader.js index c4c6b9ed8974..c2ae58da68fc 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, {useMemo} from 'react'; +import React, {useMemo, useCallback, useState} from 'react'; import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; @@ -25,7 +25,7 @@ import SettlementButton from './SettlementButton'; import withWindowDimensions, {windowDimensionsPropTypes} from './withWindowDimensions'; import * as Expensicons from '@components/Icon/Expensicons'; import useWindowDimensions from '@hooks/useWindowDimensions'; -import {useCallback, useState} from "@types/react"; +import ConfirmModal from "@components/ConfirmModal"; const propTypes = { /** The report currently being looked at */ @@ -94,6 +94,7 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt threeDotsMenuItems.push({ icon: Expensicons.Trashcan, text: 'Cancel payment', + onSelected: () => setIsConfirmModalVisible(true), }); } const shouldShowThreeDotsButton = !!threeDotsMenuItems.length; @@ -213,6 +214,16 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt )} + setIsConfirmModalVisible(false)} + prompt={translate('iou.deleteConfirmation')} + confirmText={translate('common.delete')} + cancelText={translate('common.cancel')} + danger + /> ); } From 74185830e0804ad9d65a2268edaf502599a16a7b Mon Sep 17 00:00:00 2001 From: Alberto Date: Wed, 6 Dec 2023 14:11:49 +0100 Subject: [PATCH 06/33] Right wording --- src/components/MoneyReportHeader.js | 8 ++++---- src/languages/en.ts | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/MoneyReportHeader.js b/src/components/MoneyReportHeader.js index c2ae58da68fc..bf37f79a9d33 100644 --- a/src/components/MoneyReportHeader.js +++ b/src/components/MoneyReportHeader.js @@ -215,13 +215,13 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt )} setIsConfirmModalVisible(false)} - prompt={translate('iou.deleteConfirmation')} - confirmText={translate('common.delete')} - cancelText={translate('common.cancel')} + 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 817f06f6b344..f746529d1ce2 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -94,6 +94,7 @@ type AllCountries = Record; export default { common: { cancel: 'Cancel', + dismiss: 'Dismiss', yes: 'Yes', no: 'No', ok: 'OK', @@ -541,6 +542,8 @@ 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', From f77c18b89f7ed4c20bdb64be232488b46d62a284 Mon Sep 17 00:00:00 2001 From: Alberto Date: Wed, 6 Dec 2023 14:14:08 +0100 Subject: [PATCH 07/33] spanish --- src/languages/es.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/languages/es.ts b/src/languages/es.ts index b219021daa0f..eb623b5c7c86 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -84,6 +84,7 @@ import type { export default { common: { cancel: 'Cancelar', + dismiss: 'Descartar', yes: 'Sí', no: 'No', ok: 'OK', @@ -533,6 +534,8 @@ 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ó', From 1fb616d1c4aa5ab2aa60c72b051cc641df819537 Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 7 Dec 2023 14:10:09 +0100 Subject: [PATCH 08/33] add cancel reason --- src/CONST.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/CONST.ts b/src/CONST.ts index 283195562e49..6872f4c463fa 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -571,6 +571,9 @@ const CONST = { }, }, }, + CANCEL_PAYMENT_REASONS: { + ADMIN: 'CANCEL_REASON_ADMIN', + }, ARCHIVE_REASON: { DEFAULT: 'default', ACCOUNT_CLOSED: 'accountClosed', From f61795423108be5113afe0901c6833f4a649cd85 Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 7 Dec 2023 14:16:56 +0100 Subject: [PATCH 09/33] build optimistic report action --- src/libs/ReportUtils.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 23382e87936a..b5b9e7c7c228 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -177,6 +177,11 @@ type OptimisticSubmittedReportAction = Pick< 'actionName' | 'actorAccountID' | 'automatic' | 'avatar' | 'isAttachment' | 'originalMessage' | 'message' | 'person' | 'reportActionID' | 'shouldShow' | 'created' | 'pendingAction' >; +type OptimisticCancelPaymentReportAction = Pick< + ReportAction, + 'actionName' | 'actorAccountID' | 'message' | 'person' | 'reportActionID' | 'shouldShow' | 'created' | 'pendingAction' + >; + type OptimisticEditedTaskReportAction = Pick< ReportAction, 'reportActionID' | 'actionName' | 'pendingAction' | 'actorAccountID' | 'automatic' | 'avatar' | 'created' | 'shouldShow' | 'message' | 'person' @@ -2870,6 +2875,32 @@ function buildOptimisticSubmittedReportAction(amount: number, currency: string, }; } +/** + * Builds an optimistic SUBMITTED report action with a randomly generated reportActionID. + * + */ +function buildOptimisticCancelPaymentReportAction(expenseReportID: string): OptimisticCancelPaymentReportAction { + + return { + actionName: CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENTDEQUEUED, + actorAccountID: currentUserAccountID, + message: { + 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. * @@ -4353,6 +4384,7 @@ export { buildOptimisticApprovedReportAction, buildOptimisticMovedReportAction, buildOptimisticSubmittedReportAction, + buildOptimisticCancelPaymentReportAction, buildOptimisticExpenseReport, buildOptimisticIOUReportAction, buildOptimisticReportPreview, From c454e5620534a9119a4e3e4d8f967097bd854778 Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 7 Dec 2023 14:50:55 +0100 Subject: [PATCH 10/33] add optimistic dat --- src/libs/ReportUtils.ts | 4 ++-- src/libs/actions/IOU.js | 47 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index b5b9e7c7c228..925966541305 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2876,10 +2876,10 @@ function buildOptimisticSubmittedReportAction(amount: number, currency: string, } /** - * Builds an optimistic SUBMITTED report action with a randomly generated reportActionID. + * Builds an optimistic REIMBURSEMENTDEQUEUED report action with a randomly generated reportActionID. * */ -function buildOptimisticCancelPaymentReportAction(expenseReportID: string): OptimisticCancelPaymentReportAction { +function buildOptimisticCancelPaymentReportAction(): OptimisticCancelPaymentReportAction { return { actionName: CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENTDEQUEUED, diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index ed43569c360a..3c56a72db4d2 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -2734,6 +2734,53 @@ function submitReport(expenseReport) { ); } +/** + * @param {Object} expenseReport + */ +function cancelPayment(expenseReport, chatReport) { + const optimisticReportAction = ReportUtils.buildOptimisticCancelPaymentReportAction()); + const policy = ReportUtils.getPolicy(chatReport.policyID); + const isFree = policy && policy.isFree(); + 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, + }, + }, + ] + : []), + ]; +} + /** * @param {String} paymentType * @param {Object} chatReport From 41b6cef4b7a52250d6d5b9f2f3329fefd99a180e Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 7 Dec 2023 14:58:06 +0100 Subject: [PATCH 11/33] add success data --- src/libs/actions/IOU.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 3c56a72db4d2..6b746793ca06 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -2736,9 +2736,10 @@ function submitReport(expenseReport) { /** * @param {Object} expenseReport + * @param {Object} chatReport */ function cancelPayment(expenseReport, chatReport) { - const optimisticReportAction = ReportUtils.buildOptimisticCancelPaymentReportAction()); + const optimisticReportAction = ReportUtils.buildOptimisticCancelPaymentReportAction(); const policy = ReportUtils.getPolicy(chatReport.policyID); const isFree = policy && policy.isFree(); const optimisticData = [ @@ -2779,6 +2780,19 @@ function cancelPayment(expenseReport, chatReport) { ] : []), ]; + + const successData = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`, + value: { + [optimisticReportAction.reportActionID]: { + pendingAction: null, + }, + }, + }, + ]; + } /** From 8cd3e9a4ab5442ef9a05d8c1183a8aea31d7f961 Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 7 Dec 2023 15:04:50 +0100 Subject: [PATCH 12/33] add failureData --- src/libs/actions/IOU.js | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 6b746793ca06..2063933e6d2e 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -2792,7 +2792,38 @@ function cancelPayment(expenseReport, chatReport) { }, }, ]; - + + 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, + }, + }, + ] + : []), + ]; } /** From 5ec2dd0858877ec80d5238b62eb45a2f12b882fe Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 7 Dec 2023 15:05:38 +0100 Subject: [PATCH 13/33] call command --- src/libs/actions/IOU.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 2063933e6d2e..8f1fe6589bca 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -2824,6 +2824,16 @@ function cancelPayment(expenseReport, chatReport) { ] : []), ]; + + API.write( + 'CancelPayment', + { + reportID: expenseReport.reportID, + managerAccountID: expenseReport.managerID, + reportActionID: optimisticReportAction.reportActionID, + }, + {optimisticData, successData, failureData}, + ); } /** From ca24ff49bf5f1276bb582f85ee2f8d75bace8996 Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 7 Dec 2023 15:52:26 +0100 Subject: [PATCH 14/33] Connect everything --- src/components/MoneyReportHeader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MoneyReportHeader.js b/src/components/MoneyReportHeader.js index bf37f79a9d33..d5b72d78b761 100644 --- a/src/components/MoneyReportHeader.js +++ b/src/components/MoneyReportHeader.js @@ -85,7 +85,7 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt const [isConfirmModalVisible, setIsConfirmModalVisible] = useState(false); const cancelPayment = useCallback(() => { - // IOU.CancelPayment + IOU.CancelPayment(moneyRequestReport, chatReport); setIsConfirmModalVisible(false); }, [setIsConfirmModalVisible]); From 4c866cd4c0a4e45e2f197538853fa29e8ff38cde Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 7 Dec 2023 17:07:44 +0100 Subject: [PATCH 15/33] couple of fixes --- src/components/MoneyReportHeader.js | 2 +- src/libs/actions/IOU.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/MoneyReportHeader.js b/src/components/MoneyReportHeader.js index d5b72d78b761..917f61f85530 100644 --- a/src/components/MoneyReportHeader.js +++ b/src/components/MoneyReportHeader.js @@ -85,7 +85,7 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt const [isConfirmModalVisible, setIsConfirmModalVisible] = useState(false); const cancelPayment = useCallback(() => { - IOU.CancelPayment(moneyRequestReport, chatReport); + IOU.cancelPayment(moneyRequestReport, chatReport); setIsConfirmModalVisible(false); }, [setIsConfirmModalVisible]); diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 8f1fe6589bca..5bc369e2aaaf 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -2741,7 +2741,7 @@ function submitReport(expenseReport) { function cancelPayment(expenseReport, chatReport) { const optimisticReportAction = ReportUtils.buildOptimisticCancelPaymentReportAction(); const policy = ReportUtils.getPolicy(chatReport.policyID); - const isFree = policy && policy.isFree(); + const isFree = policy && policy.type === CONST.POLICY.TYPE.FREE; const optimisticData = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -3118,4 +3118,5 @@ export { detachReceipt, getIOUReportID, editMoneyRequest, + cancelPayment, }; From d884d83256a1cec7465dcd1ba0ba18bd68e8d08d Mon Sep 17 00:00:00 2001 From: Alberto Date: Tue, 12 Dec 2023 14:27:04 +0100 Subject: [PATCH 16/33] change branch --- src/libs/ReportUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 925966541305..1577d79ea87a 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2884,9 +2884,9 @@ function buildOptimisticCancelPaymentReportAction(): OptimisticCancelPaymentRepo return { actionName: CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENTDEQUEUED, actorAccountID: currentUserAccountID, - message: { + message: [{ cancellationReason: CONST.REPORT.CANCEL_PAYMENT_REASONS.ADMIN - }, + }], person: [ { style: 'strong', From d0f78fbbb10612b13af1ecf563e479cec258533a Mon Sep 17 00:00:00 2001 From: Alberto Date: Wed, 13 Dec 2023 15:39:04 +0100 Subject: [PATCH 17/33] show right message --- src/components/MoneyReportHeader.js | 1 + src/languages/en.ts | 2 ++ src/languages/types.ts | 3 +++ src/libs/OptionsListUtils.js | 2 +- src/libs/ReportUtils.ts | 9 ++++++--- src/pages/home/report/ReportActionItem.js | 6 ++---- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/components/MoneyReportHeader.js b/src/components/MoneyReportHeader.js index 917f61f85530..09d81196506d 100644 --- a/src/components/MoneyReportHeader.js +++ b/src/components/MoneyReportHeader.js @@ -26,6 +26,7 @@ import withWindowDimensions, {windowDimensionsPropTypes} from './withWindowDimen import * as Expensicons from '@components/Icon/Expensicons'; import useWindowDimensions from '@hooks/useWindowDimensions'; import ConfirmModal from "@components/ConfirmModal"; +import * as ReportActionsUtils from "@libs/ReportActionsUtils"; const propTypes = { /** The report currently being looked at */ diff --git a/src/languages/en.ts b/src/languages/en.ts index f746529d1ce2..696bf468d69d 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -10,6 +10,7 @@ import type { BeginningOfChatHistoryAnnounceRoomPartTwo, BeginningOfChatHistoryDomainRoomPartOneParams, CanceledRequestParams, + AdminCanceledRequestParams, CharacterLimitParams, ConfirmThatParams, DateShouldBeAfterParams, @@ -577,6 +578,7 @@ 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`, + 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/types.ts b/src/languages/types.ts index 9f66dc6f97ec..d462eecefcc9 100644 --- a/src/languages/types.ts +++ b/src/languages/types.ts @@ -127,6 +127,8 @@ 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}; @@ -285,6 +287,7 @@ export type { PayerSettledParams, WaitingOnBankAccountParams, CanceledRequestParams, + AdminCanceledRequestParams, SettledAfterAddedBankAccountParams, PaidElsewhereWithAmountParams, PaidWithExpensifyWithAmountParams, diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 4678ce395f76..bb13db38f313 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -398,7 +398,7 @@ function getLastMessageTextForReport(report) { } else if (ReportActionUtils.isReimbursementQueuedAction(lastReportAction)) { lastMessageTextFromReport = ReportUtils.getReimbursementQueuedActionMessage(lastReportAction, report); } else if (ReportActionUtils.isReimbursementDeQueuedAction(lastReportAction)) { - lastMessageTextFromReport = ReportUtils.getReimbursementDeQueuedActionMessage(report); + lastMessageTextFromReport = ReportUtils.getReimbursementDeQueuedActionMessage(lastReportAction, 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 1577d79ea87a..ab0be2981e76 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1501,10 +1501,13 @@ function getReimbursementQueuedActionMessage(reportAction: OnyxEntry): string { +function getReimbursementDeQueuedActionMessage(reportAction: OnyxEntry, report: OnyxEntry): string { + const amount = CurrencyUtils.convertToDisplayString(Math.abs(report?.total ?? 0), report?.currency); + if (reportAction.message?.[0]?.cancellationReason === CONST.REPORT.CANCEL_PAYMENT_REASONS.ADMIN) { + console.log('here'); + return Localize.translateLocal('iou.adminCanceledRequest', {amount}); + } const submitterDisplayName = getDisplayNameForParticipant(report?.ownerAccountID, true) ?? ''; - const amount = CurrencyUtils.convertToDisplayString(report?.total ?? 0, report?.currency); - return Localize.translateLocal('iou.canceledRequest', {submitterDisplayName, amount}); } diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 92bb370155c9..10de70fad7aa 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -75,6 +75,7 @@ import ReportActionItemSingle from './ReportActionItemSingle'; import ReportActionItemThread from './ReportActionItemThread'; import reportActionPropTypes from './reportActionPropTypes'; import ReportAttachmentsContext from './ReportAttachmentsContext'; +import {getReimbursementDeQueuedActionMessage} from "@libs/ReportUtils"; const propTypes = { ...windowDimensionsPropTypes, @@ -417,10 +418,7 @@ function ReportActionItem(props) { ); } 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 = ; + children = ; } else if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE) { children = ; } else { From 09cfe4a3c6f776a1319abbd6962c21135e71d145 Mon Sep 17 00:00:00 2001 From: Alberto Date: Wed, 13 Dec 2023 15:54:30 +0100 Subject: [PATCH 18/33] add original message --- src/libs/ReportUtils.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ab0be2981e76..969d8483c176 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1503,8 +1503,7 @@ function getReimbursementQueuedActionMessage(reportAction: OnyxEntry, report: OnyxEntry): string { const amount = CurrencyUtils.convertToDisplayString(Math.abs(report?.total ?? 0), report?.currency); - if (reportAction.message?.[0]?.cancellationReason === CONST.REPORT.CANCEL_PAYMENT_REASONS.ADMIN) { - console.log('here'); + if (reportAction.originalMessage?.cancellationReason === CONST.REPORT.CANCEL_PAYMENT_REASONS.ADMIN) { return Localize.translateLocal('iou.adminCanceledRequest', {amount}); } const submitterDisplayName = getDisplayNameForParticipant(report?.ownerAccountID, true) ?? ''; @@ -2890,6 +2889,9 @@ function buildOptimisticCancelPaymentReportAction(): OptimisticCancelPaymentRepo message: [{ cancellationReason: CONST.REPORT.CANCEL_PAYMENT_REASONS.ADMIN }], + originalMessage: { + cancellationReason: CONST.REPORT.CANCEL_PAYMENT_REASONS.ADMIN + }, person: [ { style: 'strong', From 5e4fe74633715167f60998731fa6252bca158658 Mon Sep 17 00:00:00 2001 From: Alberto Date: Wed, 13 Dec 2023 16:19:11 +0100 Subject: [PATCH 19/33] style --- src/components/MoneyReportHeader.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/MoneyReportHeader.js b/src/components/MoneyReportHeader.js index 60194398f23f..6f21e09dc25d 100644 --- a/src/components/MoneyReportHeader.js +++ b/src/components/MoneyReportHeader.js @@ -25,8 +25,7 @@ import SettlementButton from './SettlementButton'; import withWindowDimensions, {windowDimensionsPropTypes} from './withWindowDimensions'; import * as Expensicons from '@components/Icon/Expensicons'; import useWindowDimensions from '@hooks/useWindowDimensions'; -import ConfirmModal from "@components/ConfirmModal"; -import * as ReportActionsUtils from "@libs/ReportActionsUtils"; +import ConfirmModal from '@components/ConfirmModal'; const propTypes = { /** The report currently being looked at */ From 76734d6d20bf0a10625a10c1d70e435703230357 Mon Sep 17 00:00:00 2001 From: Alberto Date: Wed, 13 Dec 2023 17:19:08 +0100 Subject: [PATCH 20/33] lint --- src/components/MoneyReportHeader.js | 8 ++++---- src/pages/home/report/ReportActionItem.js | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/components/MoneyReportHeader.js b/src/components/MoneyReportHeader.js index 6f21e09dc25d..03d1660d5f7e 100644 --- a/src/components/MoneyReportHeader.js +++ b/src/components/MoneyReportHeader.js @@ -17,15 +17,15 @@ import * as IOU from '@userActions/IOU'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import useWindowDimensions from '@hooks/useWindowDimensions'; +import * as Expensicons from './Icon/Expensicons'; +import ConfirmModal from './ConfirmModal'; import Button from './Button'; import HeaderWithBackButton from './HeaderWithBackButton'; import MoneyReportHeaderStatusBar from './MoneyReportHeaderStatusBar'; import participantPropTypes from './participantPropTypes'; import SettlementButton from './SettlementButton'; import withWindowDimensions, {windowDimensionsPropTypes} from './withWindowDimensions'; -import * as Expensicons from '@components/Icon/Expensicons'; -import useWindowDimensions from '@hooks/useWindowDimensions'; -import ConfirmModal from '@components/ConfirmModal'; const propTypes = { /** The report currently being looked at */ @@ -91,7 +91,7 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt const cancelPayment = useCallback(() => { IOU.cancelPayment(moneyRequestReport, chatReport); setIsConfirmModalVisible(false); - }, [setIsConfirmModalVisible]); + }, [setIsConfirmModalVisible, moneyRequestReport, chatReport]); const threeDotsMenuItems = []; if (isPayer && isSettled) { diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 274ba5fe5a7c..7af1d5f0b919 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -34,7 +34,6 @@ 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'; @@ -75,7 +74,6 @@ import ReportActionItemSingle from './ReportActionItemSingle'; import ReportActionItemThread from './ReportActionItemThread'; import reportActionPropTypes from './reportActionPropTypes'; import ReportAttachmentsContext from './ReportAttachmentsContext'; -import {getReimbursementDeQueuedActionMessage} from "@libs/ReportUtils"; const propTypes = { ...windowDimensionsPropTypes, From 75f13f1432d8ce2a419c4d054806d69c28848eaa Mon Sep 17 00:00:00 2001 From: Alberto Date: Wed, 13 Dec 2023 17:26:44 +0100 Subject: [PATCH 21/33] prettier --- src/components/MoneyReportHeader.js | 12 ++++----- src/languages/en.ts | 2 +- src/libs/ReportUtils.ts | 16 +++++------ src/libs/actions/IOU.js | 42 ++++++++++++++--------------- 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/components/MoneyReportHeader.js b/src/components/MoneyReportHeader.js index 03d1660d5f7e..45560e629136 100644 --- a/src/components/MoneyReportHeader.js +++ b/src/components/MoneyReportHeader.js @@ -1,10 +1,11 @@ import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; -import React, {useMemo, useCallback, useState} from 'react'; +import React, {useCallback, useMemo, useState} from 'react'; import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; import useLocalize from '@hooks/useLocalize'; +import useWindowDimensions from '@hooks/useWindowDimensions'; import compose from '@libs/compose'; import * as CurrencyUtils from '@libs/CurrencyUtils'; import Navigation from '@libs/Navigation/Navigation'; @@ -17,11 +18,10 @@ import * as IOU from '@userActions/IOU'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import useWindowDimensions from '@hooks/useWindowDimensions'; -import * as Expensicons from './Icon/Expensicons'; -import ConfirmModal from './ConfirmModal'; 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'; @@ -126,8 +126,8 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt ; -type OptimisticCancelPaymentReportAction = Pick< - ReportAction, - 'actionName' | 'actorAccountID' | 'message' | 'person' | 'reportActionID' | 'shouldShow' | 'created' | 'pendingAction' - >; +type OptimisticCancelPaymentReportAction = Pick; type OptimisticEditedTaskReportAction = Pick< ReportAction, @@ -2930,15 +2927,16 @@ function buildOptimisticSubmittedReportAction(amount: number, currency: string, * */ function buildOptimisticCancelPaymentReportAction(): OptimisticCancelPaymentReportAction { - return { actionName: CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENTDEQUEUED, actorAccountID: currentUserAccountID, - message: [{ - cancellationReason: CONST.REPORT.CANCEL_PAYMENT_REASONS.ADMIN - }], + message: [ + { + cancellationReason: CONST.REPORT.CANCEL_PAYMENT_REASONS.ADMIN, + }, + ], originalMessage: { - cancellationReason: CONST.REPORT.CANCEL_PAYMENT_REASONS.ADMIN + cancellationReason: CONST.REPORT.CANCEL_PAYMENT_REASONS.ADMIN, }, person: [ { diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 63130d6d67f2..286267b6fd6e 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -3034,17 +3034,17 @@ function cancelPayment(expenseReport, chatReport) { }, ...(chatReport.reportID ? [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, - value: { - ...chatReport, - hasOutstandingIOU: true, - hasOutstandingChildRequest: true, - iouReportID: expenseReport.reportID, - }, - }, - ] + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, + value: { + ...chatReport, + hasOutstandingIOU: true, + hasOutstandingChildRequest: true, + iouReportID: expenseReport.reportID, + }, + }, + ] : []), ]; @@ -3079,16 +3079,16 @@ function cancelPayment(expenseReport, chatReport) { }, ...(chatReport.reportID ? [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, - value: { - hasOutstandingIOU: false, - hasOutstandingChildRequest: false, - iouReportID: 0, - }, - }, - ] + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, + value: { + hasOutstandingIOU: false, + hasOutstandingChildRequest: false, + iouReportID: 0, + }, + }, + ] : []), ]; From aecf74374468f898a3abdad1ac89374fe8654224 Mon Sep 17 00:00:00 2001 From: Alberto Date: Wed, 13 Dec 2023 17:28:53 +0100 Subject: [PATCH 22/33] spanish --- src/languages/es.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/languages/es.ts b/src/languages/es.ts index 1b4bd419bb88..841e56e803a6 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -1,6 +1,7 @@ import CONST from '@src/CONST'; import type { AddressLineParams, + AdminCanceledRequestParams, AlreadySignedInParams, AmountEachParams, ApprovedAmountParams, @@ -580,6 +581,7 @@ 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) => From e598cdbac07fbc73e1a996c9babef738573378e9 Mon Sep 17 00:00:00 2001 From: Alberto Date: Wed, 13 Dec 2023 17:34:58 +0100 Subject: [PATCH 23/33] typescript BS --- src/libs/ReportUtils.ts | 2 +- src/types/onyx/OriginalMessage.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8fc6956fe1b3..5e2d86c28ab0 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1540,7 +1540,7 @@ function getReimbursementQueuedActionMessage(reportAction: OnyxEntry, report: OnyxEntry): string { const amount = CurrencyUtils.convertToDisplayString(Math.abs(report?.total ?? 0), report?.currency); - if (reportAction.originalMessage?.cancellationReason === CONST.REPORT.CANCEL_PAYMENT_REASONS.ADMIN) { + if (reportAction?.originalMessage?.cancellationReason === CONST.REPORT.CANCEL_PAYMENT_REASONS.ADMIN) { return Localize.translateLocal('iou.adminCanceledRequest', {amount}); } const submitterDisplayName = getDisplayNameForParticipant(report?.ownerAccountID, true) ?? ''; diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index 6123469aa813..1dac6911f0fd 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -42,6 +42,7 @@ type IOUMessage = { participantAccountIDs?: number[]; type: ValueOf; paymentType?: DeepValueOf; + cancellationReason?: string; /** Only exists when we are sending money */ IOUDetails?: IOUDetails; }; From d5a68ea7325f9771f85907c1d4777aae8cd2f519 Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 14 Dec 2023 12:02:28 +0100 Subject: [PATCH 24/33] more ts bs --- src/libs/ReportUtils.ts | 3 ++- src/types/onyx/OriginalMessage.ts | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 5e2d86c28ab0..a1a26c03947d 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -18,7 +18,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import {Beta, Login, PersonalDetails, PersonalDetailsList, Policy, PolicyTags, Report, ReportAction, Session, Transaction} from '@src/types/onyx'; import {Errors, Icon, PendingAction} from '@src/types/onyx/OnyxCommon'; -import {IOUMessage, OriginalMessageActionName, OriginalMessageCreated} from '@src/types/onyx/OriginalMessage'; +import {IOUMessage, OriginalMessageActionName, OriginalMessageCreated, ReimbursementDeQueuedMessage} 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'; @@ -1540,6 +1540,7 @@ 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 (reportAction?.originalMessage?.cancellationReason === CONST.REPORT.CANCEL_PAYMENT_REASONS.ADMIN) { return Localize.translateLocal('iou.adminCanceledRequest', {amount}); } diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index 1dac6911f0fd..aaf326df31b5 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -1,6 +1,7 @@ import {ValueOf} from 'type-fest'; import CONST from '@src/CONST'; import DeepValueOf from '@src/types/utils/DeepValueOf'; +import {getReimbursementDeQueuedActionMessage} from "@libs/ReportUtils"; type ActionName = DeepValueOf; type OriginalMessageActionName = @@ -47,6 +48,10 @@ type IOUMessage = { IOUDetails?: IOUDetails; }; +type ReimbursementDeQueuedMessage = { + cancellationReason: string; +}; + type OriginalMessageIOU = { actionName: typeof CONST.REPORT.ACTIONS.TYPE.IOU; originalMessage: IOUMessage; @@ -236,4 +241,4 @@ type OriginalMessage = | OriginalMessageMoved; export default OriginalMessage; -export type {ChronosOOOEvent, Decision, Reaction, ActionName, IOUMessage, Closed, OriginalMessageActionName, ChangeLog, OriginalMessageIOU, OriginalMessageCreated}; +export type {ChronosOOOEvent, Decision, Reaction, ActionName, IOUMessage, ReimbursementDeQueuedMessage, Closed, OriginalMessageActionName, ChangeLog, OriginalMessageIOU, OriginalMessageCreated}; From 1f66da612adb837bac5221ed27f8b91e7f7ac105 Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 14 Dec 2023 12:21:02 +0100 Subject: [PATCH 25/33] I hate typescript --- src/libs/ReportUtils.ts | 2 +- src/types/onyx/OriginalMessage.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index a1a26c03947d..3e095f8dbf21 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1541,7 +1541,7 @@ 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 (reportAction?.originalMessage?.cancellationReason === CONST.REPORT.CANCEL_PAYMENT_REASONS.ADMIN) { + if (originalMessage?.cancellationReason === CONST.REPORT.CANCEL_PAYMENT_REASONS.ADMIN) { return Localize.translateLocal('iou.adminCanceledRequest', {amount}); } const submitterDisplayName = getDisplayNameForParticipant(report?.ownerAccountID, true) ?? ''; diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index aaf326df31b5..c475ad00ce76 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -1,7 +1,6 @@ import {ValueOf} from 'type-fest'; import CONST from '@src/CONST'; import DeepValueOf from '@src/types/utils/DeepValueOf'; -import {getReimbursementDeQueuedActionMessage} from "@libs/ReportUtils"; type ActionName = DeepValueOf; type OriginalMessageActionName = From a9af4cc52fc0babc8463d8defdd9e05921a53aa9 Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 14 Dec 2023 12:49:57 +0100 Subject: [PATCH 26/33] prettier --- src/components/MoneyReportHeader.js | 2 +- src/types/onyx/OriginalMessage.ts | 14 +++++++++++++- src/types/onyx/ReportAction.ts | 3 +++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/components/MoneyReportHeader.js b/src/components/MoneyReportHeader.js index b184fe898758..887772ececb2 100644 --- a/src/components/MoneyReportHeader.js +++ b/src/components/MoneyReportHeader.js @@ -5,8 +5,8 @@ import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; import useLocalize from '@hooks/useLocalize'; -import useWindowDimensions from '@hooks/useWindowDimensions'; import useThemeStyles from '@hooks/useThemeStyles'; +import useWindowDimensions from '@hooks/useWindowDimensions'; import compose from '@libs/compose'; import * as CurrencyUtils from '@libs/CurrencyUtils'; import Navigation from '@libs/Navigation/Navigation'; diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index c475ad00ce76..c3b02f43c50b 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -240,4 +240,16 @@ type OriginalMessage = | OriginalMessageMoved; export default OriginalMessage; -export type {ChronosOOOEvent, Decision, Reaction, ActionName, IOUMessage, ReimbursementDeQueuedMessage, Closed, OriginalMessageActionName, ChangeLog, OriginalMessageIOU, OriginalMessageCreated}; +export type { + ChronosOOOEvent, + Decision, + Reaction, + ActionName, + IOUMessage, + ReimbursementDeQueuedMessage, + Closed, + OriginalMessageActionName, + ChangeLog, + OriginalMessageIOU, + OriginalMessageCreated, +}; diff --git a/src/types/onyx/ReportAction.ts b/src/types/onyx/ReportAction.ts index 8e56aaa67345..8eab73db39c0 100644 --- a/src/types/onyx/ReportAction.ts +++ b/src/types/onyx/ReportAction.ts @@ -52,6 +52,9 @@ type Message = { /** ID of a task report */ taskReportID?: string; + + /** Reason pf payment cancellation */ + cancellationReason?: string; }; type ImageMetadata = { From 79db9ba5536347e0b95c07bd1411a6f48ec3e7b8 Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 14 Dec 2023 13:07:38 +0100 Subject: [PATCH 27/33] typescript --- src/libs/ReportUtils.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 3e095f8dbf21..232400558fc5 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2938,6 +2938,8 @@ function buildOptimisticCancelPaymentReportAction(): OptimisticCancelPaymentRepo ], originalMessage: { cancellationReason: CONST.REPORT.CANCEL_PAYMENT_REASONS.ADMIN, + type: CONST.REPORT.MESSAGE.TYPE.COMMENT, + text: '' }, person: [ { From 7e6afbaa5de9151605885f43e7b44a3b432d0433 Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 14 Dec 2023 13:15:22 +0100 Subject: [PATCH 28/33] prettier again --- src/libs/ReportUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 232400558fc5..de8044a0e918 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2934,12 +2934,12 @@ function buildOptimisticCancelPaymentReportAction(): OptimisticCancelPaymentRepo message: [ { cancellationReason: CONST.REPORT.CANCEL_PAYMENT_REASONS.ADMIN, + type: CONST.REPORT.MESSAGE.TYPE.COMMENT, + text: '', }, ], originalMessage: { cancellationReason: CONST.REPORT.CANCEL_PAYMENT_REASONS.ADMIN, - type: CONST.REPORT.MESSAGE.TYPE.COMMENT, - text: '' }, person: [ { From 7f4bbf8411ffd4cd2d224bd717686cfa1db7a4e5 Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 14 Dec 2023 13:20:48 +0100 Subject: [PATCH 29/33] have I mentioned how much I hate typescript? --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index de8044a0e918..9d3546e1a6db 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -178,7 +178,7 @@ type OptimisticSubmittedReportAction = Pick< 'actionName' | 'actorAccountID' | 'automatic' | 'avatar' | 'isAttachment' | 'originalMessage' | 'message' | 'person' | 'reportActionID' | 'shouldShow' | 'created' | 'pendingAction' >; -type OptimisticCancelPaymentReportAction = Pick; +type OptimisticCancelPaymentReportAction = Pick; type OptimisticEditedTaskReportAction = Pick< ReportAction, From dc5723950a005bf72f37984d13bf605b6bd4d496 Mon Sep 17 00:00:00 2001 From: Alberto Date: Mon, 18 Dec 2023 14:01:27 +0100 Subject: [PATCH 30/33] remove setIsConfirmModalVisible --- src/components/MoneyReportHeader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MoneyReportHeader.js b/src/components/MoneyReportHeader.js index 887772ececb2..e21662147e40 100644 --- a/src/components/MoneyReportHeader.js +++ b/src/components/MoneyReportHeader.js @@ -91,7 +91,7 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt const cancelPayment = useCallback(() => { IOU.cancelPayment(moneyRequestReport, chatReport); setIsConfirmModalVisible(false); - }, [setIsConfirmModalVisible, moneyRequestReport, chatReport]); + }, [moneyRequestReport, chatReport]); const threeDotsMenuItems = []; if (isPayer && isSettled) { From e17f37aeca8a2ab9602d3d6bd2b50af9b3a750ac Mon Sep 17 00:00:00 2001 From: Alberto Date: Mon, 18 Dec 2023 14:01:40 +0100 Subject: [PATCH 31/33] believe it or not, prettier again --- src/libs/ReportUtils.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index de009a2c4dc6..9c3a0db08970 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -178,7 +178,10 @@ type OptimisticSubmittedReportAction = Pick< 'actionName' | 'actorAccountID' | 'automatic' | 'avatar' | 'isAttachment' | 'originalMessage' | 'message' | 'person' | 'reportActionID' | 'shouldShow' | 'created' | 'pendingAction' >; -type OptimisticCancelPaymentReportAction = Pick; +type OptimisticCancelPaymentReportAction = Pick< + ReportAction, + 'actionName' | 'actorAccountID' | 'message' | 'originalMessage' | 'person' | 'reportActionID' | 'shouldShow' | 'created' | 'pendingAction' +>; type OptimisticEditedTaskReportAction = Pick< ReportAction, From 063f842134f6a25c23e8273b3aa9c3efdb21e93d Mon Sep 17 00:00:00 2001 From: Alberto Date: Wed, 20 Dec 2023 11:07:58 +0100 Subject: [PATCH 32/33] lint --- src/components/MoneyReportHeader.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/MoneyReportHeader.js b/src/components/MoneyReportHeader.js index c1e74436c49e..ec1b1c83fc88 100644 --- a/src/components/MoneyReportHeader.js +++ b/src/components/MoneyReportHeader.js @@ -79,7 +79,6 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt 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); From 4b6e8343c0e096b0d08be213f5a79078ac219ce7 Mon Sep 17 00:00:00 2001 From: Alberto Date: Wed, 20 Dec 2023 12:54:31 +0100 Subject: [PATCH 33/33] 3 dots behavior --- src/components/MoneyReportHeader.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/components/MoneyReportHeader.js b/src/components/MoneyReportHeader.js index ec1b1c83fc88..e72f7d3576f5 100644 --- a/src/components/MoneyReportHeader.js +++ b/src/components/MoneyReportHeader.js @@ -98,15 +98,6 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt setIsConfirmModalVisible(false); }, [moneyRequestReport, chatReport]); - const threeDotsMenuItems = []; - if (isPayer && isSettled) { - threeDotsMenuItems.push({ - icon: Expensicons.Trashcan, - text: 'Cancel payment', - onSelected: () => setIsConfirmModalVisible(true), - }); - } - const shouldShowThreeDotsButton = !!threeDotsMenuItems.length; const shouldShowPayButton = useMemo( () => isPayer && !isDraft && !isSettled && !moneyRequestReport.isWaitingOnBankAccount && reimbursableTotal !== 0 && !ReportUtils.isArchivedRoom(chatReport), [isPayer, isDraft, isSettled, moneyRequestReport, reimbursableTotal, chatReport], @@ -127,6 +118,13 @@ 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, @@ -149,9 +147,6 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt