Skip to content

Commit d6be45b

Browse files
author
vikasrohit
authored
Merge pull request #1157 from yoution/feature/shapeup_billing_account_protection
TC Billing Account Enhancement
2 parents 32f3d47 + 2e8d91d commit d6be45b

File tree

10 files changed

+73
-3
lines changed

10 files changed

+73
-3
lines changed

src/actions/projects.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import {
2+
LOAD_PROJECT_BILLING_ACCOUNT,
23
LOAD_CHALLENGE_MEMBERS_SUCCESS,
34
LOAD_PROJECT_DETAILS
45
} from '../config/constants'
5-
import { fetchProjectById } from '../services/projects'
6+
import { fetchProjectById, fetchBillingAccount } from '../services/projects'
67

78
/**
89
* Loads project details
@@ -19,6 +20,13 @@ export function loadProject (projectId) {
1920
members
2021
})
2122
}
23+
24+
// Loads billing account
25+
dispatch({
26+
type: LOAD_PROJECT_BILLING_ACCOUNT,
27+
payload: fetchBillingAccount(projectId)
28+
})
29+
2230
return project
2331
})
2432
})

src/components/ChallengeEditor/ChallengeEditor.module.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,11 @@
414414
}
415415
}
416416

417+
.expiredMessage {
418+
margin-left: 20px;
419+
color: $red;
420+
}
421+
417422
.bottomContainer {
418423
display: inline-flex;
419424
justify-content: space-between;

src/components/ChallengeEditor/ChallengeView/ChallengeView.module.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@
255255
}
256256
}
257257

258+
.expiredMessage {
259+
margin-left: 20px;
260+
color: $red;
261+
}
262+
258263
.button {
259264
height: 40px;
260265
span {

src/components/ChallengeEditor/ChallengeView/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const ChallengeView = ({
3131
projectDetail,
3232
challenge,
3333
attachments,
34+
isBillingAccountExpired,
3435
metadata,
3536
challengeResources,
3637
token,
@@ -197,6 +198,7 @@ const ChallengeView = ({
197198
<span className={styles.fieldTitle}>Billing Account Id:</span>
198199
{projectDetail.billingAccountId}
199200
</span>
201+
{isBillingAccountExpired && <span className={styles.expiredMessage}>Expired</span>}
200202
</div>
201203
</div>
202204
{isBetaMode() && (
@@ -278,6 +280,7 @@ ChallengeView.propTypes = {
278280
}).isRequired,
279281
projectDetail: PropTypes.object,
280282
challenge: PropTypes.object,
283+
isBillingAccountExpired: PropTypes.bool,
281284
attachments: PropTypes.array,
282285
metadata: PropTypes.object,
283286
token: PropTypes.string,

src/components/ChallengeEditor/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,7 @@ class ChallengeEditor extends Component {
11811181
} = this.state
11821182
const {
11831183
isNew,
1184+
isBillingAccountExpired,
11841185
isLoading,
11851186
metadata,
11861187
uploadAttachments,
@@ -1483,6 +1484,7 @@ class ChallengeEditor extends Component {
14831484
<span className={styles.fieldTitle}>Billing Account Id:</span>
14841485
{projectDetail.billingAccountId}
14851486
</span>
1487+
{isBillingAccountExpired && <span className={styles.expiredMessage}>Expired</span>}
14861488
</div>
14871489
</div>
14881490
{isBetaMode() && (
@@ -1606,6 +1608,7 @@ ChallengeEditor.propTypes = {
16061608
projectDetail: PropTypes.object,
16071609
challengeResources: PropTypes.arrayOf(PropTypes.object),
16081610
isNew: PropTypes.bool.isRequired,
1611+
isBillingAccountExpired: PropTypes.bool,
16091612
projectId: PropTypes.string.isRequired,
16101613
challengeId: PropTypes.string,
16111614
metadata: PropTypes.object.isRequired,

src/config/constants.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ export const LOAD_PROJECTS_SUCCESS = 'LOAD_PROJECTS_SUCCESS'
4444
export const LOAD_PROJECTS_PENDING = 'LOAD_PROJECTS_PENDING'
4545
export const LOAD_PROJECTS_FAILURE = 'LOAD_PROJECTS_FAILURE'
4646

47+
// project billingAccount
48+
export const LOAD_PROJECT_BILLING_ACCOUNT = 'LOAD_PROJECT_BILLING_ACCOUNT'
49+
export const LOAD_PROJECT_BILLING_ACCOUNT_PENDING = 'LOAD_PROJECT_BILLING_ACCOUNT_PENDING'
50+
export const LOAD_PROJECT_BILLING_ACCOUNT_FAILURE = 'LOAD_PROJECT_BILLING_ACCOUNT_FAILURE'
51+
export const LOAD_PROJECT_BILLING_ACCOUNT_SUCCESS = 'LOAD_PROJECT_BILLING_ACCOUNT_SUCCESS'
52+
4753
export const SET_ACTIVE_PROJECT = 'SET_ACTIVE_PROJECT'
4854

4955
export const LOAD_USER_SUCCESS = 'LOAD_USER_SUCCESS'

src/containers/ChallengeEditor/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ class ChallengeEditor extends Component {
236236
const {
237237
match,
238238
isLoading,
239+
isBillingAccountExpired,
239240
isProjectLoading,
240241
// challengeDetails,
241242
challengeResources,
@@ -316,6 +317,7 @@ class ChallengeEditor extends Component {
316317
<ChallengeEditorComponent
317318
isLoading={isLoading}
318319
challengeDetails={challengeDetails}
320+
isBillingAccountExpired={isBillingAccountExpired}
319321
challengeResources={challengeResources}
320322
metadata={metadata}
321323
projectId={_.get(match.params, 'projectId', null)}
@@ -343,6 +345,7 @@ class ChallengeEditor extends Component {
343345
render={({ match }) => ((
344346
<ChallengeEditorComponent
345347
isLoading={isLoading}
348+
isBillingAccountExpired={isBillingAccountExpired}
346349
challengeDetails={challengeDetails}
347350
challengeResources={challengeResources}
348351
metadata={metadata}
@@ -371,6 +374,7 @@ class ChallengeEditor extends Component {
371374
render={({ match }) => ((
372375
<ChallengeViewComponent
373376
isLoading={isLoading}
377+
isBillingAccountExpired={isBillingAccountExpired}
374378
metadata={metadata}
375379
projectDetail={projectDetail}
376380
challenge={challengeDetails}
@@ -418,6 +422,7 @@ ChallengeEditor.propTypes = {
418422
challengeTypes: PropTypes.array
419423
}),
420424
isLoading: PropTypes.bool,
425+
isBillingAccountExpired: PropTypes.bool,
421426
createAttachments: PropTypes.func,
422427
attachments: PropTypes.arrayOf(PropTypes.shape()),
423428
token: PropTypes.string,
@@ -441,6 +446,7 @@ const mapStateToProps = ({ projects, challenges: { challengeDetails, challengeRe
441446
challengeResources,
442447
metadata,
443448
isLoading,
449+
isBillingAccountExpired: projects.isBillingAccountExpired,
444450
isProjectLoading: projects.isLoading,
445451
attachments,
446452
token,

src/containers/Challenges/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ const mapStateToProps = ({ challenges, sidebar, projects }) => ({
185185
activeProjectId: sidebar.activeProjectId,
186186
projects: sidebar.projects,
187187
projectDetail: projects.projectDetail
188-
189188
})
190189

191190
const mapDispatchToProps = {

src/reducers/projects.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33
*/
44
import _ from 'lodash'
55
import {
6+
LOAD_PROJECT_BILLING_ACCOUNT_PENDING,
7+
LOAD_PROJECT_BILLING_ACCOUNT_SUCCESS,
8+
LOAD_PROJECT_BILLING_ACCOUNT_FAILURE,
69
LOAD_PROJECT_DETAILS_FAILURE,
710
LOAD_PROJECT_DETAILS_PENDING,
811
LOAD_PROJECT_DETAILS_SUCCESS
912
} from '../config/constants'
1013

1114
const initialState = {
1215
isLoading: false,
13-
projectDetail: {}
16+
projectDetail: {},
17+
isBillingAccountExpired: false,
18+
isBillingAccountLoading: false
1419
}
1520

1621
export default function (state = initialState, action) {
@@ -28,6 +33,24 @@ export default function (state = initialState, action) {
2833
hasProjectAccess: true,
2934
isLoading: false
3035
}
36+
case LOAD_PROJECT_BILLING_ACCOUNT_PENDING:
37+
return {
38+
...state,
39+
isBillingAccountLoading: true,
40+
isBillingAccountExpired: false
41+
}
42+
case LOAD_PROJECT_BILLING_ACCOUNT_SUCCESS:
43+
return {
44+
...state,
45+
isBillingAccountLoading: false,
46+
isBillingAccountExpired: !action.payload.active
47+
}
48+
case LOAD_PROJECT_BILLING_ACCOUNT_FAILURE:
49+
return {
50+
...state,
51+
isBillingAccountLoading: false,
52+
isBillingAccountExpired: false
53+
}
3154
default:
3255
return state
3356
}

src/services/projects.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ import { axiosInstance } from './axiosWithAuth'
33
import * as queryString from 'query-string'
44
const { PROJECT_API_URL } = process.env
55

6+
/**
7+
* Get billing account based on project id
8+
*
9+
* @param {String} projectId Id of the project
10+
*
11+
* @returns {Promise<Object>} Billing account data
12+
*/
13+
export async function fetchBillingAccount (projectId) {
14+
const response = await axiosInstance.get(`${PROJECT_API_URL}/${projectId}/billingAccount`)
15+
return _.get(response, 'data')
16+
}
17+
618
/**
719
* Api request for fetching member's projects
820
* @returns {Promise<*>}

0 commit comments

Comments
 (0)