Skip to content

Commit 44f7cc0

Browse files
author
vikasrohit
authored
Merge pull request #994 from maxceem/issue-993
fix: Challenge activation issues #993
2 parents c632157 + a573722 commit 44f7cc0

File tree

6 files changed

+42
-17
lines changed

6 files changed

+42
-17
lines changed

src/actions/challenges.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,11 @@ export function partiallyUpdateChallengeDetails (challengeId, partialChallengeDe
258258
type: UPDATE_CHALLENGE_DETAILS_SUCCESS,
259259
challengeDetails: challenge
260260
})
261-
}).catch(() => {
261+
}).catch((error) => {
262262
dispatch({
263263
type: UPDATE_CHALLENGE_DETAILS_FAILURE
264264
})
265+
throw error
265266
})
266267
}
267268
}

src/components/ChallengesComponent/ChallengeCard/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import ChallengeTag from '../ChallengeTag'
1515
import styles from './ChallengeCard.module.scss'
1616
import { getFormattedDuration, formatDate } from '../../../util/date'
1717
import { CHALLENGE_STATUS, COMMUNITY_APP_URL, DIRECT_PROJECT_URL, MESSAGE, ONLINE_REVIEW_URL } from '../../../config/constants'
18-
import { patchChallenge } from '../../../services/challenges'
1918
import ConfirmationModal from '../../Modal/ConfirmationModal'
2019
import AlertModal from '../../Modal/AlertModal'
2120
import Tooltip from '../../Tooltip'
@@ -201,12 +200,16 @@ class ChallengeCard extends React.Component {
201200
}
202201

203202
async onLaunchChallenge () {
203+
const { partiallyUpdateChallengeDetails } = this.props
204204
if (this.state.isSaving) return
205205
const { challenge } = this.props
206206
try {
207207
this.setState({ isSaving: true })
208-
const response = await patchChallenge(challenge.id, { status: 'Active' })
209-
this.setState({ isLaunch: true, isConfirm: response.id, isSaving: false })
208+
// call action to update the challenge with a new status
209+
await partiallyUpdateChallengeDetails(challenge.id, {
210+
status: 'Active'
211+
})
212+
this.setState({ isLaunch: true, isConfirm: challenge.id, isSaving: false })
210213
} catch (e) {
211214
const error = _.get(e, 'response.data.message', 'Unable to activate the challenge')
212215
this.setState({ isSaving: false, error })
@@ -287,7 +290,8 @@ ChallengeCard.propTypes = {
287290
challenge: PropTypes.object,
288291
shouldShowCurrentPhase: PropTypes.bool,
289292
showError: PropTypes.func,
290-
reloadChallengeList: PropTypes.func
293+
reloadChallengeList: PropTypes.func,
294+
partiallyUpdateChallengeDetails: PropTypes.func.isRequired
291295
}
292296

293297
export default withRouter(ChallengeCard)

src/components/ChallengesComponent/ChallengeList/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ class ChallengeList extends Component {
101101
status,
102102
page,
103103
perPage,
104-
totalChallenges } = this.props
104+
totalChallenges,
105+
partiallyUpdateChallengeDetails
106+
} = this.props
105107
if (warnMessage) {
106108
return <Message warnMessage={warnMessage} />
107109
}
@@ -206,7 +208,13 @@ class ChallengeList extends Component {
206208
map(challenges, (c) => {
207209
return (
208210
<li className={styles.challengeItem} key={`challenge-card-${c.id}`}>
209-
<ChallengeCard shouldShowCurrentPhase={selectedTab === 0} challenge={c} showError={this.showError} reloadChallengeList={this.reloadChallengeList} />
211+
<ChallengeCard
212+
shouldShowCurrentPhase={selectedTab === 0}
213+
challenge={c}
214+
showError={this.showError}
215+
reloadChallengeList={this.reloadChallengeList}
216+
partiallyUpdateChallengeDetails={partiallyUpdateChallengeDetails}
217+
/>
210218
</li>
211219
)
212220
})
@@ -247,7 +255,8 @@ ChallengeList.propTypes = {
247255
loadChallengesByPage: PropTypes.func.isRequired,
248256
page: PropTypes.number.isRequired,
249257
perPage: PropTypes.number.isRequired,
250-
totalChallenges: PropTypes.number.isRequired
258+
totalChallenges: PropTypes.number.isRequired,
259+
partiallyUpdateChallengeDetails: PropTypes.func.isRequired
251260
}
252261

253262
export default ChallengeList

src/components/ChallengesComponent/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const ChallengesComponent = ({
2525
activeProjectId,
2626
page,
2727
perPage,
28-
totalChallenges
28+
totalChallenges,
29+
partiallyUpdateChallengeDetails
2930
}) => {
3031
return (
3132
<Sticky top={10}>
@@ -84,6 +85,7 @@ const ChallengesComponent = ({
8485
page={page}
8586
perPage={perPage}
8687
totalChallenges={totalChallenges}
88+
partiallyUpdateChallengeDetails={partiallyUpdateChallengeDetails}
8789
/>
8890
)}
8991
</div>
@@ -106,7 +108,8 @@ ChallengesComponent.propTypes = {
106108
loadChallengesByPage: PropTypes.func.isRequired,
107109
page: PropTypes.number.isRequired,
108110
perPage: PropTypes.number.isRequired,
109-
totalChallenges: PropTypes.number.isRequired
111+
totalChallenges: PropTypes.number.isRequired,
112+
partiallyUpdateChallengeDetails: PropTypes.func.isRequired
110113
}
111114

112115
ChallengesComponent.defaultProps = {

src/containers/ChallengeEditor/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,25 @@ class ChallengeEditor extends Component {
153153
}
154154

155155
async activateChallenge () {
156+
const { partiallyUpdateChallengeDetails } = this.props
156157
if (this.state.isLaunching) return
157158
const { challengeDetails } = this.props
158159
try {
159160
this.setState({ isLaunching: true })
160-
const response = await patchChallenge(challengeDetails.id, { status: 'Active' })
161+
// call action to update the challenge status
162+
const action = await partiallyUpdateChallengeDetails(challengeDetails.id, {
163+
status: 'Active'
164+
})
161165
this.setState({
162166
isLaunching: false,
163167
showLaunchModal: false,
164168
showSuccessModal: true,
165169
suceessMessage: MESSAGE.CHALLENGE_LAUNCH_SUCCESS,
166-
challengeDetails: { ...challengeDetails, status: response.status }
170+
challengeDetails: action.challengeDetails
167171
})
168172
} catch (e) {
169173
const error = _.get(e, 'response.data.message', 'Unable to activate the challenge')
170-
this.setState({ isLaunching: false, showLaunchModal: false, launchError: error })
174+
this.setState({ isLaunching: false, launchError: error })
171175
}
172176
}
173177

src/containers/Challenges/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { DebounceInput } from 'react-debounce-input'
1010
import ChallengesComponent from '../../components/ChallengesComponent'
1111
import ProjectCard from '../../components/ProjectCard'
1212
import Loader from '../../components/Loader'
13-
import { loadChallengesByPage } from '../../actions/challenges'
13+
import { loadChallengesByPage, partiallyUpdateChallengeDetails } from '../../actions/challenges'
1414
import { loadProject } from '../../actions/projects'
1515
import { loadProjects, setActiveProject, resetSidebarActiveParams } from '../../actions/sidebar'
1616
import {
@@ -85,7 +85,8 @@ class Challenges extends Component {
8585
page,
8686
perPage,
8787
totalChallenges,
88-
setActiveProject
88+
setActiveProject,
89+
partiallyUpdateChallengeDetails
8990
} = this.props
9091
const { searchProjectName, onlyMyProjects } = this.state
9192
const projectInfo = _.find(projects, { id: activeProjectId }) || {}
@@ -145,6 +146,7 @@ class Challenges extends Component {
145146
page={page}
146147
perPage={perPage}
147148
totalChallenges={totalChallenges}
149+
partiallyUpdateChallengeDetails={partiallyUpdateChallengeDetails}
148150
/>
149151
}
150152
</Fragment>
@@ -170,7 +172,8 @@ Challenges.propTypes = {
170172
perPage: PropTypes.number.isRequired,
171173
totalChallenges: PropTypes.number.isRequired,
172174
loadProjects: PropTypes.func.isRequired,
173-
setActiveProject: PropTypes.func.isRequired
175+
setActiveProject: PropTypes.func.isRequired,
176+
partiallyUpdateChallengeDetails: PropTypes.func.isRequired
174177
}
175178

176179
const mapStateToProps = ({ challenges, sidebar, projects }) => ({
@@ -187,7 +190,8 @@ const mapDispatchToProps = {
187190
resetSidebarActiveParams,
188191
loadProject,
189192
loadProjects,
190-
setActiveProject
193+
setActiveProject,
194+
partiallyUpdateChallengeDetails
191195
}
192196

193197
export default connect(mapStateToProps, mapDispatchToProps)(Challenges)

0 commit comments

Comments
 (0)