Skip to content

Commit

Permalink
Merge pull request #1159 from topcoder-platform/develop
Browse files Browse the repository at this point in the history
Prod Release - 0.9.0
  • Loading branch information
vikasrohit authored Jun 3, 2021
2 parents 0df6294 + 51c2948 commit 89b7109
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 15 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
10 changes: 9 additions & 1 deletion src/components/ChallengeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,11 @@ class ChallengeEditor extends Component {
toggleLaunch (e) {
e.preventDefault()
if (this.validateChallenge()) {
this.setState({ isLaunch: true })
if (!this.props.isBillingAccountExpired) {
this.setState({ isLaunch: true })
} else {
this.setState({ isLaunch: true, error: 'Unable to activate challenge as Billing Account is not active.' })
}
}
}

Expand Down Expand Up @@ -1181,6 +1185,7 @@ class ChallengeEditor extends Component {
} = this.state
const {
isNew,
isBillingAccountExpired,
isLoading,
metadata,
uploadAttachments,
Expand Down Expand Up @@ -1278,6 +1283,7 @@ class ChallengeEditor extends Component {
errorMessage={this.state.error}
onCancel={this.resetModal}
onConfirm={this.onActiveChallenge}
disableConfirmButton={isBillingAccountExpired}
/>
)
}
Expand Down Expand Up @@ -1483,6 +1489,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 +1613,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
12 changes: 9 additions & 3 deletions src/components/ChallengesComponent/ChallengeCard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ class ChallengeCard extends React.Component {

onUpdateLaunch () {
if (!this.state.isLaunch) {
this.setState({ isLaunch: true })
if (!this.props.isBillingAccountExpired) {
this.setState({ isLaunch: true })
} else {
this.setState({ isLaunch: true, error: 'Unable to activate challenge as Billing Account is not active.' })
}
}
}

Expand Down Expand Up @@ -272,7 +276,7 @@ class ChallengeCard extends React.Component {

render () {
const { isLaunch, isConfirm, isSaving, isDeleteLaunch, isCheckChalengePermission, hasEditChallengePermission } = this.state
const { challenge, shouldShowCurrentPhase, reloadChallengeList } = this.props
const { challenge, shouldShowCurrentPhase, reloadChallengeList, isBillingAccountExpired } = this.props
const { phaseMessage, endTime } = getPhaseInfo(challenge)
const deleteMessage = isCheckChalengePermission
? 'Checking permissions...'
Expand Down Expand Up @@ -305,6 +309,7 @@ class ChallengeCard extends React.Component {
errorMessage={this.state.error}
onCancel={this.resetModal}
onConfirm={this.onLaunchChallenge}
disableConfirmButton={isBillingAccountExpired}
/>
)
}
Expand Down Expand Up @@ -364,7 +369,8 @@ ChallengeCard.propTypes = {
shouldShowCurrentPhase: PropTypes.bool,
reloadChallengeList: PropTypes.func,
partiallyUpdateChallengeDetails: PropTypes.func.isRequired,
deleteChallenge: PropTypes.func.isRequired
deleteChallenge: PropTypes.func.isRequired,
isBillingAccountExpired: PropTypes.bool
}

export default withRouter(ChallengeCard)
7 changes: 5 additions & 2 deletions src/components/ChallengesComponent/ChallengeList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ class ChallengeList extends Component {
perPage,
totalChallenges,
partiallyUpdateChallengeDetails,
deleteChallenge
deleteChallenge,
isBillingAccountExpired
} = this.props
if (warnMessage) {
return <Message warnMessage={warnMessage} />
Expand Down Expand Up @@ -215,6 +216,7 @@ class ChallengeList extends Component {
reloadChallengeList={this.reloadChallengeList}
partiallyUpdateChallengeDetails={partiallyUpdateChallengeDetails}
deleteChallenge={deleteChallenge}
isBillingAccountExpired={isBillingAccountExpired}
/>
</li>
)
Expand Down Expand Up @@ -258,7 +260,8 @@ ChallengeList.propTypes = {
perPage: PropTypes.number.isRequired,
totalChallenges: PropTypes.number.isRequired,
partiallyUpdateChallengeDetails: PropTypes.func.isRequired,
deleteChallenge: PropTypes.func.isRequired
deleteChallenge: PropTypes.func.isRequired,
isBillingAccountExpired: PropTypes.bool
}

export default ChallengeList
7 changes: 5 additions & 2 deletions src/components/ChallengesComponent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const ChallengesComponent = ({
perPage,
totalChallenges,
partiallyUpdateChallengeDetails,
deleteChallenge
deleteChallenge,
isBillingAccountExpired
}) => {
return (
<Sticky top={10}>
Expand Down Expand Up @@ -88,6 +89,7 @@ const ChallengesComponent = ({
totalChallenges={totalChallenges}
partiallyUpdateChallengeDetails={partiallyUpdateChallengeDetails}
deleteChallenge={deleteChallenge}
isBillingAccountExpired={isBillingAccountExpired}
/>
)}
</div>
Expand All @@ -112,7 +114,8 @@ ChallengesComponent.propTypes = {
perPage: PropTypes.number.isRequired,
totalChallenges: PropTypes.number.isRequired,
partiallyUpdateChallengeDetails: PropTypes.func.isRequired,
deleteChallenge: PropTypes.func.isRequired
deleteChallenge: PropTypes.func.isRequired,
isBillingAccountExpired: PropTypes.bool
}

ChallengesComponent.defaultProps = {
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
13 changes: 12 additions & 1 deletion src/containers/ChallengeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ class ChallengeEditor extends Component {
}

onLaunchChallenge () {
this.setState({ showLaunchModal: true })
if (!this.props.isBillingAccountExpired) {
this.setState({ showLaunchModal: true })
} else {
this.setState({ showLaunchModal: true, launchError: 'Unable to activate challenge as Billing Account is not active.' })
}
}

onCloseTask () {
Expand Down Expand Up @@ -236,6 +240,7 @@ class ChallengeEditor extends Component {
const {
match,
isLoading,
isBillingAccountExpired,
isProjectLoading,
// challengeDetails,
challengeResources,
Expand Down Expand Up @@ -288,6 +293,7 @@ class ChallengeEditor extends Component {
errorMessage={this.state.launchError}
onCancel={this.closeLaunchModal}
onConfirm={this.activateChallenge}
disableConfirmButton={isBillingAccountExpired}
/>
const closeTaskModal = <ConfirmationModal
title='Confirm Close Task'
Expand Down Expand Up @@ -316,6 +322,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 +350,7 @@ class ChallengeEditor extends Component {
render={({ match }) => ((
<ChallengeEditorComponent
isLoading={isLoading}
isBillingAccountExpired={isBillingAccountExpired}
challengeDetails={challengeDetails}
challengeResources={challengeResources}
metadata={metadata}
Expand Down Expand Up @@ -371,6 +379,7 @@ class ChallengeEditor extends Component {
render={({ match }) => ((
<ChallengeViewComponent
isLoading={isLoading}
isBillingAccountExpired={isBillingAccountExpired}
metadata={metadata}
projectDetail={projectDetail}
challenge={challengeDetails}
Expand Down Expand Up @@ -418,6 +427,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 +451,7 @@ const mapStateToProps = ({ projects, challenges: { challengeDetails, challengeRe
challengeResources,
metadata,
isLoading,
isBillingAccountExpired: projects.isBillingAccountExpired,
isProjectLoading: projects.isLoading,
attachments,
token,
Expand Down
11 changes: 7 additions & 4 deletions src/containers/Challenges/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ class Challenges extends Component {
totalChallenges,
setActiveProject,
partiallyUpdateChallengeDetails,
deleteChallenge
deleteChallenge,
isBillingAccountExpired
} = this.props
const { searchProjectName, onlyMyProjects } = this.state
const projectInfo = _.find(projects, { id: activeProjectId }) || {}
Expand Down Expand Up @@ -149,6 +150,7 @@ class Challenges extends Component {
totalChallenges={totalChallenges}
partiallyUpdateChallengeDetails={partiallyUpdateChallengeDetails}
deleteChallenge={deleteChallenge}
isBillingAccountExpired={isBillingAccountExpired}
/>
}
</Fragment>
Expand Down Expand Up @@ -176,16 +178,17 @@ Challenges.propTypes = {
loadProjects: PropTypes.func.isRequired,
setActiveProject: PropTypes.func.isRequired,
partiallyUpdateChallengeDetails: PropTypes.func.isRequired,
deleteChallenge: PropTypes.func.isRequired
deleteChallenge: PropTypes.func.isRequired,
isBillingAccountExpired: PropTypes.bool
}

const mapStateToProps = ({ challenges, sidebar, projects }) => ({
..._.omit(challenges, ['projectId']),
challengeProjectId: challenges.projectId,
activeProjectId: sidebar.activeProjectId,
projects: sidebar.projects,
projectDetail: projects.projectDetail

projectDetail: projects.projectDetail,
isBillingAccountExpired: projects.isBillingAccountExpired
})

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 89b7109

Please sign in to comment.