Skip to content

Commit

Permalink
Merge pull request #19194 from Expensify/vit-fixHeaderPaymentButton
Browse files Browse the repository at this point in the history
Fix couple of manual request bugs
  • Loading branch information
mountiny authored May 19, 2023
2 parents 435c70b + f21c9bc commit 40d992f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 29 deletions.
6 changes: 3 additions & 3 deletions src/components/MoneyRequestHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ const MoneyRequestHeader = (props) => {
? ReportUtils.getWorkspaceAvatar(moneyRequestReport)
: ReportUtils.getAvatar(lodashGet(props.personalDetails, [moneyRequestReport.managerEmail, 'avatar']), moneyRequestReport.managerEmail);
const policy = props.policies[`${ONYXKEYS.COLLECTION.POLICY}${props.report.policyID}`];
const shouldShowSettlementButton =
!isSettled && (Policy.isAdminOfFreePolicy([policy]) || (ReportUtils.isMoneyRequestReport(props.report) && lodashGet(props.session, 'email', null) === props.report.managerEmail));
const isPayer = Policy.isAdminOfFreePolicy([policy]) || (ReportUtils.isMoneyRequestReport(props.report) && lodashGet(props.session, 'email', null) === props.report.managerEmail);
const shouldShowSettlementButton = !isSettled && !props.isSingleTransactionView && isPayer;
return (
<View style={[{backgroundColor: themeColors.highlightBG}, styles.pl0]}>
<HeaderWithCloseButton
Expand Down Expand Up @@ -149,7 +149,7 @@ const MoneyRequestHeader = (props) => {
currency={props.report.currency}
policyID={props.report.policyID}
shouldShowPaypal={Boolean(lodashGet(props.personalDetails, [moneyRequestReport.managerEmail, 'payPalMeAddress']))}
chatReportID={props.report.chatReportID}
chatReportID={props.chatReport.reportID}
iouReport={props.report}
onPress={(paymentType) => IOU.payMoneyRequest(paymentType, props.chatReport, props.report)}
enablePaymentsRoute={ROUTES.BANK_ACCOUNT_NEW}
Expand Down
8 changes: 5 additions & 3 deletions src/components/ReportActionItem/ReportPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const ReportPreview = (props) => {
const isCurrentUserManager = managerEmail === lodashGet(props.session, 'email', null);
return (
<View style={[styles.chatItemMessage, styles.mt4]}>
{_.map(props.action.message, (index) => (
{_.map(props.action.message, (message, index) => (
<Pressable
key={`ReportPreview-${props.action.reportActionID}-${index}`}
onPress={() => {
Expand All @@ -114,10 +114,12 @@ const ReportPreview = (props) => {
>
<View style={[styles.flexShrink1]}>
{props.iouReport.hasOutstandingIOU ? (
<Text style={[styles.chatItemMessage, styles.cursorPointer]}>{props.translate('iou.payerOwesAmount', {payer: managerName, amount: reportAmount})}</Text>
<Text style={[styles.chatItemMessage, styles.cursorPointer]}>
{lodashGet(message, 'html', props.translate('iou.payerOwesAmount', {payer: managerName, amount: reportAmount}))}
</Text>
) : (
<View style={[styles.flexRow]}>
<Text style={[styles.chatItemMessage, styles.cursorPointer]}>{props.translate('iou.payerSettled', {amount: reportAmount})}</Text>
<Text style={[styles.chatItemMessage, styles.cursorPointer]}>{lodashGet(message, 'html', props.translate('iou.payerSettled', {amount: reportAmount}))}</Text>
{!props.iouReport.hasOutstandingIOU && (
<Icon
style={[styles.ml10]}
Expand Down
5 changes: 3 additions & 2 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1383,9 +1383,10 @@ function getIOUReportActionMessage(type, total, comment, currency, paymentType =
* @param {String} [paymentType] - Only required if the IOUReportAction type is 'pay'. Can be oneOf(elsewhere, payPal, Expensify).
* @param {String} [iouReportID] - Only required if the IOUReportActions type is oneOf(decline, cancel, pay). Generates a randomID as default.
* @param {Boolean} [isSettlingUp] - Whether we are settling up an IOU.
* @param {Boolean} [isSendMoneyFlow] - Whether this is send money flow
* @returns {Object}
*/
function buildOptimisticIOUReportAction(type, amount, currency, comment, participants, transactionID, paymentType = '', iouReportID = '', isSettlingUp = false) {
function buildOptimisticIOUReportAction(type, amount, currency, comment, participants, transactionID, paymentType = '', iouReportID = '', isSettlingUp = false, isSendMoneyFlow = false) {
const IOUReportID = iouReportID || generateReportID();
const parser = new ExpensiMark();
const commentText = getParsedComment(comment);
Expand All @@ -1401,7 +1402,7 @@ function buildOptimisticIOUReportAction(type, amount, currency, comment, partici
};

// We store amount, comment, currency in IOUDetails when type = pay
if (type === CONST.IOU.REPORT_ACTION_TYPE.PAY) {
if (type === CONST.IOU.REPORT_ACTION_TYPE.PAY && isSendMoneyFlow) {
_.each(['amount', 'comment', 'currency'], (key) => {
delete originalMessage[key];
});
Expand Down
21 changes: 2 additions & 19 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,8 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType
optimisticTransaction.transactionID,
paymentMethodType,
optimisticIOUReport.reportID,
false,
true,
);

// First, add data that will be used in all cases
Expand Down Expand Up @@ -1014,7 +1016,6 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType
* @returns {Object}
*/
function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMethodType) {
const reportPreviewAction = ReportActionsUtils.getReportPreviewAction(chatReport.reportID, iouReport.reportID);
const optimisticTransaction = TransactionUtils.buildOptimisticTransaction(iouReport.total, iouReport.currency, iouReport.reportID);
const optimisticIOUReportAction = ReportUtils.buildOptimisticIOUReportAction(
CONST.IOU.REPORT_ACTION_TYPE.PAY,
Expand Down Expand Up @@ -1042,15 +1043,6 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho
lastMessageHtml: optimisticIOUReportAction.message[0].html,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`,
value: {
[reportPreviewAction.reportActionID]: {
created: DateUtils.getDBTime(),
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`,
Expand Down Expand Up @@ -1104,15 +1096,6 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho
];

const failureData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`,
value: {
[reportPreviewAction.reportActionID]: {
created: reportPreviewAction.created,
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`,
Expand Down
3 changes: 1 addition & 2 deletions src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,10 @@ class ReportActionItem extends Component {
originalMessage &&
(originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.CREATE ||
originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.SPLIT ||
(originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.PAY && originalMessage.IOUDetails))
(originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.PAY && _.has(originalMessage, 'IOUDetails')))
) {
// There is no single iouReport for bill splits, so only 1:1 requests require an iouReportID
const iouReportID = originalMessage.IOUReportID ? originalMessage.IOUReportID.toString() : '0';

children = (
<MoneyRequestAction
chatReportID={this.props.report.reportID}
Expand Down

0 comments on commit 40d992f

Please sign in to comment.