Skip to content

Commit 2a6ff01

Browse files
committed
Billing account field in project default
1 parent 2d04a30 commit 2a6ff01

File tree

7 files changed

+131
-6
lines changed

7 files changed

+131
-6
lines changed

src/api/billingAccounts.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { axiosInstance as axios } from './requestInterceptor'
2+
import { TC_API_URL } from '../config/constants'
3+
4+
/**
5+
* Get a user groups based on it's member id and membership type
6+
*
7+
* @param {String} projectId Id of the project
8+
*
9+
* @returns {Promise<Object>} Billing accounts data
10+
*/
11+
export function fetchBillingAccounts(projectId) {
12+
return axios.get(`${TC_API_URL}/v5/projects/${projectId}/billingAccounts`)
13+
}
14+
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import React from 'react'
2+
import {HOC as hoc} from 'formsy-react'
3+
4+
import Select from '../../../../components/Select/Select'
5+
import {fetchBillingAccounts} from '../../../../api/billingAccounts'
6+
import {SALESFORCE_PROJECT_LEAD_LINK} from '../../../../config/constants'
7+
8+
import styles from './styles.module.scss'
9+
10+
class BillingAccountField extends React.Component {
11+
constructor (props) {
12+
super(props)
13+
14+
this.state = {
15+
billingAccounts: [],
16+
selectedBillingAccount: this.props.billingAccountId
17+
}
18+
19+
this.handleChange = this.handleChange.bind(this)
20+
this.mapOpts = this.mapOpts.bind(this)
21+
}
22+
23+
componentDidMount() {
24+
fetchBillingAccounts(this.props.projectId)
25+
.then(({data: billingAccounts}) => this.setState({billingAccounts}))
26+
.then(() => {
27+
if (this.props.billingAccountId) {
28+
this.setState(state => {
29+
const filteredArray = state.billingAccounts.filter(
30+
({tcBillingAccountId}) =>
31+
tcBillingAccountId === this.props.billingAccountId
32+
)
33+
if (filteredArray.length === 0) {
34+
const billingAccountObj = {
35+
name: '<Assigned Account>',
36+
tcBillingAccountId: this.props.billingAccountId
37+
}
38+
return {
39+
billingAccounts: [...state.billingAccounts, billingAccountObj],
40+
selectedBillingAccount: this.mapOpts(billingAccountObj)
41+
}
42+
} else {
43+
return {
44+
selectedBillingAccount: this.mapOpts(filteredArray[0])
45+
}
46+
}
47+
})
48+
}
49+
})
50+
.catch(console.error)
51+
}
52+
53+
handleChange(value) {
54+
this.setState({selectedBillingAccount: value})
55+
this.props.setValue(value.value)
56+
}
57+
58+
mapOpts(opt) {
59+
return {
60+
label: `${opt.name} (${opt.tcBillingAccountId})`,
61+
value: opt.tcBillingAccountId
62+
}
63+
}
64+
65+
render() {
66+
const mapOpts = opt => ({
67+
label: `${opt.name} (${opt.tcBillingAccountId})`,
68+
value: opt.tcBillingAccountId
69+
})
70+
return (
71+
<div className={styles.container}>
72+
<div>Choose a Billing Account</div>
73+
<Select
74+
placeholder={
75+
this.state.billingAccounts.length > 0
76+
? 'Select billing account'
77+
: 'No Billing Account Available'
78+
}
79+
heightAuto
80+
onChange={this.handleChange}
81+
value={this.state.selectedBillingAccount}
82+
options={this.state.billingAccounts.map(mapOpts)}
83+
isDisabled={this.state.billingAccounts.length === 0}
84+
/>
85+
<a
86+
className="tc-link"
87+
href={`${SALESFORCE_PROJECT_LEAD_LINK}${this.props.projectId}`}
88+
target="_blank"
89+
rel="noopener noreferrer"
90+
>
91+
Manage the billing account in Salesforce
92+
</a>
93+
</div>
94+
)
95+
}
96+
}
97+
98+
export default hoc(BillingAccountField)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.container {
2+
display: flex;
3+
flex-direction: column;
4+
gap: 10px;
5+
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const Formsy = FormsyForm.Formsy
66
import { updateProject } from '../../../actions/project'
77
import NDAField from '../NDAField'
88
import GroupsField from '../GroupsField'
9+
import BillingAccountField from '../BillingAccountField'
910

1011
import './EditProjectDefaultsForm.scss'
1112

@@ -40,7 +41,7 @@ class EditProjectDefaultsForm extends React.Component {
4041
}, {})
4142
const project = _.assign({}, this.state.project, reqProjectState)
4243
this.setState({project})
43-
const isProjectEqual = _.isEqual(this.state.project, this.props.project)
44+
const isProjectEqual = _.isEqual(project, this.props.project)
4445
if (!isProjectEqual && !this.state.enableButton) {
4546
this.setState({enableButton: true})
4647
} else if (isProjectEqual && this.state.enableButton !== false) {
@@ -80,6 +81,11 @@ class EditProjectDefaultsForm extends React.Component {
8081
name="groups"
8182
value={this.state.project.groups}
8283
/>
84+
<BillingAccountField
85+
name="billingAccountId"
86+
projectId={this.state.project.id}
87+
billingAccountId={this.state.project.billingAccountId}
88+
/>
8389
</div>
8490
<div className="section-footer section-footer-spec">
8591
<button

src/projects/detail/components/EditProjectDefaultsForm/EditProjectDefaultsForm.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
.container {
77
padding: 50px 0 70px 0;
88
margin: 0 50px 20px 50px;
9+
display: flex;
10+
flex-direction: column;
11+
gap: 20px;
912
}
1013
.radio-group-options {
1114
flex-direction: column;
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.container {
2-
margin: 10px 0;
3-
}
4-
.fieldName {
5-
margin-bottom: 10px;
2+
display: flex;
3+
flex-direction: column;
4+
gap: 10px;
65
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class GroupsField extends React.Component {
6767
render() {
6868
return (
6969
<div className={styles.container}>
70-
<div className={styles.fieldName}>Intended Work Groups</div>
70+
<div>Intended Work Groups</div>
7171
<FormsySelect
7272
name="groups-field"
7373
isMulti

0 commit comments

Comments
 (0)