From ebf50d8820812528b6e71b1b5153a74edfce364f Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 9 Jun 2021 23:13:47 +0300 Subject: [PATCH 01/24] conditional render ActivityIndicator vs Text --- src/components/ReportTransaction.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/components/ReportTransaction.js b/src/components/ReportTransaction.js index 557786e71fa6..beffd04579bb 100644 --- a/src/components/ReportTransaction.js +++ b/src/components/ReportTransaction.js @@ -1,7 +1,10 @@ import React, {Component} from 'react'; import PropTypes from 'prop-types'; -import {Text, View, Pressable} from 'react-native'; +import { + Text, View, Pressable, ActivityIndicator, +} from 'react-native'; import styles from '../styles/styles'; +import themeColors from '../styles/themes/default'; import {rejectTransaction} from '../libs/actions/IOU'; import ReportActionPropTypes from '../pages/home/report/ReportActionPropTypes'; import ReportActionItemSingle from '../pages/home/report/ReportActionItemSingle'; @@ -23,6 +26,9 @@ const propTypes = { /** Text label for the reject transaction button */ rejectButtonLabelText: PropTypes.string.isRequired, + + /* eslint-disable-next-line react/no-unused-prop-types */ + rejectInProgress: PropTypes.arrayOf(PropTypes.string), }; const defaultProps = { @@ -45,7 +51,15 @@ class ReportTransaction extends Component { }); } + isRejected(rejectedIDs, transactionID) { + if (!rejectedIDs) { + return false; + } + return rejectedIDs.includes(transactionID.toString()); + } + render() { + const rejectedIDs = lodashGet(this.props, 'rejectInProgress', []); return ( - {this.props.rejectButtonLabelText} + { + this.isRejected(rejectedIDs, this.props.action.originalMessage.IOUTransactionID) + ? + : ( + + {this.props.rejectButtonLabelText} + + ) + } )} From cd6cabf5872289eb87bd89b9f9c50ba2d2af3ed4 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 9 Jun 2021 23:14:57 +0300 Subject: [PATCH 02/24] add REJECT_IN_PROGRESS Onyx key --- src/ONYXKEYS.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ONYXKEYS.js b/src/ONYXKEYS.js index d7fcd65074f3..a1c0685be7f0 100755 --- a/src/ONYXKEYS.js +++ b/src/ONYXKEYS.js @@ -87,6 +87,9 @@ export default { // Indicates which locale should be used PREFERRED_LOCALE: 'preferredLocale', + // List of transactions that are in progress of being rejected + REJECT_IN_PROGRESS: 'rejectInProgress', + // User's Expensify Wallet USER_WALLET: 'userWallet', From 5e45cf005aa3705ec8957a3a4f0939655d28d2d0 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 9 Jun 2021 23:17:18 +0300 Subject: [PATCH 03/24] export composed with onyx --- src/components/ReportTransaction.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/ReportTransaction.js b/src/components/ReportTransaction.js index beffd04579bb..4fe7ac1becc9 100644 --- a/src/components/ReportTransaction.js +++ b/src/components/ReportTransaction.js @@ -8,6 +8,7 @@ import themeColors from '../styles/themes/default'; import {rejectTransaction} from '../libs/actions/IOU'; import ReportActionPropTypes from '../pages/home/report/ReportActionPropTypes'; import ReportActionItemSingle from '../pages/home/report/ReportActionItemSingle'; +import compose from '../libs/compose'; const propTypes = { /** The chatReport which the transaction is associated with */ @@ -100,4 +101,10 @@ class ReportTransaction extends Component { ReportTransaction.displayName = 'ReportTransaction'; ReportTransaction.defaultProps = defaultProps; ReportTransaction.propTypes = propTypes; -export default ReportTransaction; +export default compose( + withOnyx({ + rejectInProgress: { + key: ONYXKEYS.REJECT_IN_PROGRESS, + }, + }), +)(ReportTransaction); From 80126f44f51afe5edb7a29379ae5dff6ef505131 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 9 Jun 2021 23:22:27 +0300 Subject: [PATCH 04/24] import withOnyx onyxkeys lodash/get --- src/components/ReportTransaction.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/components/ReportTransaction.js b/src/components/ReportTransaction.js index 4fe7ac1becc9..8cca9bba022e 100644 --- a/src/components/ReportTransaction.js +++ b/src/components/ReportTransaction.js @@ -1,8 +1,13 @@ import React, {Component} from 'react'; import PropTypes from 'prop-types'; +import lodashGet from 'lodash/get'; import { Text, View, Pressable, ActivityIndicator, } from 'react-native'; +import { + withOnyx, +} from 'react-native-onyx'; +import ONYXKEYS from '../ONYXKEYS'; import styles from '../styles/styles'; import themeColors from '../styles/themes/default'; import {rejectTransaction} from '../libs/actions/IOU'; From d3e31805a202c111ed5e090ee00981816c59c04f Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 9 Jun 2021 23:24:19 +0300 Subject: [PATCH 05/24] defalt prop for rejectInProgress --- src/components/ReportTransaction.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/ReportTransaction.js b/src/components/ReportTransaction.js index 8cca9bba022e..4ccada7912f9 100644 --- a/src/components/ReportTransaction.js +++ b/src/components/ReportTransaction.js @@ -39,6 +39,7 @@ const propTypes = { const defaultProps = { canBeRejected: false, + rejectInProgress: [], }; class ReportTransaction extends Component { From 7a294b2efd2190f763d20d3794b0e75dd3bf5a08 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 9 Jun 2021 23:27:21 +0300 Subject: [PATCH 06/24] add rejected transactionID to Onyx --- src/libs/actions/IOU.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 3e64047eedc8..403d1c696265 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -135,6 +135,7 @@ function createIOUSplit(params) { function rejectTransaction({ reportID, chatReportID, transactionID, comment, }) { + Onyx.merge(ONYXKEYS.REJECT_IN_PROGRESS, [transactionID]); API.RejectTransaction({ reportID, transactionID, From 33cdbaf9d33fa451b9af34b7dd9b9a1d336b2a60 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 9 Jun 2021 23:28:25 +0300 Subject: [PATCH 07/24] add minWidth to Pressable --- src/components/ReportTransaction.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/ReportTransaction.js b/src/components/ReportTransaction.js index 4ccada7912f9..602142c1acea 100644 --- a/src/components/ReportTransaction.js +++ b/src/components/ReportTransaction.js @@ -84,6 +84,7 @@ class ReportTransaction extends Component { styles.buttonSmall, styles.chatItemComposeSecondaryRowOffset, styles.mb3, + {minWidth: '20%'}, ]} onPress={this.rejectTransaction} > From 99e04e35f3dc7a4211ae359abb060b8a10e561d0 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 9 Jun 2021 23:33:05 +0300 Subject: [PATCH 08/24] remove rejectedID from Onyx when done --- src/components/ReportTransaction.js | 1 + src/libs/actions/IOU.js | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/ReportTransaction.js b/src/components/ReportTransaction.js index 602142c1acea..0912090ef35d 100644 --- a/src/components/ReportTransaction.js +++ b/src/components/ReportTransaction.js @@ -55,6 +55,7 @@ class ReportTransaction extends Component { chatReportID: this.props.chatReportID, transactionID: this.props.action.originalMessage.IOUTransactionID, comment: '', + rejectedIDs: this.props.rejectInProgress, }); } diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 403d1c696265..6ed9f1b3b7ba 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -133,7 +133,7 @@ function createIOUSplit(params) { * @param {String} params.comment */ function rejectTransaction({ - reportID, chatReportID, transactionID, comment, + reportID, chatReportID, transactionID, comment, rejectedIDs, }) { Onyx.merge(ONYXKEYS.REJECT_IN_PROGRESS, [transactionID]); API.RejectTransaction({ @@ -154,7 +154,11 @@ function rejectTransaction({ // we should also sync the chatReport after fetching the iouReport. fetchIOUReportByIDAndUpdateChatReport(reportID, chatReportID); }) - .catch(error => console.error(`Error rejecting transaction: ${error}`)); + .catch(error => console.error(`Error rejecting transaction: ${error}`)) + .finally(() => { + const withoutCurrentID = rejectedIDs.filter(id => id !== transactionID); + Onyx.set(ONYXKEYS.REJECT_IN_PROGRESS, withoutCurrentID); + }); } /** From e4cb02789ab21dafa422ef534e6f636708038f3c Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 9 Jun 2021 23:49:38 +0300 Subject: [PATCH 09/24] add some docs --- src/components/ReportTransaction.js | 3 +++ src/libs/actions/IOU.js | 1 + 2 files changed, 4 insertions(+) diff --git a/src/components/ReportTransaction.js b/src/components/ReportTransaction.js index 0912090ef35d..2578d3621ee4 100644 --- a/src/components/ReportTransaction.js +++ b/src/components/ReportTransaction.js @@ -33,6 +33,9 @@ const propTypes = { /** Text label for the reject transaction button */ rejectButtonLabelText: PropTypes.string.isRequired, + /* Onyx Props */ + + /** List of transactionIDs in process of rejection */ /* eslint-disable-next-line react/no-unused-prop-types */ rejectInProgress: PropTypes.arrayOf(PropTypes.string), }; diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 6ed9f1b3b7ba..8306648bbce9 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -131,6 +131,7 @@ function createIOUSplit(params) { * @param {Number} params.chatReportID * @param {String} params.transactionID * @param {String} params.comment + * @param {Object} params.rejectedIDs */ function rejectTransaction({ reportID, chatReportID, transactionID, comment, rejectedIDs, From 2aa493b144cf298c2dc63d45aae0aeef41a38a2b Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Thu, 10 Jun 2021 14:02:11 +0300 Subject: [PATCH 10/24] center ActivityIndicator --- src/components/ReportTransaction.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/ReportTransaction.js b/src/components/ReportTransaction.js index 2578d3621ee4..004b5a459fd7 100644 --- a/src/components/ReportTransaction.js +++ b/src/components/ReportTransaction.js @@ -94,7 +94,12 @@ class ReportTransaction extends Component { > { this.isRejected(rejectedIDs, this.props.action.originalMessage.IOUTransactionID) - ? + ? ( + + ) : ( {this.props.rejectButtonLabelText} From 012e0f09b3791e33d079679867262a9c25c3d0e5 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Thu, 10 Jun 2021 16:28:02 +0300 Subject: [PATCH 11/24] export without using compose --- src/components/ReportTransaction.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/components/ReportTransaction.js b/src/components/ReportTransaction.js index 004b5a459fd7..7e3e5c4cd236 100644 --- a/src/components/ReportTransaction.js +++ b/src/components/ReportTransaction.js @@ -13,7 +13,6 @@ import themeColors from '../styles/themes/default'; import {rejectTransaction} from '../libs/actions/IOU'; import ReportActionPropTypes from '../pages/home/report/ReportActionPropTypes'; import ReportActionItemSingle from '../pages/home/report/ReportActionItemSingle'; -import compose from '../libs/compose'; const propTypes = { /** The chatReport which the transaction is associated with */ @@ -117,10 +116,8 @@ class ReportTransaction extends Component { ReportTransaction.displayName = 'ReportTransaction'; ReportTransaction.defaultProps = defaultProps; ReportTransaction.propTypes = propTypes; -export default compose( - withOnyx({ - rejectInProgress: { - key: ONYXKEYS.REJECT_IN_PROGRESS, - }, - }), -)(ReportTransaction); +export default withOnyx({ + rejectInProgress: { + key: ONYXKEYS.REJECT_IN_PROGRESS, + }, +})(ReportTransaction); From 74554169656ce51d463eec2bc90cdef0d397d80b Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Thu, 10 Jun 2021 18:21:45 +0300 Subject: [PATCH 12/24] remove default prop --- src/components/ReportTransaction.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/components/ReportTransaction.js b/src/components/ReportTransaction.js index 7e3e5c4cd236..ed227baf0e1d 100644 --- a/src/components/ReportTransaction.js +++ b/src/components/ReportTransaction.js @@ -4,9 +4,7 @@ import lodashGet from 'lodash/get'; import { Text, View, Pressable, ActivityIndicator, } from 'react-native'; -import { - withOnyx, -} from 'react-native-onyx'; +import {withOnyx} from 'react-native-onyx'; import ONYXKEYS from '../ONYXKEYS'; import styles from '../styles/styles'; import themeColors from '../styles/themes/default'; @@ -35,13 +33,12 @@ const propTypes = { /* Onyx Props */ /** List of transactionIDs in process of rejection */ - /* eslint-disable-next-line react/no-unused-prop-types */ + /* eslint-disable-next-line react/no-unused-prop-types, react/require-default-props */ rejectInProgress: PropTypes.arrayOf(PropTypes.string), }; const defaultProps = { canBeRejected: false, - rejectInProgress: [], }; class ReportTransaction extends Component { From f290d9aa661aab6bc695a5bcce63f29ad8338f23 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Thu, 10 Jun 2021 18:27:16 +0300 Subject: [PATCH 13/24] remove inline style --- src/components/ReportTransaction.js | 2 +- src/styles/styles.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/ReportTransaction.js b/src/components/ReportTransaction.js index ed227baf0e1d..37235e43f336 100644 --- a/src/components/ReportTransaction.js +++ b/src/components/ReportTransaction.js @@ -84,7 +84,7 @@ class ReportTransaction extends Component { styles.buttonSmall, styles.chatItemComposeSecondaryRowOffset, styles.mb3, - {minWidth: '20%'}, + styles.rejectIOU, ]} onPress={this.rejectTransaction} > diff --git a/src/styles/styles.js b/src/styles/styles.js index 170b7fea55c0..b5add8f2b40f 100644 --- a/src/styles/styles.js +++ b/src/styles/styles.js @@ -1603,6 +1603,10 @@ const webViewStyles = { fontFamily: fontFamily.GTA, flex: 1, }, + + rejectIOU: { + minWidth: '20%', + } }; /** From ea0257ac9c62c021e18a6c21147a425d3be5630c Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Thu, 10 Jun 2021 18:50:11 +0300 Subject: [PATCH 14/24] fixtypo in style.js --- src/styles/styles.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/styles/styles.js b/src/styles/styles.js index b5add8f2b40f..a72ed082a7d2 100644 --- a/src/styles/styles.js +++ b/src/styles/styles.js @@ -1521,6 +1521,10 @@ const styles = { cursorDisabled: { cursor: 'not-allowed', }, + + rejectIOU: { + minWidth: '20%', + }, }; const baseCodeTagStyles = { @@ -1603,10 +1607,6 @@ const webViewStyles = { fontFamily: fontFamily.GTA, flex: 1, }, - - rejectIOU: { - minWidth: '20%', - } }; /** From dcc7a50e46c3a304a25fadeeb06214cb19e16d6b Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Sat, 12 Jun 2021 11:20:51 +0300 Subject: [PATCH 15/24] undo new onyx key, use IOU --- src/ONYXKEYS.js | 3 --- src/components/ReportTransaction.js | 21 ++++++++++++--------- src/libs/actions/IOU.js | 10 +++++++--- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/ONYXKEYS.js b/src/ONYXKEYS.js index a1c0685be7f0..d7fcd65074f3 100755 --- a/src/ONYXKEYS.js +++ b/src/ONYXKEYS.js @@ -87,9 +87,6 @@ export default { // Indicates which locale should be used PREFERRED_LOCALE: 'preferredLocale', - // List of transactions that are in progress of being rejected - REJECT_IN_PROGRESS: 'rejectInProgress', - // User's Expensify Wallet USER_WALLET: 'userWallet', diff --git a/src/components/ReportTransaction.js b/src/components/ReportTransaction.js index 37235e43f336..2527bbc3b1c7 100644 --- a/src/components/ReportTransaction.js +++ b/src/components/ReportTransaction.js @@ -34,7 +34,9 @@ const propTypes = { /** List of transactionIDs in process of rejection */ /* eslint-disable-next-line react/no-unused-prop-types, react/require-default-props */ - rejectInProgress: PropTypes.arrayOf(PropTypes.string), + iou: PropTypes.shape({ + transactionsBeingRejected: PropTypes.arrayOf(PropTypes.string), + }), }; const defaultProps = { @@ -54,19 +56,20 @@ class ReportTransaction extends Component { chatReportID: this.props.chatReportID, transactionID: this.props.action.originalMessage.IOUTransactionID, comment: '', - rejectedIDs: this.props.rejectInProgress, + iou: this.props.iou, }); } - isRejected(rejectedIDs, transactionID) { - if (!rejectedIDs) { + isRejected() { + const IOUTransactionID = lodashGet(this.props.action, 'originalMessage.IOUTransactionID', ''); + const transactionsBeingRejected = lodashGet(this.props, 'iou.transactionsBeingRejected', []); + if (!transactionsBeingRejected || !transactionsBeingRejected.length) { return false; } - return rejectedIDs.includes(transactionID.toString()); + return transactionsBeingRejected.includes(IOUTransactionID.toString()); } render() { - const rejectedIDs = lodashGet(this.props, 'rejectInProgress', []); return ( { - this.isRejected(rejectedIDs, this.props.action.originalMessage.IOUTransactionID) + this.isRejected() ? ( console.error(`Error rejecting transaction: ${error}`)) .finally(() => { const withoutCurrentID = rejectedIDs.filter(id => id !== transactionID); - Onyx.set(ONYXKEYS.REJECT_IN_PROGRESS, withoutCurrentID); + Onyx.set(ONYXKEYS.IOU, {...iou, transactionsBeingRejected: withoutCurrentID}); }); } From d8978ad7614c654648ca4a3f1e0a10db6156d09d Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Sat, 12 Jun 2021 12:10:14 +0300 Subject: [PATCH 16/24] cleanup IOU.js --- src/libs/actions/IOU.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 8ddc6b5ac37c..cb1a9fdc1e48 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -132,14 +132,14 @@ function createIOUSplit(params) { * @param {Number} params.chatReportID * @param {String} params.transactionID * @param {String} params.comment - * @param {Object} params.rejectedIDs + * @param {Object} params.iou */ function rejectTransaction({ reportID, chatReportID, transactionID, comment, iou, }) { - const rejectedIDs = lodashGet(iou, 'transactionsBeingRejected', []); + const transactionsBeingRejected = lodashGet(iou, 'transactionsBeingRejected', []); Onyx.merge(ONYXKEYS.IOU, { - transactionsBeingRejected: [...rejectedIDs, transactionID], + transactionsBeingRejected: [...transactionsBeingRejected, transactionID], }); API.RejectTransaction({ reportID, @@ -161,7 +161,7 @@ function rejectTransaction({ }) .catch(error => console.error(`Error rejecting transaction: ${error}`)) .finally(() => { - const withoutCurrentID = rejectedIDs.filter(id => id !== transactionID); + const withoutCurrentID = transactionsBeingRejected.filter(id => id !== transactionID); Onyx.set(ONYXKEYS.IOU, {...iou, transactionsBeingRejected: withoutCurrentID}); }); } From 5848d1a96f9ee76f1c92097f98067ad1422721eb Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Mon, 14 Jun 2021 13:17:51 +0300 Subject: [PATCH 17/24] rm unnecessary toString --- src/components/ReportTransaction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportTransaction.js b/src/components/ReportTransaction.js index 2527bbc3b1c7..8b83a8300d5c 100644 --- a/src/components/ReportTransaction.js +++ b/src/components/ReportTransaction.js @@ -66,7 +66,7 @@ class ReportTransaction extends Component { if (!transactionsBeingRejected || !transactionsBeingRejected.length) { return false; } - return transactionsBeingRejected.includes(IOUTransactionID.toString()); + return transactionsBeingRejected.includes(IOUTransactionID); } render() { From 04e673bca08caf4a75a689b656f6d45d9b8da14f Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Tue, 15 Jun 2021 15:05:55 +0300 Subject: [PATCH 18/24] create new onyx key, replace array with object --- src/ONYXKEYS.js | 3 +++ src/components/ReportTransaction.js | 17 +++++++++-------- src/libs/actions/IOU.js | 14 +++++++------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/ONYXKEYS.js b/src/ONYXKEYS.js index d7fcd65074f3..c8367552f811 100755 --- a/src/ONYXKEYS.js +++ b/src/ONYXKEYS.js @@ -87,6 +87,9 @@ export default { // Indicates which locale should be used PREFERRED_LOCALE: 'preferredLocale', + /** List of transactionIDs in process of rejection */ + TRANSACTIONS_BEING_REJECTED: 'transactionsBeingRejected', + // User's Expensify Wallet USER_WALLET: 'userWallet', diff --git a/src/components/ReportTransaction.js b/src/components/ReportTransaction.js index 8b83a8300d5c..1e99b3b5a41f 100644 --- a/src/components/ReportTransaction.js +++ b/src/components/ReportTransaction.js @@ -5,6 +5,7 @@ import { Text, View, Pressable, ActivityIndicator, } from 'react-native'; import {withOnyx} from 'react-native-onyx'; +import _ from 'underscore'; import ONYXKEYS from '../ONYXKEYS'; import styles from '../styles/styles'; import themeColors from '../styles/themes/default'; @@ -34,8 +35,8 @@ const propTypes = { /** List of transactionIDs in process of rejection */ /* eslint-disable-next-line react/no-unused-prop-types, react/require-default-props */ - iou: PropTypes.shape({ - transactionsBeingRejected: PropTypes.arrayOf(PropTypes.string), + transactionsBeingRejected: PropTypes.shape({ + transactionID: PropTypes.bool, }), }; @@ -56,17 +57,17 @@ class ReportTransaction extends Component { chatReportID: this.props.chatReportID, transactionID: this.props.action.originalMessage.IOUTransactionID, comment: '', - iou: this.props.iou, }); } isRejected() { const IOUTransactionID = lodashGet(this.props.action, 'originalMessage.IOUTransactionID', ''); - const transactionsBeingRejected = lodashGet(this.props, 'iou.transactionsBeingRejected', []); - if (!transactionsBeingRejected || !transactionsBeingRejected.length) { + const transactionsBeingRejected = lodashGet(this.props, 'transactionsBeingRejected', {}); + console.log('****', transactionsBeingRejected, IOUTransactionID); + if (_.isEmpty(transactionsBeingRejected)) { return false; } - return transactionsBeingRejected.includes(IOUTransactionID); + return _.has(transactionsBeingRejected, IOUTransactionID); } render() { @@ -117,7 +118,7 @@ ReportTransaction.displayName = 'ReportTransaction'; ReportTransaction.defaultProps = defaultProps; ReportTransaction.propTypes = propTypes; export default withOnyx({ - iou: { - key: ONYXKEYS.IOU, + transactionsBeingRejected: { + key: ONYXKEYS.TRANSACTIONS_BEING_REJECTED, }, })(ReportTransaction); diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index cb1a9fdc1e48..89171a4ae55b 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1,7 +1,6 @@ import Onyx from 'react-native-onyx'; import {Linking} from 'react-native'; import _ from 'underscore'; -import lodashGet from 'lodash/get'; import CONST from '../../CONST'; import ONYXKEYS from '../../ONYXKEYS'; import ROUTES from '../../ROUTES'; @@ -135,11 +134,10 @@ function createIOUSplit(params) { * @param {Object} params.iou */ function rejectTransaction({ - reportID, chatReportID, transactionID, comment, iou, + reportID, chatReportID, transactionID, comment, }) { - const transactionsBeingRejected = lodashGet(iou, 'transactionsBeingRejected', []); - Onyx.merge(ONYXKEYS.IOU, { - transactionsBeingRejected: [...transactionsBeingRejected, transactionID], + Onyx.merge(ONYXKEYS.TRANSACTIONS_BEING_REJECTED, { + [transactionID]: true, }); API.RejectTransaction({ reportID, @@ -161,8 +159,10 @@ function rejectTransaction({ }) .catch(error => console.error(`Error rejecting transaction: ${error}`)) .finally(() => { - const withoutCurrentID = transactionsBeingRejected.filter(id => id !== transactionID); - Onyx.set(ONYXKEYS.IOU, {...iou, transactionsBeingRejected: withoutCurrentID}); + // setting as null deletes the tranactionID + Onyx.merge(ONYXKEYS.TRANSACTIONS_BEING_REJECTED, { + [transactionID]: null, + }); }); } From edb1d815de4976f4a43565918f3a6e74160f2cec Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Tue, 15 Jun 2021 15:08:12 +0300 Subject: [PATCH 19/24] rm console.log --- src/components/ReportTransaction.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/ReportTransaction.js b/src/components/ReportTransaction.js index 1e99b3b5a41f..b828729561c4 100644 --- a/src/components/ReportTransaction.js +++ b/src/components/ReportTransaction.js @@ -63,7 +63,6 @@ class ReportTransaction extends Component { isRejected() { const IOUTransactionID = lodashGet(this.props.action, 'originalMessage.IOUTransactionID', ''); const transactionsBeingRejected = lodashGet(this.props, 'transactionsBeingRejected', {}); - console.log('****', transactionsBeingRejected, IOUTransactionID); if (_.isEmpty(transactionsBeingRejected)) { return false; } From 5ade9cf9e969d9e8e29a278729fc934250bce8d7 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 16 Jun 2021 14:12:40 +0300 Subject: [PATCH 20/24] fix eslint warn --- src/styles/styles.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/styles/styles.js b/src/styles/styles.js index 068a158af2e7..cc504ae8cb23 100644 --- a/src/styles/styles.js +++ b/src/styles/styles.js @@ -1534,7 +1534,7 @@ const styles = { rejectIOU: { minWidth: '20%', }, - + workspaceInviteWelcome: { minHeight: 150, }, From 859b18a3adb586dea80b45e4f83d8b7a5223f6ea Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 16 Jun 2021 14:36:38 +0300 Subject: [PATCH 21/24] create new sizing utility --- src/components/ReportTransaction.js | 2 +- src/styles/styles.js | 4 ---- src/styles/utilities/sizing.js | 4 ++++ 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/ReportTransaction.js b/src/components/ReportTransaction.js index b828729561c4..31e473517ab4 100644 --- a/src/components/ReportTransaction.js +++ b/src/components/ReportTransaction.js @@ -87,7 +87,7 @@ class ReportTransaction extends Component { styles.buttonSmall, styles.chatItemComposeSecondaryRowOffset, styles.mb3, - styles.rejectIOU, + styles.w20, ]} onPress={this.rejectTransaction} > diff --git a/src/styles/styles.js b/src/styles/styles.js index cc504ae8cb23..8e5dccda69b6 100644 --- a/src/styles/styles.js +++ b/src/styles/styles.js @@ -1531,10 +1531,6 @@ const styles = { cursor: 'not-allowed', }, - rejectIOU: { - minWidth: '20%', - }, - workspaceInviteWelcome: { minHeight: 150, }, diff --git a/src/styles/utilities/sizing.js b/src/styles/utilities/sizing.js index 169aba760e03..c6f68a66d687 100644 --- a/src/styles/utilities/sizing.js +++ b/src/styles/utilities/sizing.js @@ -16,6 +16,10 @@ export default { width: '50%', }, + w20: { + width: '20%', + }, + mwn: { maxWidth: 'auto', }, From 2d296e729a13df1ee02b606a8b627df9f29e957d Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 16 Jun 2021 15:07:04 +0300 Subject: [PATCH 22/24] add docs --- src/components/ReportTransaction.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/ReportTransaction.js b/src/components/ReportTransaction.js index 31e473517ab4..cec3b823cd1d 100644 --- a/src/components/ReportTransaction.js +++ b/src/components/ReportTransaction.js @@ -36,6 +36,7 @@ const propTypes = { /** 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, }), }; @@ -60,7 +61,11 @@ class ReportTransaction extends Component { }); } - isRejected() { + /** + * 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)) { @@ -92,7 +97,7 @@ class ReportTransaction extends Component { onPress={this.rejectTransaction} > { - this.isRejected() + this.isBeingRejected() ? ( Date: Wed, 16 Jun 2021 19:37:34 +0300 Subject: [PATCH 23/24] rm param docs --- src/libs/actions/IOU.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index ad4296c4a8e8..3422e54e76dd 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -119,7 +119,6 @@ function createIOUSplit(params) { * @param {Number} params.chatReportID * @param {String} params.transactionID * @param {String} params.comment - * @param {Object} params.iou */ function rejectTransaction({ reportID, chatReportID, transactionID, comment, From beb9ebc572aefb128185a7bc3c95c64ec2a2acb4 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Thu, 17 Jun 2021 14:02:00 +0300 Subject: [PATCH 24/24] change comment style --- src/ONYXKEYS.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ONYXKEYS.js b/src/ONYXKEYS.js index 2a2146e710b1..ce9fec36759f 100755 --- a/src/ONYXKEYS.js +++ b/src/ONYXKEYS.js @@ -90,7 +90,7 @@ export default { // Indicates which locale should be used PREFERRED_LOCALE: 'preferredLocale', - /** List of transactionIDs in process of rejection */ + // List of transactionIDs in process of rejection TRANSACTIONS_BEING_REJECTED: 'transactionsBeingRejected', // User's Expensify Wallet