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

Personal details list migration: fix Header not displayed while sending money #20679

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
2 changes: 1 addition & 1 deletion src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, {
reportName = ReportUtils.getReportName(report);
} else {
reportName = ReportUtils.getDisplayNameForParticipant(accountIDs[0]);
result.keyForList = accountIDs[0];
result.keyForList = String(accountIDs[0]);
mountiny marked this conversation as resolved.
Show resolved Hide resolved
result.alternateText = '';
}

Expand Down
60 changes: 60 additions & 0 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as OptionsListUtils from '../OptionsListUtils';
import DateUtils from '../DateUtils';
import TransactionUtils from '../TransactionUtils';
import * as ErrorUtils from '../ErrorUtils';
import * as UserUtils from '../UserUtils';

const chatReports = {};
const iouReports = {};
Expand Down Expand Up @@ -51,6 +52,7 @@ function buildOnyxDataForMoneyRequest(
chatCreatedAction,
iouCreatedAction,
iouAction,
optimisticPersonalDetailListAction,
reportPreviewAction,
isNewChatReport,
isNewIOUReport,
Expand Down Expand Up @@ -104,6 +106,14 @@ function buildOnyxDataForMoneyRequest(
},
];

if (isNewChatReport && !_.isEmpty(optimisticPersonalDetailListAction)) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: optimisticPersonalDetailListAction,
});
}
Comment on lines +109 to +115
Copy link
Contributor

Choose a reason for hiding this comment

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

This caused a regression. Merging the personal data should only be done only if it's not in Onyx already. Otherwise we would overwrite the existing user data e.g. displayName.


const successData = [
...(isNewChatReport
? [
Expand Down Expand Up @@ -326,6 +336,15 @@ function requestMoney(report, amount, currency, payeeEmail, payeeAccountID, part
'',
iouReport.reportID,
);
// Add optimistic personal details for participant
BeeMargarida marked this conversation as resolved.
Show resolved Hide resolved
const optimisticPersonalDetailListAction = {
[payerAccountID]: {
accountID: payerAccountID,
avatar: UserUtils.getDefaultAvatarURL(payerAccountID),
displayName: participant.displayName || payerEmail,
login: participant.login,
},
};

let isNewReportPreviewAction = false;
let reportPreviewAction = isNewIOUReport ? null : ReportActionsUtils.getReportPreviewAction(chatReport.reportID, iouReport.reportID);
Expand All @@ -342,6 +361,7 @@ function requestMoney(report, amount, currency, payeeEmail, payeeAccountID, part
optimisticCreatedActionForChat,
optimisticCreatedActionForIOU,
optimisticIOUAction,
optimisticPersonalDetailListAction,
reportPreviewAction,
isNewChatReport,
isNewIOUReport,
Expand Down Expand Up @@ -563,6 +583,15 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco
'',
oneOnOneIOUReport.reportID,
);
// Add optimistic personal details for new participants
BeeMargarida marked this conversation as resolved.
Show resolved Hide resolved
const oneOnOnePersonalDetailListAction = {
[accountID]: {
accountID,
mountiny marked this conversation as resolved.
Show resolved Hide resolved
avatar: UserUtils.getDefaultAvatarURL(accountID),
displayName: participant.displayName || email,
login: participant.login,
},
};

let isNewOneOnOneReportPreviewAction = false;
let oneOnOneReportPreviewAction = ReportActionsUtils.getReportPreviewAction(oneOnOneChatReport.reportID, oneOnOneIOUReport.reportID);
Expand All @@ -579,6 +608,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco
oneOnOneCreatedActionForChat,
oneOnOneCreatedActionForIOU,
oneOnOneIOUAction,
oneOnOnePersonalDetailListAction,
oneOnOneReportPreviewAction,
isNewOneOnOneChatReport,
isNewOneOnOneIOUReport,
Expand Down Expand Up @@ -937,6 +967,8 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType
},
];

let optimisticPersonalDetailListData = {};

// Now, let's add the data we need just when we are creating a new chat report
if (isNewChat) {
// Change the method to set for new reports because it doesn't exist yet, is faster,
Expand All @@ -962,6 +994,20 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType
},
});

// Add optimistic personal details for recipient
optimisticPersonalDetailListData = {
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: {
[recipientAccountID]: {
accountID: recipientAccountID,
avatar: UserUtils.getDefaultAvatarURL(recipient.accountID),
displayName: recipient.displayName || recipient.login,
login: recipient.login,
},
},
};

// Add an optimistic created action to the optimistic reportActions data
optimisticReportActionsData.value[optimisticCreatedAction.reportActionID] = optimisticCreatedAction;

Expand All @@ -970,6 +1016,9 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType
}

const optimisticData = [optimisticChatReportData, optimisticIOUReportData, optimisticReportActionsData, optimisticTransactionData];
if (!_.isEmpty(optimisticPersonalDetailListData)) {
optimisticData.push(optimisticPersonalDetailListData);
}

return {
params: {
Expand Down Expand Up @@ -1007,6 +1056,12 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho
iouReport.reportID,
true,
);
const optimisticPersonalDetailsListAction = {
accountID: Number(recipient.accountID),
avatar: UserUtils.getDefaultAvatarURL(Number(recipient.accountID)),
displayName: recipient.displayName || recipient.login,
login: recipient.login,
};
Comment on lines +1061 to +1066
Copy link
Contributor

Choose a reason for hiding this comment

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

There was a copy/paste mistake here. This data itself (without accountID key) is added in ONYXKEYS.PERSONAL_DETAILS_LIST. Luckily, this didn't cause any issue but just console error.
More details: #23645 (comment)


const optimisticData = [
{
Expand Down Expand Up @@ -1053,6 +1108,11 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho
key: ONYXKEYS.NVP_LAST_PAYMENT_METHOD,
value: {[iouReport.policyID]: paymentMethodType},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: optimisticPersonalDetailsListAction,
},
];

const successData = [
Expand Down