-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hide transaction detail and dismiss the edit modal when the request is deleted #24590
Changes from 6 commits
5b5e039
1be995b
9ad5423
c913c46
63ef191
b753252
de34408
d7821f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
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'; | ||
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,24 +32,40 @@ 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 transactionID = lodashGet(ReportActionsUtils.getParentReportAction(report), 'originalMessage.IOUTransactionID', ''); | ||
function EditRequestPage({report, route, parentReport}) { | ||
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))); | ||
const transactionAmount = TransactionUtils.getAmount(transaction, ReportUtils.isExpenseReport(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 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]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the modal open, If you delete a money request without any message you'll be lead to the "Hmm it's not here" page. Is this intended? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should go to the parent report then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same logic as when deleting the request without the modal There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When we delete the request if the report of the request has a comment, we don't navigate to parent report. If not, report will be deleted, and then we cannot get the parent report from the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Besides, if user A is currently in the thread transaction report and on another device user A deletes the request, not found page will also appear. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets just mimic the same behaviour as if the modal would not be opened (+dismiss it) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And the behavior is already the same when we delete the request from another device. Screencast.from.16-08-2023.07.25.58.webmThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seeing as this is the current behaviour on production, perhaps it's out of scope here. |
||
|
||
// Update the transaction object and close the modal | ||
function editMoneyRequest(transactionChanges) { | ||
IOU.editMoneyRequest(transactionID, report.reportID, transactionChanges); | ||
|
@@ -116,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 ? report.parentReportID : '0'}`, | ||
}, | ||
}), | ||
)(EditRequestPage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dukenv0307 What was the plan for this once the transaction is added as a prop (which it is now)?