Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/services/challenges.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'lodash'
import qs from 'qs'
import { axiosInstance } from './axiosWithAuth'
import { updateChallengePhaseBeforeSendRequest, convertChallengePhaseFromSecondsToHours } from '../util/date'
import { updateChallengePhaseBeforeSendRequest, convertChallengePhaseFromSecondsToHours, sortChallengePhases } from '../util/date'
import FormData from 'form-data'
const {
CHALLENGE_API_URL,
Expand Down Expand Up @@ -88,6 +88,7 @@ export async function fetchChallenge (challengeId) {
}
}
convertChallengePhaseFromSecondsToHours(newResponse.phases)
newResponse.phases = sortChallengePhases(newResponse.phases)
return newResponse
}

Expand Down
9 changes: 9 additions & 0 deletions src/util/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ export const convertChallengePhaseFromSecondsToHours = (phases) => {
}
}

/**
* Sorts the challenge phases in order of their supposed execution
*
* @param {Array} phases challenge phases that are to be sorte3d
*/
export const sortChallengePhases = (phases) => {
return _.sortBy(phases, phase => phase.actualStartDate || phase.scheduledStartDate)
}

/**
* Convert challenge phase from hours to second and remove unnessesary field
* @param {Object} challengeDetail challenge detail
Expand Down