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

Refactor RejectTransaction to CancelIOUTransaction #11720

Merged
merged 36 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ff85464
Refactoring the reject transaction to cancel money request
mountiny Oct 11, 2022
bc79770
Remove deprecated export
mountiny Oct 12, 2022
cc66f3b
Merge branch 'main' into vit-rejectTransaction
mountiny Oct 13, 2022
f884152
Move transaction to ReportTransaction component
mountiny Oct 13, 2022
51e910f
Fix report id types
mountiny Oct 13, 2022
2200d96
clean up
mountiny Oct 13, 2022
c3840b2
Use switch and add offlineWithFeedback component to IOUTransaction
mountiny Oct 13, 2022
516dae7
Lint errors
mountiny Oct 14, 2022
c6c7745
Merge branch 'main' into vit-rejectTransaction
mountiny Oct 14, 2022
0db62f1
Make the optimisti total updates working and update propTypes
mountiny Oct 14, 2022
a0eea41
Merge branch 'main' into vit-rejectTransaction
mountiny Oct 21, 2022
0d0d441
Improve comments and remove console log
mountiny Oct 21, 2022
2adffd3
resolve conflicts
luacmartins Oct 31, 2022
23c3f80
rm log, use sequenceNumber, update comments
luacmartins Oct 31, 2022
ad80669
use updateIOUOwnerAndTotal
luacmartins Oct 31, 2022
8859584
rollback iouReport on failure
luacmartins Oct 31, 2022
9d924c3
use errors key
luacmartins Oct 31, 2022
d13d32c
use type
luacmartins Oct 31, 2022
38b7ccf
resolve conflicts
luacmartins Oct 31, 2022
3282eb2
add other types to getIOUReportActionMessage
luacmartins Oct 31, 2022
a5f8583
fix args for buildOptimisticIOUReportAction
luacmartins Oct 31, 2022
15ddce0
pass correct transactionID in request money
luacmartins Nov 1, 2022
741726b
add additional params
luacmartins Nov 1, 2022
36f1ee0
fix iou report key
luacmartins Nov 1, 2022
2298759
rm unused import
luacmartins Nov 1, 2022
56ded86
rm iouReportUpdate
luacmartins Nov 1, 2022
fcf55ff
always return shortName
luacmartins Nov 2, 2022
04cf6f2
resolve conflicts
luacmartins Nov 3, 2022
806c244
update variable name
luacmartins Nov 3, 2022
046e282
update iouReportID to string
luacmartins Nov 3, 2022
f898336
update error message
luacmartins Nov 3, 2022
44a6876
rm error from optimistic data
luacmartins Nov 3, 2022
3501542
rm object from failure data
luacmartins Nov 4, 2022
4c5153f
Merge main and resolve merge conflicts
mountiny Nov 4, 2022
ad3b7c3
resolve conflicts
luacmartins Nov 4, 2022
afb8e63
use const
luacmartins Nov 4, 2022
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: 2 additions & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,8 @@ const CONST = {
PAY: 'pay',
CREATE: 'create',
SPLIT: 'split',
DECLINE: 'decline',
CANCEL: 'cancel',
},
AMOUNT_MAX_LENGTH: 10,
},
Expand Down
4 changes: 2 additions & 2 deletions src/components/KYCWall/kycWallPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ const propTypes = {
userWallet: userWalletPropTypes,

/** When the button is opened via an IOU, ID for the chatReport that the IOU is linked to */
chatReportID: PropTypes.number,
chatReportID: PropTypes.string,
};

const defaultProps = {
userWallet: {},
popoverPlacement: 'top',
shouldListenForResize: false,
isDisabled: false,
chatReportID: 0,
chatReportID: '',
};

export {propTypes, defaultProps};
110 changes: 49 additions & 61 deletions src/components/ReportTransaction.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import lodashGet from 'lodash/get';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import ONYXKEYS from '../ONYXKEYS';
import styles from '../styles/styles';
import CONST from '../CONST';
import * as IOU from '../libs/actions/IOU';
import * as ReportActions from '../libs/actions/ReportActions';
import reportActionPropTypes from '../pages/home/report/reportActionPropTypes';
import ReportActionItemSingle from '../pages/home/report/ReportActionItemSingle';
import withLocalize, {withLocalizePropTypes} from './withLocalize';
import OfflineWithFeedback from './OfflineWithFeedback';
import Text from './Text';
import Button from './Button';

Expand All @@ -27,17 +27,10 @@ const propTypes = {
/** Can this transaction be rejected? */
canBeRejected: PropTypes.bool,

/** Text label for the reject transaction button */
rejectButtonLabelText: PropTypes.string.isRequired,
/** Type of the reject transaction button */
rejectButtonType: PropTypes.oneOf([CONST.IOU.REPORT_ACTION_TYPE.DECLINE, CONST.IOU.REPORT_ACTION_TYPE.CANCEL]).isRequired,

/* Onyx Props */

/** List of transactionIDs in process of rejection */
/* eslint-disable-next-line react/no-unused-prop-types, react/require-default-props */
transactionsBeingRejected: PropTypes.shape({
/** IOUTransactionID that's being rejected */
transactionID: PropTypes.bool,
}),
...withLocalizePropTypes,
};

const defaultProps = {
Expand All @@ -48,62 +41,57 @@ class ReportTransaction extends Component {
constructor(props) {
super(props);

this.rejectTransaction = this.rejectTransaction.bind(this);
}

rejectTransaction() {
IOU.rejectTransaction({
reportID: this.props.iouReportID,
chatReportID: this.props.chatReportID,
transactionID: this.props.action.originalMessage.IOUTransactionID,
comment: '',
});
this.cancelMoneyRequest = this.cancelMoneyRequest.bind(this);
}

/**
* Checks if current IOUTransactionID is being rejected.
* @returns {boolean} Returns `true` if current IOUtransactionID is being rejected, else `false`.
*/
isBeingRejected() {
const IOUTransactionID = lodashGet(this.props.action, 'originalMessage.IOUTransactionID', '');
const transactionsBeingRejected = lodashGet(this.props, 'transactionsBeingRejected', {});
if (_.isEmpty(transactionsBeingRejected)) {
return false;
}
return _.has(transactionsBeingRejected, IOUTransactionID);
cancelMoneyRequest() {
IOU.cancelMoneyRequest(
this.props.chatReportID,
this.props.iouReportID,
this.props.rejectButtonType,
this.props.action,
);
}

render() {
return (
<View styles={[styles.mb5]}>
<ReportActionItemSingle
action={this.props.action}
wrapperStyles={[styles.reportTransactionWrapper]}
>
<Text style={[styles.chatItemMessage]}>
{this.props.action.message[0].text}
</Text>
</ReportActionItemSingle>
{this.props.canBeRejected && (
<View style={[styles.flexRow, styles.justifyContentStart]}>
<Button
small
text={this.props.rejectButtonLabelText}
style={[styles.mb3, styles.chatItemComposeSecondaryRowOffset]}
onPress={this.rejectTransaction}
isLoading={this.isBeingRejected()}
/>
</View>
)}
</View>
<OfflineWithFeedback
onClose={() => {
if (this.props.action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
ReportActions.deleteOptimisticReportAction(this.props.chatReportID, this.props.action.sequenceNumber);
} else {
ReportActions.clearReportActionErrors(this.props.chatReportID, this.props.action.sequenceNumber);
}
}}
pendingAction={this.props.action.pendingAction}
errors={this.props.action.errors}
errorRowStyles={[styles.ml10, styles.mr2]}
>
<View styles={[styles.mb5]}>
<ReportActionItemSingle
action={this.props.action}
wrapperStyles={[styles.reportTransactionWrapper]}
>
<Text style={[styles.chatItemMessage]}>
{this.props.action.message[0].text}
</Text>
</ReportActionItemSingle>
{this.props.canBeRejected && (
<View style={[styles.flexRow, styles.justifyContentStart]}>
<Button
small
text={this.props.translate(`common.${this.props.rejectButtonType}`)}
style={[styles.mb3, styles.chatItemComposeSecondaryRowOffset]}
onPress={this.cancelMoneyRequest}
/>
</View>
)}
</View>
</OfflineWithFeedback>
);
}
}

ReportTransaction.defaultProps = defaultProps;
ReportTransaction.propTypes = propTypes;
export default withOnyx({
transactionsBeingRejected: {
key: ONYXKEYS.TRANSACTIONS_BEING_REJECTED,
},
})(ReportTransaction);
export default withLocalize(ReportTransaction);
4 changes: 2 additions & 2 deletions src/components/SettlementButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ const propTypes = {
network: networkPropTypes.isRequired,

/** When the button is opened via an IOU, ID for the chatReport that the IOU is linked to */
chatReportID: PropTypes.number,
chatReportID: PropTypes.string,

...withLocalizePropTypes,
};

const defaultProps = {
currency: CONST.CURRENCY.USD,
shouldShowPaypal: false,
chatReportID: 0,
chatReportID: '',
};

class SettlementButton extends React.Component {
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ export default {
invalidSplit: 'Split amounts do not equal total amount',
other: 'Unexpected error, please try again later',
genericCreateFailureMessage: 'Unexpected error requesting money, please try again later',
genericCancelFailureMessage: ({type}) => `Unexpected error ${type === 'decline' ? 'declining' : 'cancelling'} the money request, please try again later`,
},
},
notificationPreferences: {
Expand Down
2 changes: 2 additions & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ export default {
invalidSplit: 'La suma de las partes no equivale al monto total',
other: 'Error inesperado, por favor inténtalo más tarde',
genericCreateFailureMessage: 'Error inesperado solicitando dinero, por favor inténtalo más tarde',
genericCancelFailureMessage: ({type}) => `Error inesperado al ${type === 'decline' ? 'rechazar' : 'cancelar'} la solicitud de dinero, por favor inténtalo más tarde`,

},
},
notificationPreferences: {
Expand Down
19 changes: 14 additions & 5 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,18 +702,27 @@ function buildOptimisticIOUReport(ownerEmail, userEmail, total, chatReportID, cu
*/
function getIOUReportActionMessage(type, total, participants, comment, currency) {
const amount = NumberFormatUtils.format(preferredLocale, total / 100, {style: 'currency', currency});
const displayNames = _.map(participants, participant => getDisplayNameForParticipant(participant.login, true) || participant.login);
const from = displayNames.length < 3
const displayNames = _.map(participants, participant => getDisplayNameForParticipant(participant.login, true));
const who = displayNames.length < 3
? displayNames.join(' and ')
: `${displayNames.slice(0, -1).join(', ')}, and ${_.last(displayNames)}`;

let iouMessage;
switch (type) {
case CONST.IOU.REPORT_ACTION_TYPE.CREATE:
iouMessage = `Requested ${amount} from ${from}${comment && ` for ${comment}`}`;
iouMessage = `Requested ${amount} from ${who}${comment && ` for ${comment}`}`;
break;
case CONST.IOU.REPORT_ACTION_TYPE.SPLIT:
iouMessage = `Split ${amount} with ${from}${comment && ` for ${comment}`}`;
iouMessage = `Split ${amount} with ${who}${comment && ` for ${comment}`}`;
break;
case CONST.IOU.REPORT_ACTION_TYPE.CANCEL:
iouMessage = `Cancelled the ${amount} request${comment && ` for ${comment}`}`;
break;
case CONST.IOU.REPORT_ACTION_TYPE.DECLINE:
iouMessage = `Declined the ${amount} request${comment && ` for ${comment}`}`;
break;
case CONST.IOU.REPORT_ACTION_TYPE.PAY:
iouMessage = `Paid ${amount} to ${who}${comment && ` for ${comment}`}`;
break;
default:
break;
Expand All @@ -733,7 +742,7 @@ function getIOUReportActionMessage(type, total, participants, comment, currency)
* @param {Number} sequenceNumber - Caller is responsible for providing a best guess at what the next sequenceNumber will be.
* @param {String} type - IOUReportAction type. Can be oneOf(create, decline, cancel, pay, split).
* @param {Number} amount - IOU amount in cents.
* @param {String} currency - IOU currency.
* @param {String} currency
* @param {String} comment - User comment for the IOU.
* @param {Array} participants - An array with participants details.
* @param {String} paymentType - Only required if the IOUReportAction type is 'pay'. Can be oneOf(elsewhere, payPal, Expensify).
Expand Down
Loading