From 5b5e039e3bc00bf1bc6795d2bf65b1669e6a5f7f Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 15 Aug 2023 21:54:50 +0700 Subject: [PATCH 1/8] Hide transaction detail when the request is deleted --- src/pages/home/report/ReportActionItem.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index d182dc4c6bc3..1fc124d3e937 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -463,7 +463,7 @@ function ReportActionItem(props) { if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED) { const parentReportAction = ReportActionsUtils.getParentReportAction(props.report); - if (ReportActionsUtils.isTransactionThread(parentReportAction)) { + if (ReportActionsUtils.isTransactionThread(parentReportAction) && !ReportActionsUtils.isDeletedParentAction(parentReportAction)) { return ( ); } + if (ReportActionsUtils.isTransactionThread(parentReportAction) && ReportActionsUtils.isDeletedParentAction(parentReportAction)) { + return null; + } if (ReportUtils.isTaskReport(props.report)) { return ( From 1be995b0205a3cb488db9627560b7d705301f96e Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 15 Aug 2023 23:06:32 +0700 Subject: [PATCH 2/8] Dismiss modal when the request is paid or deleted --- src/pages/EditRequestPage.js | 17 +++++++++++++++-- src/pages/home/report/ReportActionItem.js | 4 ++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index 971ad056ae7e..ba9c089d8781 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, {useEffect} from 'react'; import PropTypes from 'prop-types'; import lodashGet from 'lodash/get'; import {withOnyx} from 'react-native-onyx'; @@ -38,7 +38,9 @@ const defaultProps = { }; function EditRequestPage({report, route}) { - const transactionID = lodashGet(ReportActionsUtils.getParentReportAction(report), 'originalMessage.IOUTransactionID', ''); + const parentReport = ReportUtils.getParentReport(report); + const parentReportAction = ReportActionsUtils.getParentReportAction(report); + const transactionID = lodashGet(parentReportAction, 'originalMessage.IOUTransactionID', ''); const transaction = TransactionUtils.getTransaction(transactionID); const transactionDescription = TransactionUtils.getDescription(transaction); const transactionAmount = TransactionUtils.getAmount(transaction, ReportUtils.isExpenseReport(ReportUtils.getParentReport(report))); @@ -49,6 +51,17 @@ function EditRequestPage({report, route}) { const transactionCreated = format(transactionCreatedDate, CONST.DATE.FNS_FORMAT_STRING); const fieldToEdit = lodashGet(route, ['params', 'field'], ''); + const isDeleted = ReportActionsUtils.isDeletedAction(parentReportAction); + const isSetted = ReportUtils.isSettled(parentReport.reportID); + + // Dismiss the modal when the request is paid or deleted + useEffect(() => { + if (!isDeleted && !isSetted) { + return; + } + Navigation.dismissModal(); + }, [isDeleted, isSetted]); + // Update the transaction object and close the modal function editMoneyRequest(transactionChanges) { IOU.editMoneyRequest(transactionID, report.reportID, transactionChanges); diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 1fc124d3e937..b9d0367152b5 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -463,7 +463,7 @@ function ReportActionItem(props) { if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED) { const parentReportAction = ReportActionsUtils.getParentReportAction(props.report); - if (ReportActionsUtils.isTransactionThread(parentReportAction) && !ReportActionsUtils.isDeletedParentAction(parentReportAction)) { + if (ReportActionsUtils.isTransactionThread(parentReportAction) && !ReportActionsUtils.isDeletedAction(parentReportAction)) { return ( ); } - if (ReportActionsUtils.isTransactionThread(parentReportAction) && ReportActionsUtils.isDeletedParentAction(parentReportAction)) { + if (ReportActionsUtils.isTransactionThread(parentReportAction) && ReportActionsUtils.isDeletedAction(parentReportAction)) { return null; } if (ReportUtils.isTaskReport(props.report)) { From 9ad54237a009ce110f96afa8a7b1e338f3c280d5 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 15 Aug 2023 23:26:32 +0700 Subject: [PATCH 3/8] return null if request is deleted --- src/components/ReportActionItem/MoneyRequestView.js | 6 ++++++ src/pages/home/report/ReportActionItem.js | 5 +---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.js b/src/components/ReportActionItem/MoneyRequestView.js index 598fe8d096d9..91f035eb8e0b 100644 --- a/src/components/ReportActionItem/MoneyRequestView.js +++ b/src/components/ReportActionItem/MoneyRequestView.js @@ -83,6 +83,12 @@ function MoneyRequestView({report, parentReport, shouldShowHorizontalRule, polic description += ` • ${translate('iou.pending')}`; } + // A temporary solution to hide the transaction detail + // This will be removed after we probably add the transaction as a prop + if (ReportActionsUtils.isDeletedAction(parentReportAction)) { + return null; + } + return ( diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index b9d0367152b5..d182dc4c6bc3 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -463,7 +463,7 @@ function ReportActionItem(props) { if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED) { const parentReportAction = ReportActionsUtils.getParentReportAction(props.report); - if (ReportActionsUtils.isTransactionThread(parentReportAction) && !ReportActionsUtils.isDeletedAction(parentReportAction)) { + if (ReportActionsUtils.isTransactionThread(parentReportAction)) { return ( ); } - if (ReportActionsUtils.isTransactionThread(parentReportAction) && ReportActionsUtils.isDeletedAction(parentReportAction)) { - return null; - } if (ReportUtils.isTaskReport(props.report)) { return ( From c913c46ccd095dc8a4b847c9e90efabaf914ef45 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 15 Aug 2023 23:54:29 +0700 Subject: [PATCH 4/8] fix crash when deleting request --- src/libs/TransactionUtils.js | 6 +++--- src/pages/EditRequestPage.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/TransactionUtils.js b/src/libs/TransactionUtils.js index a05cd377514c..837a92443b8a 100644 --- a/src/libs/TransactionUtils.js +++ b/src/libs/TransactionUtils.js @@ -140,7 +140,7 @@ function getCurrency(transaction) { if (currency) { return currency; } - return lodashGet(transaction, 'currency', ''); + return lodashGet(transaction, 'currency', CONST.CURRENCY.USD); } /** @@ -150,11 +150,11 @@ function getCurrency(transaction) { * @returns {String} */ function getCreated(transaction) { - const created = lodashGet(transaction, 'modifiedCreated', ''); + const created = lodashGet(transaction, 'modifiedCreated', '') || lodashGet(transaction, 'created', ''); if (created) { return format(new Date(created), CONST.DATE.FNS_FORMAT_STRING); } - return format(new Date(lodashGet(transaction, 'created', '')), CONST.DATE.FNS_FORMAT_STRING); + return format(new Date(), CONST.DATE.FNS_FORMAT_STRING); } export {buildOptimisticTransaction, getUpdatedTransaction, getTransaction, getDescription, getAmount, getCurrency, getCreated}; diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index ba9c089d8781..b5eb2aee363a 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -43,7 +43,7 @@ function EditRequestPage({report, route}) { const transactionID = lodashGet(parentReportAction, 'originalMessage.IOUTransactionID', ''); const transaction = TransactionUtils.getTransaction(transactionID); const transactionDescription = TransactionUtils.getDescription(transaction); - const transactionAmount = TransactionUtils.getAmount(transaction, ReportUtils.isExpenseReport(ReportUtils.getParentReport(report))); + const transactionAmount = TransactionUtils.getAmount(transaction, ReportUtils.isExpenseReport(parentReport)); const transactionCurrency = TransactionUtils.getCurrency(transaction); // Take only the YYYY-MM-DD value From 63ef1917e2e4168965f318405536ef3ffb2f931c Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 16 Aug 2023 00:06:08 +0700 Subject: [PATCH 5/8] subscribe parent report for dynamic update --- src/pages/EditRequestPage.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index b5eb2aee363a..cd288a55b520 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'; import lodashGet from 'lodash/get'; import {withOnyx} from 'react-native-onyx'; import {format} from 'date-fns'; +import compose from '../libs/compose'; import CONST from '../CONST'; import Navigation from '../libs/Navigation/Navigation'; import ONYXKEYS from '../ONYXKEYS'; @@ -31,14 +32,17 @@ const propTypes = { /** The report object for the thread report */ report: reportPropTypes, + + /** The parent report object for the thread report */ + parentReport: reportPropTypes, }; const defaultProps = { report: {}, + parentReport: {}, }; -function EditRequestPage({report, route}) { - const parentReport = ReportUtils.getParentReport(report); +function EditRequestPage({report, route, parentReport}) { const parentReportAction = ReportActionsUtils.getParentReportAction(report); const transactionID = lodashGet(parentReportAction, 'originalMessage.IOUTransactionID', ''); const transaction = TransactionUtils.getTransaction(transactionID); @@ -129,8 +133,15 @@ function EditRequestPage({report, route}) { EditRequestPage.displayName = 'EditRequestPage'; EditRequestPage.propTypes = propTypes; EditRequestPage.defaultProps = defaultProps; -export default withOnyx({ - report: { - key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.threadReportID}`, - }, -})(EditRequestPage); +export default compose( + withOnyx({ + report: { + key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.threadReportID}`, + }, + }), + withOnyx({ + parentReport: { + key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`, + }, + }), +)(EditRequestPage); From b75325222e0d72cff4c058fa9a9051f1df5e003d Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 16 Aug 2023 01:00:36 +0700 Subject: [PATCH 6/8] fix crash in edit request page when deleting request money --- src/pages/EditRequestPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index cd288a55b520..7afd2d3f500d 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -141,7 +141,7 @@ export default compose( }), withOnyx({ parentReport: { - key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`, + key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT}${report ? report.parentReportID : '0'}`, }, }), )(EditRequestPage); From de344083ed6f37e345db80f2f148a177045a5c09 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 16 Aug 2023 06:55:00 +0700 Subject: [PATCH 7/8] edit comment --- src/components/ReportActionItem/MoneyRequestView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.js b/src/components/ReportActionItem/MoneyRequestView.js index 91f035eb8e0b..8502b0fb2fea 100644 --- a/src/components/ReportActionItem/MoneyRequestView.js +++ b/src/components/ReportActionItem/MoneyRequestView.js @@ -84,7 +84,7 @@ function MoneyRequestView({report, parentReport, shouldShowHorizontalRule, polic } // A temporary solution to hide the transaction detail - // This will be removed after we probably add the transaction as a prop + // This will be removed after we properly add the transaction as a prop if (ReportActionsUtils.isDeletedAction(parentReportAction)) { return null; } From d7821f593d037569b2de285446d9782919661493 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 16 Aug 2023 07:18:07 +0700 Subject: [PATCH 8/8] clear condition --- src/libs/TransactionUtils.js | 2 +- src/pages/EditRequestPage.js | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/libs/TransactionUtils.js b/src/libs/TransactionUtils.js index 837a92443b8a..b424956cf4e0 100644 --- a/src/libs/TransactionUtils.js +++ b/src/libs/TransactionUtils.js @@ -154,7 +154,7 @@ function getCreated(transaction) { if (created) { return format(new Date(created), CONST.DATE.FNS_FORMAT_STRING); } - return format(new Date(), CONST.DATE.FNS_FORMAT_STRING); + return ''; } export {buildOptimisticTransaction, getUpdatedTransaction, getTransaction, getDescription, getAmount, getCurrency, getCreated}; diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index 7afd2d3f500d..071ffa0ccb40 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -2,7 +2,6 @@ import React, {useEffect} from 'react'; import PropTypes from 'prop-types'; import lodashGet from 'lodash/get'; import {withOnyx} from 'react-native-onyx'; -import {format} from 'date-fns'; import compose from '../libs/compose'; import CONST from '../CONST'; import Navigation from '../libs/Navigation/Navigation'; @@ -51,8 +50,7 @@ function EditRequestPage({report, route, parentReport}) { const transactionCurrency = TransactionUtils.getCurrency(transaction); // Take only the YYYY-MM-DD value - const transactionCreatedDate = new Date(TransactionUtils.getCreated(transaction)); - const transactionCreated = format(transactionCreatedDate, CONST.DATE.FNS_FORMAT_STRING); + const transactionCreated = TransactionUtils.getCreated(transaction); const fieldToEdit = lodashGet(route, ['params', 'field'], ''); const isDeleted = ReportActionsUtils.isDeletedAction(parentReportAction);