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

Hide add payment button #4034

Merged
Merged
Show file tree
Hide file tree
Changes from all 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/actions/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function getBetas() {
function getUserDetails() {
API.Get({
returnValueList: 'account, loginList, nameValuePairs',
nvpNames: CONST.NVP.BLOCKED_FROM_CONCIERGE,
nvpNames: [CONST.NVP.BLOCKED_FROM_CONCIERGE, CONST.NVP.PAYPAL_ME_ADDRESS].join(','),
})
.then((response) => {
// Update the User onyx key
Expand Down
2 changes: 0 additions & 2 deletions src/pages/settings/Payments/AddPayPalMePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,13 @@ class AddPayPalMePage extends React.Component {
value={this.state.payPalMeUsername}
placeholder={this.props.translate('addPayPalMePage.yourPayPalUsername')}
onChangeText={text => this.setState({payPalMeUsername: text})}
editable={!this.props.payPalMeUsername}
returnKeyType="done"
/>
</View>
</View>
<FixedFooter>
<Button
success
isDisabled={Boolean(this.props.payPalMeUsername)}
onPress={this.setPayPalMeUsername}
style={[styles.mt3]}
text={this.props.translate('addPayPalMePage.addPayPalAccount')}
Expand Down
17 changes: 11 additions & 6 deletions src/pages/settings/Payments/PaymentMethodList.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,17 @@ class PaymentMethodList extends Component {
});
}

combinedPaymentMethods.push({
title: this.props.translate('paymentMethodList.addPaymentMethod'),
icon: Plus,
onPress: e => this.props.onPress(e),
key: 'addPaymentMethodButton',
});
// Don't show Add Payment Method button if user provided details for all possible payment methods.
// Right now only available method is Paypal.me
// When there is a new payment method, it needs to be added to following if condition.
if (!this.props.payPalMeUsername) {
combinedPaymentMethods.push({
title: this.props.translate('paymentMethodList.addPaymentMethod'),
icon: Plus,
onPress: e => this.props.onPress(e),
key: 'addPaymentMethodButton',
});
}

return combinedPaymentMethods;
}
Expand Down
32 changes: 26 additions & 6 deletions src/pages/settings/Payments/PaymentsPage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import React from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import ONYXKEYS from '../../../ONYXKEYS';
import PaymentMethodList from './PaymentMethodList';
import ROUTES from '../../../ROUTES';
import HeaderWithCloseButton from '../../../components/HeaderWithCloseButton';
Expand All @@ -18,9 +21,16 @@ import getClickedElementLocation from '../../../libs/getClickedElementLocation';
const PAYPAL = 'payPalMe';

const propTypes = {
/** User's paypal.me username if they have one */
payPalMeUsername: PropTypes.string,

...withLocalizePropTypes,
};

const defaultProps = {
payPalMeUsername: '',
};

class PaymentsPage extends React.Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -48,7 +58,9 @@ class PaymentsPage extends React.Component {
*/
paymentMethodPressed(nativeEvent, account) {
if (account) {
// TODO: Show the make default/delete popover
tugbadogan marked this conversation as resolved.
Show resolved Hide resolved
if (account === PAYPAL) {
Navigation.navigate(ROUTES.SETTINGS_ADD_PAYPAL_ME);
}
} else {
const position = getClickedElementLocation(nativeEvent);
this.setState({
Expand Down Expand Up @@ -104,11 +116,13 @@ class PaymentsPage extends React.Component {
left: this.state.anchorPositionLeft,
}}
>
<MenuItem
title="PayPal.me"
icon={PayPal}
onPress={() => this.addPaymentMethodTypePressed(PAYPAL)}
/>
{!this.props.payPalMeUsername && (
<MenuItem
title="PayPal.me"
icon={PayPal}
onPress={() => this.addPaymentMethodTypePressed(PAYPAL)}
/>
)}
</Popover>
</KeyboardAvoidingView>
</ScreenWrapper>
Expand All @@ -117,8 +131,14 @@ class PaymentsPage extends React.Component {
}

PaymentsPage.propTypes = propTypes;
PaymentsPage.defaultProps = defaultProps;
PaymentsPage.displayName = 'PaymentsPage';

export default compose(
withLocalize,
withOnyx({
payPalMeUsername: {
key: ONYXKEYS.NVP_PAYPAL_ME_ADDRESS,
},
}),
)(PaymentsPage);