diff --git a/src/components/MoneyRequestDetails.js b/src/components/MoneyRequestDetails.js index 358ba03e075a..f8c371aa5a58 100644 --- a/src/components/MoneyRequestDetails.js +++ b/src/components/MoneyRequestDetails.js @@ -26,6 +26,7 @@ import MenuItemWithTopDescription from './MenuItemWithTopDescription'; import DateUtils from '../libs/DateUtils'; import reportPropTypes from '../pages/reportPropTypes'; import * as UserUtils from '../libs/UserUtils'; +import OfflineWithFeedback from './OfflineWithFeedback'; const propTypes = { /** The report currently being looked at */ @@ -91,105 +92,112 @@ function MoneyRequestDetails(props) { const shouldShowSettlementButton = !isSettled && !props.isSingleTransactionView && isPayer; const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport); const shouldShowPaypal = Boolean(lodashGet(props.personalDetails, [moneyRequestReport.ownerAccountID, 'payPalMeAddress'])); + const {addWorkspaceRoomOrChatPendingAction, addWorkspaceRoomOrChatErrors} = ReportUtils.getReportOfflinePendingActionAndErrors(props.report); return ( - - - {props.translate('common.to')} - - - - - - {payeeName} - - {isExpenseReport && ( + + + + {props.translate('common.to')} + + + + - {props.translate('workspace.common.workspace')} + {payeeName} + {isExpenseReport && ( + + {props.translate('workspace.common.workspace')} + + )} + + + + {!props.isSingleTransactionView && {formattedAmount}} + {!props.isSingleTransactionView && isSettled && ( + + + + )} + {shouldShowSettlementButton && !props.isSmallScreenWidth && ( + + IOU.payMoneyRequest(paymentType, props.chatReport, props.report)} + enablePaymentsRoute={ROUTES.BANK_ACCOUNT_NEW} + addBankAccountRoute={bankAccountRoute} + shouldShowPaymentOptions + /> + )} - - {!props.isSingleTransactionView && {formattedAmount}} - {!props.isSingleTransactionView && isSettled && ( - - - - )} - {shouldShowSettlementButton && !props.isSmallScreenWidth && ( - - IOU.payMoneyRequest(paymentType, props.chatReport, props.report)} - enablePaymentsRoute={ROUTES.BANK_ACCOUNT_NEW} - addBankAccountRoute={bankAccountRoute} - shouldShowPaymentOptions - /> - - )} - + {shouldShowSettlementButton && props.isSmallScreenWidth && ( + IOU.payMoneyRequest(paymentType, props.chatReport, props.report)} + enablePaymentsRoute={ROUTES.BANK_ACCOUNT_NEW} + addBankAccountRoute={bankAccountRoute} + shouldShowPaymentOptions + /> + )} - {shouldShowSettlementButton && props.isSmallScreenWidth && ( - IOU.payMoneyRequest(paymentType, props.chatReport, props.report)} - enablePaymentsRoute={ROUTES.BANK_ACCOUNT_NEW} - addBankAccountRoute={bankAccountRoute} - shouldShowPaymentOptions - /> + {props.isSingleTransactionView && ( + <> + Navigation.navigate(ROUTES.getEditRequestRoute(props.report.reportID, CONST.EDIT_REQUEST_FIELD.AMOUNT))} + /> + Navigation.navigate(ROUTES.getEditRequestRoute(props.report.reportID, CONST.EDIT_REQUEST_FIELD.DESCRIPTION))} + /> + Navigation.navigate(ROUTES.getEditRequestRoute(props.report.reportID, CONST.EDIT_REQUEST_FIELD.DATE))} + /> + )} - {props.isSingleTransactionView && ( - <> - Navigation.navigate(ROUTES.getEditRequestRoute(props.report.reportID, CONST.EDIT_REQUEST_FIELD.AMOUNT))} - /> - Navigation.navigate(ROUTES.getEditRequestRoute(props.report.reportID, CONST.EDIT_REQUEST_FIELD.DESCRIPTION))} - /> - Navigation.navigate(ROUTES.getEditRequestRoute(props.report.reportID, CONST.EDIT_REQUEST_FIELD.DATE))} - /> - - )} - + ); } diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 00b8753a405f..3b6928b15238 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2486,6 +2486,19 @@ function getOriginalReportID(reportID, reportAction) { return isThreadFirstChat(reportAction, reportID) ? lodashGet(allReports, [`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, 'parentReportID']) : reportID; } +/** + * Return the pendingAction and the errors when we have creating a chat or a workspace room offline + * @param {Object} report + * @returns {Object} pending action , errors + */ +function getReportOfflinePendingActionAndErrors(report) { + // We are either adding a workspace room, or we're creating a chat, it isn't possible for both of these to be pending, or to have errors for the same report at the same time, so + // simply looking up the first truthy value for each case will get the relevant property if it's set. + const addWorkspaceRoomOrChatPendingAction = lodashGet(report, 'pendingFields.addWorkspaceRoom') || lodashGet(report, 'pendingFields.createChat'); + const addWorkspaceRoomOrChatErrors = lodashGet(report, 'errorFields.addWorkspaceRoom') || lodashGet(report, 'errorFields.createChat'); + return {addWorkspaceRoomOrChatPendingAction, addWorkspaceRoomOrChatErrors}; +} + export { getReportParticipantsTitle, isReportMessageAttachment, @@ -2589,4 +2602,5 @@ export { shouldHideComposer, getOriginalReportID, canAccessReport, + getReportOfflinePendingActionAndErrors, }; diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 4571e5318a8b..aa8a9e89822c 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -232,11 +232,8 @@ class ReportScreen extends React.Component { } render() { - // We are either adding a workspace room, or we're creating a chat, it isn't possible for both of these to be pending, or to have errors for the same report at the same time, so - // simply looking up the first truthy value for each case will get the relevant property if it's set. const reportID = getReportID(this.props.route); - const addWorkspaceRoomOrChatPendingAction = lodashGet(this.props.report, 'pendingFields.addWorkspaceRoom') || lodashGet(this.props.report, 'pendingFields.createChat'); - const addWorkspaceRoomOrChatErrors = lodashGet(this.props.report, 'errorFields.addWorkspaceRoom') || lodashGet(this.props.report, 'errorFields.createChat'); + const {addWorkspaceRoomOrChatPendingAction, addWorkspaceRoomOrChatErrors} = ReportUtils.getReportOfflinePendingActionAndErrors(this.props.report); const screenWrapperStyle = [styles.appContent, styles.flex1, {marginTop: this.props.viewportOffsetTop}]; // There are no reportActions at all to display and we are still in the process of loading the next set of actions.