11import React from 'react'
22import moment from 'moment'
3+ import _ from 'lodash'
34import { HOC as hoc } from 'formsy-react'
45
56import 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
0 commit comments