Skip to content
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

[Manual Requests] Create thread for Manual Request when opening IOUPreview #18760

Merged
merged 26 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
202122a
create method to find if a thread exists or not
bondydaa May 11, 2023
fa1b3dc
add rough sketch of what needs to happen to create a thread on demand
bondydaa May 11, 2023
e30b603
fixing merge conflict
bondydaa May 12, 2023
a5e043e
rename method and update to return the report object for a thread
bondydaa May 12, 2023
94c9125
allow the passing of a parentReportActionID so we can create threads
bondydaa May 12, 2023
94c19d6
generate report optimistically and pass parentReportActionID to creat…
bondydaa May 12, 2023
b2c926f
Merge branch 'main' of github.com:Expensify/App into bondy-thread-man…
bondydaa May 12, 2023
6e3bf2c
appease linter
bondydaa May 12, 2023
b4a991b
appease linter and import full lib
bondydaa May 12, 2023
c0e2430
we dont need to prefilter the user making the request out since auth …
bondydaa May 12, 2023
4cfefbb
use amount not payee in report name
bondydaa May 12, 2023
9d518ba
fixing jsdocs and comment
bondydaa May 12, 2023
f83e240
use proper prop
bondydaa May 12, 2023
03f8c6f
Merge main and resolve conflicts
mountiny May 13, 2023
dfc4e79
Fix linter
mountiny May 13, 2023
33afd33
Merge branch 'main' into bondy-thread-manual-requests
mountiny May 14, 2023
6e6eb06
Merge branch 'vit-ensureDeleteShowsAsText' into bondy-thread-manual-r…
mountiny May 14, 2023
35c3c79
Ensure threads are created optimistically
mountiny May 14, 2023
22f9a4a
Add the childReportID to the report action so we do not create multip…
mountiny May 14, 2023
bcb6855
Merge branch 'main' into bondy-thread-manual-requests
mountiny May 14, 2023
3ec51b5
Remove unsused method
mountiny May 14, 2023
9acde61
Merge branch 'main' into bondy-thread-manual-requests
mountiny May 15, 2023
e9d4c4a
Access property safely
mountiny May 15, 2023
df1462a
Update spanish translation
mountiny May 15, 2023
42db583
Fix lint
mountiny May 15, 2023
e800564
Merge branch 'main' into bondy-thread-manual-requests
mountiny May 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/components/ReportActionItem/MoneyRequestAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import Navigation from '../../libs/Navigation/Navigation';
import ROUTES from '../../ROUTES';
import styles from '../../styles/styles';
import * as IOUUtils from '../../libs/IOUUtils';
import {getThreadForReportActionID, buildOptimisticChatReport} from '../../libs/ReportUtils';
mountiny marked this conversation as resolved.
Show resolved Hide resolved
import * as Report from '../../libs/actions/Report';
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
import lodashGet from 'lodash/get';
mountiny marked this conversation as resolved.
Show resolved Hide resolved

const propTypes = {
/** All the data of the action */
Expand Down Expand Up @@ -55,6 +59,14 @@ const propTypes = {
isHovered: PropTypes.bool,

network: networkPropTypes.isRequired,

/** Session info for the currently logged in user. */
session: PropTypes.shape({
/** Currently logged in user email */
email: PropTypes.string,
}),

...withLocalizePropTypes,
};

const defaultProps = {
Expand All @@ -66,11 +78,40 @@ const defaultProps = {
iouReport: {},
reportActions: {},
isHovered: false,
session: {
email: null,
},
};

const MoneyRequestAction = (props) => {
const hasMultipleParticipants = props.chatReport.participants.length > 1;
const onIOUPreviewPressed = () => {
// This would ideally be passed as a prop or hooked up via withOnyx so that we are not be triggering a potentially intensive
// search in an onPress handler, I think this could lead to performance issues but it probably ok for now.
const thread = getThreadForReportActionID(props.action.reportActionID);
console.log({thread});
if (_.isEmpty(thread)) {
// Since a thread does not exist yet then we need to create it now. This is done by creating the report object
// and passing the parentReportActionID of the reportAction. OpenReport will then automatically create the thread for us.
const optimisticThreadReport = buildOptimisticChatReport(
props.chatReport.participants,
props.translate('iou.threadReportName', {payee: props.action.actorEmail, comment: props.action.originalMessage.comment}),
'',
props.chatReport.policyID,
props.chatReport.owner,
props.chatReport.type === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT,
mountiny marked this conversation as resolved.
Show resolved Hide resolved
props.chatReport.oldPolicyName,
undefined,
CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
props.action.reportActionID,
);
console.log({optimisticThreadReport});
Report.openReport(
optimisticThreadReport.reportID,
[_.reject(optimisticThreadReport.participants, (login) => login === lodashGet(props.session, 'email', ''))],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be the same as props.chatReport.participants?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't 100% sure since the API param for participants says it shouldn't include the user making the request: https://github.com/Expensify/Web-Expensify/blob/335001f0f64bf449fc884456ef1911cd1e6f17d5/lib/ReportAPI.php#L4404-L4405

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay asked about this here https://expensify.slack.com/archives/C02HWMSMZEC/p1683912289696679?thread_ts=1683911072.385549&cid=C02HWMSMZEC

And looks like it doesn't really matter if we include the user making the request here because in Auth here we make sure to include them and since set doesn't allow duplicates we are fine https://github.com/Expensify/Auth/blob/dbd779f7c423a82d4871d6dc076ecb37406fb43c/auth/command/OpenReport.cpp#L77

optimisticThreadReport,
);
}
if (hasMultipleParticipants) {
Navigation.navigate(ROUTES.getReportParticipantsRoute(props.chatReportID));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I think in order to get the newly created thread to show up we'll need to have something like GetChats triggered OR navigate to the report here in this section.

@Julesssss and @luacmartins had mentioned that this might be in the works else where as well but I'm not sure of a GH or anything for it.

If nothing changes here with these routes then the modal will continue to open instead of going to the thread.

} else {
Expand Down Expand Up @@ -126,6 +167,7 @@ MoneyRequestAction.defaultProps = defaultProps;
MoneyRequestAction.displayName = 'MoneyRequestAction';

export default compose(
withLocalize,
withOnyx({
chatReport: {
key: ({chatReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`,
Expand All @@ -137,6 +179,9 @@ export default compose(
key: ({chatReportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReportID}`,
canEvict: false,
},
session: {
key: ONYXKEYS.SESSION,
},
}),
withNetwork(),
)(MoneyRequestAction);
1 change: 1 addition & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ export default {
payerOwesAmount: ({payer, amount}) => `${payer} owes ${amount}`,
noReimbursableExpenses: 'This report has an invalid amount',
pendingConversionMessage: "Total will update when you're back online",
threadReportName: ({payee, comment}) => `${payee} request${comment ? ` for ${comment}` : ''}`,
mountiny marked this conversation as resolved.
Show resolved Hide resolved
error: {
invalidSplit: 'Split amounts do not equal total amount',
other: 'Unexpected error, please try again later',
Expand Down
19 changes: 19 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,7 @@ function buildOptimisticChatReport(
oldPolicyName = '',
visibility = undefined,
notificationPreference = CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
parentReportActionID = '',
bondydaa marked this conversation as resolved.
Show resolved Hide resolved
) {
const currentTime = DateUtils.getDBTime();
return {
Expand All @@ -1295,6 +1296,7 @@ function buildOptimisticChatReport(
participants: participantList,
policyID,
reportID: generateReportID(),
parentReportActionID,
reportName,
stateNum: 0,
statusNum: 0,
Expand Down Expand Up @@ -1894,6 +1896,22 @@ function getWhisperDisplayNames(participants) {
return _.map(participants, (login) => getDisplayNameForParticipant(login, !isWhisperOnlyVisibleToCurrentUSer)).join(', ');
}

/**
* Used to determine if a thread exists already or not for a given reportActionID
mountiny marked this conversation as resolved.
Show resolved Hide resolved
*
* @param {String}
* @returns {Boolean}
*/
function getThreadForReportActionID(reportActionID) {
return _.find(allReports, (report) => {
if (!report.parentReportActionID) {
return false;
}

return report.parentReportActionID === reportActionID;
});
}

/**
* Show subscript on IOU or expense report
* @param {Object} report
Expand Down Expand Up @@ -1990,5 +2008,6 @@ export {
canRequestMoney,
getWhisperDisplayNames,
getWorkspaceAvatar,
getThreadForReportActionID,
shouldReportShowSubscript,
};
5 changes: 5 additions & 0 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,11 @@ function openReport(reportID, participantList = [], newReportObject = {}) {

// Add the createdReportActionID parameter to the API call
params.createdReportActionID = optimisticCreatedAction.reportActionID;

// Only add the parentReportActionID if it's been added to the optimistic report
if (newReportObject.parentReportActionID) {
params.parentReportActionID = newReportObject.parentReportActionID;
}
}

API.write('OpenReport', params, onyxData);
Expand Down