Skip to content

Commit 5a0c8d1

Browse files
author
Vikas Agarwal
committed
fix: clean up, avoid using componentWillReceiveProps and triggering state changes in constructor.
1 parent 8d0f3fa commit 5a0c8d1

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

src/components/ChallengeEditor/index.js

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -113,30 +113,18 @@ class ChallengeEditor extends Component {
113113
this.getTemplatePhases = this.getTemplatePhases.bind(this)
114114
this.getAvailableTimelineTemplates = this.getAvailableTimelineTemplates.bind(this)
115115
this.autoUpdateChallengeThrottled = _.throttle(this.autoUpdateChallenge.bind(this), 3000) // 3s
116-
this.resetChallengeData((newState, finish) => {
117-
this.state = {
118-
...this.state,
119-
...newState
120-
}
121-
if (finish) {
122-
finish()
123-
}
124-
})
125116
}
126117

127-
componentDidUpdate () {
118+
componentDidMount () {
128119
this.resetChallengeData(this.setState.bind(this))
129120
}
130121

131-
componentWillReceiveProps (nextProps) {
132-
// if member details weren't initially loaded and now they got loaded, then set them to the state
133-
if (!this.state.assignedMemberDetails && nextProps.assignedMemberDetails) {
134-
this.setState({ assignedMemberDetails: nextProps.assignedMemberDetails })
135-
}
122+
componentDidUpdate () {
123+
this.resetChallengeData(this.setState.bind(this))
136124
}
137125

138126
async resetChallengeData (setState = () => {}) {
139-
const { isNew, challengeDetails, metadata, attachments, challengeId } = this.props
127+
const { isNew, challengeDetails, metadata, attachments, challengeId, assignedMemberDetails } = this.props
140128
if (
141129
challengeDetails &&
142130
challengeDetails.id &&
@@ -160,10 +148,11 @@ class ChallengeEditor extends Component {
160148
}
161149
challengeData.copilot = copilot || copilotFromResources
162150
challengeData.reviewer = reviewer || reviewerFromResources
163-
const challengeDetail = { ...dropdowns['newChallenge'], ...challengeData }
151+
const challengeDetail = { ...challengeData }
164152
const isOpenAdvanceSettings = challengeDetail.groups.length > 0
165153
setState({
166154
challenge: challengeDetail,
155+
assignedMemberDetails,
167156
draftChallenge: { data: {
168157
..._.cloneDeep(challengeDetails),
169158
copilot: challengeData.copilot,

0 commit comments

Comments
 (0)