Skip to content

Commit 6fe3ffb

Browse files
committed
fix: payment link for no setup
1 parent 52eb08c commit 6fe3ffb

File tree

3 files changed

+58
-13
lines changed

3 files changed

+58
-13
lines changed

src/shared/components/Settings/Preferences/List/data.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const data = [
1818
name: 'Payment',
1919
description: 'To setup your payments preferences, please click the “Go To Payments” button.',
2020
link: `${config.URL.COMMUNITY}/PactsMemberServlet?module=PaymentHistory&full_list=false`,
21+
altLink: `${config.URL.THRIVE}/articles/Payment%20Methods`,
2122
linkTitle: 'GO TO PAYMENTS',
2223
},
2324
];

src/shared/components/Settings/Preferences/List/index.jsx

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,39 @@
55
*/
66
import _ from 'lodash';
77
import React from 'react';
8+
import PT from 'prop-types';
89
import Item from './Item';
910
import data from './data';
1011

11-
const preferenceList = () => (
12+
const preferenceList = ({ paymentSetupCompleted }) => (
1213
<div>
1314
{
14-
_.map(data, item => (
15-
<Item
16-
icon={item.icon}
17-
key={item.id}
18-
id={item.id}
19-
title={item.name}
20-
description={item.description}
21-
link={item.link}
22-
linkTitle={item.linkTitle}
23-
/>
24-
))
15+
_.map(data, (item) => {
16+
let itemLink;
17+
if (item.id !== 'payment' || paymentSetupCompleted === true) {
18+
itemLink = item.link;
19+
} else {
20+
itemLink = item.altLink;
21+
}
22+
23+
return (
24+
<Item
25+
icon={item.icon}
26+
key={item.id}
27+
id={item.id}
28+
title={item.name}
29+
description={item.description}
30+
link={itemLink}
31+
linkTitle={item.linkTitle}
32+
/>
33+
);
34+
})
2535
}
2636
</div>
2737
);
2838

2939
export default preferenceList;
40+
41+
preferenceList.propTypes = {
42+
paymentSetupCompleted: PT.bool.isRequired,
43+
};

src/shared/components/Settings/Preferences/index.jsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable prefer-destructuring */
2+
import _ from 'lodash';
23
import React from 'react';
34
import PT from 'prop-types';
45
import { PrimaryButton } from 'topcoder-react-ui-kit';
@@ -13,18 +14,38 @@ export default class Preferences extends React.Component {
1314
constructor(props) {
1415
super(props);
1516
this.save = this.save.bind(this);
17+
this.loadOnboardingChecklistTrait = this.loadOnboardingChecklistTrait.bind(this);
1618
this.newsRef = React.createRef();
19+
20+
const { userTraits } = props;
21+
this.state = {
22+
onboardingChecklistTrait: this.loadOnboardingChecklistTrait(userTraits),
23+
};
1724
}
1825

1926
componentWillReceiveProps(nextProps) {
2027
const { isSaving, setIsSaving } = this.props;
28+
const onboardingChecklistTrait = this.loadOnboardingChecklistTrait(nextProps.userTraits);
29+
this.setState({
30+
onboardingChecklistTrait,
31+
});
2132
if (isSaving !== nextProps.isSaving) {
2233
setTimeout(() => {
2334
setIsSaving(false);
2435
}, 600);
2536
}
2637
}
2738

39+
/**
40+
* Get onboarding checklist trait
41+
* @param userTraits the all user traits
42+
*/
43+
loadOnboardingChecklistTrait = (userTraits) => {
44+
const trait = userTraits.filter(t => t.traitId === 'onboarding_checklist');
45+
const onboardingChecklist = trait.length === 0 ? {} : trait[0];
46+
return _.assign({}, onboardingChecklist);
47+
}
48+
2849
save() {
2950
const { isSaving, setIsSaving } = this.props;
3051
if (isSaving) {
@@ -37,6 +58,14 @@ export default class Preferences extends React.Component {
3758

3859
render() {
3960
const { profile: { email }, isSaving } = this.props;
61+
const { onboardingChecklistTrait } = this.state;
62+
63+
const traitData = onboardingChecklistTrait.traits.data[0];
64+
let paymentSetupCompleted = false;
65+
if (_.has(traitData, 'user_payment_method')) {
66+
paymentSetupCompleted = !_.isEmpty(traitData.user_payment_method.payment_method)
67+
&& traitData.user_payment_method.status === 'completed';
68+
}
4069

4170
const saveBtn = (
4271
<PrimaryButton
@@ -61,7 +90,7 @@ export default class Preferences extends React.Component {
6190
email={email}
6291
ref={this.newsRef}
6392
/>
64-
<PreferenceList />
93+
<PreferenceList paymentSetupCompleted={paymentSetupCompleted} />
6594
</div>
6695
</div>
6796
<div styleName="footer">{saveBtn}</div>
@@ -78,4 +107,5 @@ Preferences.propTypes = {
78107
profile: PT.shape().isRequired,
79108
isSaving: PT.bool,
80109
setIsSaving: PT.func.isRequired,
110+
userTraits: PT.array.isRequired,
81111
};

0 commit comments

Comments
 (0)