Skip to content

Commit 20ddf80

Browse files
committed
Merge branch 'integration-v5-challenge-api' into issue-4549
2 parents a0661f4 + a2d866b commit 20ddf80

File tree

6 files changed

+55
-16
lines changed

6 files changed

+55
-16
lines changed

src/shared/actions/challenge-listing/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ function getAllActiveChallengesDone(uuid, tokenV3) {
139139
return getAllActiveChallengesWithUsersDone(uuid, tokenV3, filter);
140140
}
141141

142+
function getAllUserChallengesInit(uuid) {
143+
return uuid;
144+
}
145+
146+
function getAllUserChallengesDone(uuid, tokenV3) {
147+
const memberId = decodeToken(tokenV3).userId;
148+
const filter = { status: 'Active', memberId };
149+
return getAllActiveChallengesWithUsersDone(uuid, tokenV3, filter);
150+
}
151+
142152
/**
143153
* Gets 1 page of active challenges (including marathon matches) from the backend.
144154
* Once this action is completed any active challenges saved to the state before
@@ -316,6 +326,9 @@ export default createActions({
316326
GET_ALL_ACTIVE_CHALLENGES_INIT: getAllActiveChallengesInit,
317327
GET_ALL_ACTIVE_CHALLENGES_DONE: getAllActiveChallengesDone,
318328

329+
GET_ALL_USER_CHALLENGES_INIT: getAllUserChallengesInit,
330+
GET_ALL_USER_CHALLENGES_DONE: getAllUserChallengesDone,
331+
319332
GET_ALL_RECOMMENDED_CHALLENGES_INIT: getAllRecommendedChallengesInit,
320333
GET_ALL_RECOMMENDED_CHALLENGES_DONE: getAllRecommendedChallengesDone,
321334

src/shared/components/Dashboard/CurrentActivity/Challenges/ChallengeCard/index.jsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,19 @@ export default function ChallengeCard({
4545
// unregisterFromChallenge,
4646
}) {
4747
const {
48-
currentPhases,
48+
phases,
4949
legacy,
5050
id,
5151
registrationStartDate,
5252
status,
53-
subTrack,
5453
userDetails,
5554
} = challenge;
5655

56+
const { track } = legacy;
57+
5758
let EventTag;
5859
// let TrackTag;
59-
switch (legacy.track) {
60+
switch (track) {
6061
case 'DATA_SCIENCE':
6162
EventTag = DataScienceTrackEventTag;
6263
// TrackTag = DataScienceTrackTag;
@@ -70,6 +71,7 @@ export default function ChallengeCard({
7071
// TrackTag = DevelopmentTrackTag;
7172
break;
7273
default:
74+
EventTag = DevelopmentTrackEventTag;
7375
}
7476

7577
const forumEndpoint = _.toLower(legacy.track) === 'design'
@@ -94,7 +96,7 @@ export default function ChallengeCard({
9496

9597
const submitter = roles.includes('Submitter');
9698
const submitted = _.get(userDetails, 'hasUserSubmittedForReview');
97-
const nextPhase = currentPhases && _.last(currentPhases);
99+
const nextPhase = phases && _.last(phases);
98100

99101
const nextPhaseType = _.get(nextPhase, 'phaseType');
100102

@@ -158,14 +160,14 @@ export default function ChallengeCard({
158160
<EventTag
159161
onClick={
160162
() => setImmediate(
161-
() => setChallengeListingFilter({ subtracks: [subTrack] }),
163+
() => setChallengeListingFilter({ subtracks: [track] }),
162164
)
163165
}
164166
theme={{ button: style.tag }}
165167
to={`/challenges?filter[subtracks][0]=${
166-
encodeURIComponent(subTrack)}`}
168+
encodeURIComponent(track)}`}
167169
>
168-
{normalizeSubTrackTagForRendering(challenge.subTrack)}
170+
{normalizeSubTrackTagForRendering(track)}
169171
</EventTag>
170172
{
171173
isTco ? (
@@ -280,12 +282,11 @@ ChallengeCard.propTypes = {
280282
}).isRequired,
281283
id: PT.oneOfType([PT.number, PT.string]).isRequired,
282284
name: PT.string.isRequired,
283-
currentPhases: PT.any,
285+
phases: PT.any,
284286
registrationStartDate: PT.any,
285287
status: PT.any,
286288
userDetails: PT.any,
287289
events: PT.any,
288-
subTrack: PT.string.isRequired,
289290
}).isRequired,
290291
selectChallengeDetailsTab: PT.func.isRequired,
291292
setChallengeListingFilter: PT.func.isRequired,

src/shared/components/Dashboard/CurrentActivity/index.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,13 @@ export default class MyChallenges extends React.Component {
130130
}
131131
}
132132

133+
MyChallenges.defaultProps = {
134+
challenges: [],
135+
};
136+
133137
MyChallenges.propTypes = {
134138
challengeFilter: PT.string.isRequired,
135-
challenges: PT.arrayOf(PT.object).isRequired,
139+
challenges: PT.arrayOf(PT.object),
136140
challengesLoading: PT.bool.isRequired,
137141
communities: PT.arrayOf(PT.object).isRequired,
138142
communitiesLoading: PT.bool.isRequired,

src/shared/containers/Dashboard/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ function mapDispatchToProps(dispatch) {
366366
return {
367367
getAllActiveChallenges: (tokenV3) => {
368368
const uuid = shortId();
369-
dispatch(challengeListingActions.challengeListing.getAllActiveChallengesInit(uuid));
370-
dispatch(challengeListingActions.challengeListing.getAllActiveChallengesDone(uuid, tokenV3));
369+
dispatch(challengeListingActions.challengeListing.getAllUserChallengesInit(uuid));
370+
dispatch(challengeListingActions.challengeListing.getAllUserChallengesDone(uuid, tokenV3));
371371
},
372372
getCommunityList: (auth) => {
373373
const uuid = shortId();

src/shared/containers/challenge-detail/index.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -843,12 +843,12 @@ const mapDispatchToProps = (dispatch) => {
843843
dispatch(a.getDetailsDone(challengeId, tokens.tokenV3, tokens.tokenV2))
844844
.then((res) => {
845845
const ch = res.payload;
846-
if (ch.track === 'DESIGN') {
846+
if (ch.legacy.track === 'DESIGN') {
847847
const p = ch.allPhases || ch.phases || []
848848
.filter(x => x.name === 'Checkpoint Review');
849849
if (p.length && !p[0].isOpen) {
850850
dispatch(a.fetchCheckpointsInit());
851-
dispatch(a.fetchCheckpointsDone(tokens.tokenV2, challengeId));
851+
dispatch(a.fetchCheckpointsDone(tokens.tokenV2, ch.legacyId));
852852
} else dispatch(a.dropCheckpoints());
853853
} else dispatch(a.dropCheckpoints());
854854
if (ch.status === 'COMPLETED') {
@@ -867,11 +867,11 @@ const mapDispatchToProps = (dispatch) => {
867867
const a = actions.challenge;
868868
dispatch(a.getDetailsDone(challengeId, tokens.tokenV3, tokens.tokenV2))
869869
.then((challengeDetails) => {
870-
if (challengeDetails.track === 'DESIGN') {
870+
if (challengeDetails.legacy.track === 'DESIGN') {
871871
const p = challengeDetails.allPhases || challengeDetails.phases || []
872872
.filter(x => x.name === 'Checkpoint Review');
873873
if (p.length && !p[0].isOpen) {
874-
dispatch(a.fetchCheckpointsDone(tokens.tokenV2, challengeId));
874+
dispatch(a.fetchCheckpointsDone(tokens.tokenV2, challengeDetails.legacyId));
875875
}
876876
}
877877
return challengeDetails;

src/shared/reducers/challenge-listing/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ function onGetAllActiveChallengesDone(state, { error, payload }) {
5252
};
5353
}
5454

55+
function onGetAllUserChallengesInit(state, { payload }) {
56+
return { ...state, loadingActiveChallengesUUID: payload };
57+
}
58+
function onGetAllUserChallengesDone(state, { error, payload }) {
59+
if (error) {
60+
logger.error(payload);
61+
return state;
62+
}
63+
const { challenges } = payload || [];
64+
65+
return {
66+
...state,
67+
challenges,
68+
lastUpdateOfActiveChallenges: Date.now(),
69+
loadingActiveChallengesUUID: '',
70+
};
71+
}
72+
5573
/**
5674
* Called when 1st page of ative challenges is loaded from `/challenges` api
5775
* @param {*} state
@@ -502,6 +520,9 @@ function create(initialState) {
502520
[a.getAllActiveChallengesInit]: onGetAllActiveChallengesInit,
503521
[a.getAllActiveChallengesDone]: onGetAllActiveChallengesDone,
504522

523+
[a.getAllUserChallengesInit]: onGetAllUserChallengesInit,
524+
[a.getAllUserChallengesDone]: onGetAllUserChallengesDone,
525+
505526
[a.getAllRecommendedChallengesInit]: onGetAllRecommendedChallengesInit,
506527
[a.getAllRecommendedChallengesDone]: onGetAllRecommendedChallengesDone,
507528

0 commit comments

Comments
 (0)