Skip to content

Commit

Permalink
Merge pull request #1157 from yoution/feature/shapeup_billing_account…
Browse files Browse the repository at this point in the history
…_protection

TC Billing Account Enhancement
  • Loading branch information
vikasrohit authored May 31, 2021
2 parents 32f3d47 + 2e8d91d commit d6be45b
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/actions/projects.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {
LOAD_PROJECT_BILLING_ACCOUNT,
LOAD_CHALLENGE_MEMBERS_SUCCESS,
LOAD_PROJECT_DETAILS
} from '../config/constants'
import { fetchProjectById } from '../services/projects'
import { fetchProjectById, fetchBillingAccount } from '../services/projects'

/**
* Loads project details
Expand All @@ -19,6 +20,13 @@ export function loadProject (projectId) {
members
})
}

// Loads billing account
dispatch({
type: LOAD_PROJECT_BILLING_ACCOUNT,
payload: fetchBillingAccount(projectId)
})

return project
})
})
Expand Down
5 changes: 5 additions & 0 deletions src/components/ChallengeEditor/ChallengeEditor.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,11 @@
}
}

.expiredMessage {
margin-left: 20px;
color: $red;
}

.bottomContainer {
display: inline-flex;
justify-content: space-between;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@
}
}

.expiredMessage {
margin-left: 20px;
color: $red;
}

.button {
height: 40px;
span {
Expand Down
3 changes: 3 additions & 0 deletions src/components/ChallengeEditor/ChallengeView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const ChallengeView = ({
projectDetail,
challenge,
attachments,
isBillingAccountExpired,
metadata,
challengeResources,
token,
Expand Down Expand Up @@ -197,6 +198,7 @@ const ChallengeView = ({
<span className={styles.fieldTitle}>Billing Account Id:</span>
{projectDetail.billingAccountId}
</span>
{isBillingAccountExpired && <span className={styles.expiredMessage}>Expired</span>}
</div>
</div>
{isBetaMode() && (
Expand Down Expand Up @@ -278,6 +280,7 @@ ChallengeView.propTypes = {
}).isRequired,
projectDetail: PropTypes.object,
challenge: PropTypes.object,
isBillingAccountExpired: PropTypes.bool,
attachments: PropTypes.array,
metadata: PropTypes.object,
token: PropTypes.string,
Expand Down
3 changes: 3 additions & 0 deletions src/components/ChallengeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,7 @@ class ChallengeEditor extends Component {
} = this.state
const {
isNew,
isBillingAccountExpired,
isLoading,
metadata,
uploadAttachments,
Expand Down Expand Up @@ -1483,6 +1484,7 @@ class ChallengeEditor extends Component {
<span className={styles.fieldTitle}>Billing Account Id:</span>
{projectDetail.billingAccountId}
</span>
{isBillingAccountExpired && <span className={styles.expiredMessage}>Expired</span>}
</div>
</div>
{isBetaMode() && (
Expand Down Expand Up @@ -1606,6 +1608,7 @@ ChallengeEditor.propTypes = {
projectDetail: PropTypes.object,
challengeResources: PropTypes.arrayOf(PropTypes.object),
isNew: PropTypes.bool.isRequired,
isBillingAccountExpired: PropTypes.bool,
projectId: PropTypes.string.isRequired,
challengeId: PropTypes.string,
metadata: PropTypes.object.isRequired,
Expand Down
6 changes: 6 additions & 0 deletions src/config/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ export const LOAD_PROJECTS_SUCCESS = 'LOAD_PROJECTS_SUCCESS'
export const LOAD_PROJECTS_PENDING = 'LOAD_PROJECTS_PENDING'
export const LOAD_PROJECTS_FAILURE = 'LOAD_PROJECTS_FAILURE'

// project billingAccount
export const LOAD_PROJECT_BILLING_ACCOUNT = 'LOAD_PROJECT_BILLING_ACCOUNT'
export const LOAD_PROJECT_BILLING_ACCOUNT_PENDING = 'LOAD_PROJECT_BILLING_ACCOUNT_PENDING'
export const LOAD_PROJECT_BILLING_ACCOUNT_FAILURE = 'LOAD_PROJECT_BILLING_ACCOUNT_FAILURE'
export const LOAD_PROJECT_BILLING_ACCOUNT_SUCCESS = 'LOAD_PROJECT_BILLING_ACCOUNT_SUCCESS'

export const SET_ACTIVE_PROJECT = 'SET_ACTIVE_PROJECT'

export const LOAD_USER_SUCCESS = 'LOAD_USER_SUCCESS'
Expand Down
6 changes: 6 additions & 0 deletions src/containers/ChallengeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ class ChallengeEditor extends Component {
const {
match,
isLoading,
isBillingAccountExpired,
isProjectLoading,
// challengeDetails,
challengeResources,
Expand Down Expand Up @@ -316,6 +317,7 @@ class ChallengeEditor extends Component {
<ChallengeEditorComponent
isLoading={isLoading}
challengeDetails={challengeDetails}
isBillingAccountExpired={isBillingAccountExpired}
challengeResources={challengeResources}
metadata={metadata}
projectId={_.get(match.params, 'projectId', null)}
Expand Down Expand Up @@ -343,6 +345,7 @@ class ChallengeEditor extends Component {
render={({ match }) => ((
<ChallengeEditorComponent
isLoading={isLoading}
isBillingAccountExpired={isBillingAccountExpired}
challengeDetails={challengeDetails}
challengeResources={challengeResources}
metadata={metadata}
Expand Down Expand Up @@ -371,6 +374,7 @@ class ChallengeEditor extends Component {
render={({ match }) => ((
<ChallengeViewComponent
isLoading={isLoading}
isBillingAccountExpired={isBillingAccountExpired}
metadata={metadata}
projectDetail={projectDetail}
challenge={challengeDetails}
Expand Down Expand Up @@ -418,6 +422,7 @@ ChallengeEditor.propTypes = {
challengeTypes: PropTypes.array
}),
isLoading: PropTypes.bool,
isBillingAccountExpired: PropTypes.bool,
createAttachments: PropTypes.func,
attachments: PropTypes.arrayOf(PropTypes.shape()),
token: PropTypes.string,
Expand All @@ -441,6 +446,7 @@ const mapStateToProps = ({ projects, challenges: { challengeDetails, challengeRe
challengeResources,
metadata,
isLoading,
isBillingAccountExpired: projects.isBillingAccountExpired,
isProjectLoading: projects.isLoading,
attachments,
token,
Expand Down
1 change: 0 additions & 1 deletion src/containers/Challenges/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ const mapStateToProps = ({ challenges, sidebar, projects }) => ({
activeProjectId: sidebar.activeProjectId,
projects: sidebar.projects,
projectDetail: projects.projectDetail

})

const mapDispatchToProps = {
Expand Down
25 changes: 24 additions & 1 deletion src/reducers/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
*/
import _ from 'lodash'
import {
LOAD_PROJECT_BILLING_ACCOUNT_PENDING,
LOAD_PROJECT_BILLING_ACCOUNT_SUCCESS,
LOAD_PROJECT_BILLING_ACCOUNT_FAILURE,
LOAD_PROJECT_DETAILS_FAILURE,
LOAD_PROJECT_DETAILS_PENDING,
LOAD_PROJECT_DETAILS_SUCCESS
} from '../config/constants'

const initialState = {
isLoading: false,
projectDetail: {}
projectDetail: {},
isBillingAccountExpired: false,
isBillingAccountLoading: false
}

export default function (state = initialState, action) {
Expand All @@ -28,6 +33,24 @@ export default function (state = initialState, action) {
hasProjectAccess: true,
isLoading: false
}
case LOAD_PROJECT_BILLING_ACCOUNT_PENDING:
return {
...state,
isBillingAccountLoading: true,
isBillingAccountExpired: false
}
case LOAD_PROJECT_BILLING_ACCOUNT_SUCCESS:
return {
...state,
isBillingAccountLoading: false,
isBillingAccountExpired: !action.payload.active
}
case LOAD_PROJECT_BILLING_ACCOUNT_FAILURE:
return {
...state,
isBillingAccountLoading: false,
isBillingAccountExpired: false
}
default:
return state
}
Expand Down
12 changes: 12 additions & 0 deletions src/services/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ import { axiosInstance } from './axiosWithAuth'
import * as queryString from 'query-string'
const { PROJECT_API_URL } = process.env

/**
* Get billing account based on project id
*
* @param {String} projectId Id of the project
*
* @returns {Promise<Object>} Billing account data
*/
export async function fetchBillingAccount (projectId) {
const response = await axiosInstance.get(`${PROJECT_API_URL}/${projectId}/billingAccount`)
return _.get(response, 'data')
}

/**
* Api request for fetching member's projects
* @returns {Promise<*>}
Expand Down

0 comments on commit d6be45b

Please sign in to comment.