Skip to content

Commit 7ae9a4b

Browse files
vikasrohityoution
andauthored
Feature/billing account protection (#4394)
* fix: issue #4391 * Deployable feature branch Co-authored-by: yoution <[email protected]>
1 parent 0dac1df commit 7ae9a4b

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ workflows:
128128
- build-dev
129129
filters:
130130
branches:
131-
only: ['dev', 'feature/cf-2.20']
131+
only: ['dev', 'feature/billing_account_protection']
132132

133133
- deployTest01:
134134
context : org-global

src/projects/detail/components/BillingAccountField/index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
22
import moment from 'moment'
3+
import _ from 'lodash'
34
import {HOC as hoc} from 'formsy-react'
45

56
import Select from '../../../../components/Select/Select'
@@ -27,6 +28,8 @@ class BillingAccountField extends React.Component {
2728
isLoading: true,
2829
billingAccounts: [],
2930
selectedBillingAccount: null,
31+
defaultBillingAccount: null,
32+
isDefaultBillingAccountExpired: false,
3033
}
3134

3235
this.handleChange = this.handleChange.bind(this)
@@ -60,6 +63,10 @@ class BillingAccountField extends React.Component {
6063
})
6164

6265
billingAccounts = [selectedBillingAccount, ...billingAccounts]
66+
this.setState({
67+
defaultBillingAccount: selectedBillingAccount,
68+
isDefaultBillingAccountExpired: this.props.isExpired
69+
})
6370
}
6471
}
6572

@@ -74,11 +81,16 @@ class BillingAccountField extends React.Component {
7481
handleChange(value) {
7582
this.setState({ selectedBillingAccount: value })
7683
this.props.setValue(value ? value.value : null)
84+
this.props.setBillingAccountExpired && this.props.setBillingAccountExpired(this.isCurrentBillingAccountExpired(value))
85+
}
86+
87+
isCurrentBillingAccountExpired(nextSelectedBillingAccount) {
88+
const {defaultBillingAccount, isDefaultBillingAccountExpired, selectedBillingAccount} = this.state
89+
return isDefaultBillingAccountExpired && _.get(defaultBillingAccount, 'value') === _.get(nextSelectedBillingAccount || selectedBillingAccount, 'value')
7790
}
7891

7992
render() {
8093

81-
const {isExpired} = this.props
8294
const placeholder = this.state.billingAccounts.length > 0
8395
? 'Select billing account'
8496
: 'No Billing Account Available'
@@ -94,7 +106,7 @@ class BillingAccountField extends React.Component {
94106
isDisabled={this.state.billingAccounts.length === 0}
95107
showDropdownIndicator
96108
/>
97-
{isExpired && <span className="error-message">Expired</span>}
109+
{this.isCurrentBillingAccountExpired() && <span className="error-message">Expired</span>}
98110
{this.state.selectedBillingAccount && (
99111
<div className={styles.manageBillingAccountLinkWrapper}>
100112
<a

src/projects/detail/components/EditProjectDefaultsForm/EditProjectDefaultsForm.jsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ class EditProjectDefaultsForm extends React.Component {
1818

1919
this.state = {
2020
enableButton: false,
21-
isLoading: true
21+
isLoading: true,
22+
isBillingAccountExpired: false,
2223
}
2324

2425
this.handleChange = this.handleChange.bind(this)
2526
this.handleSubmit = this.handleSubmit.bind(this)
27+
this.setBillingAccountExpired = this.setBillingAccountExpired.bind(this)
2628
}
2729

2830
componentDidMount() {
@@ -35,6 +37,11 @@ class EditProjectDefaultsForm extends React.Component {
3537
}
3638
}
3739

40+
setBillingAccountExpired(value) {
41+
this.setState({
42+
isBillingAccountExpired: value
43+
})
44+
}
3845
handleChange(changed) {
3946
const keys = _.intersection(Object.keys(changed), Object.keys(this.state.project))
4047
const reqProjectState = keys.reduce((acc, curr) => {
@@ -88,13 +95,14 @@ class EditProjectDefaultsForm extends React.Component {
8895
projectId={this.state.project.id}
8996
isExpired={this.props.isBillingAccountExpired}
9097
value={this.state.project.billingAccountId}
98+
setBillingAccountExpired={this.setBillingAccountExpired}
9199
/>
92100
</div>
93101
<div className="section-footer section-footer-spec">
94102
<button
95103
className="tc-btn tc-btn-primary tc-btn-md"
96104
type="submit"
97-
disabled={!this.state.enableButton}
105+
disabled={this.state.isBillingAccountExpired || !this.state.enableButton}
98106
>
99107
Save
100108
</button>

0 commit comments

Comments
 (0)