From 16fa1d19cb42f0d7bedde9d4809fed1e24c179c8 Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Mon, 1 Jun 2020 19:52:01 +0530 Subject: [PATCH] fix: Github issue#666, Standard Design "Edit" Event Sequence Out of Order --- src/services/challenges.js | 3 ++- src/util/date.js | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/services/challenges.js b/src/services/challenges.js index 9fa6150c..f845daed 100644 --- a/src/services/challenges.js +++ b/src/services/challenges.js @@ -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, @@ -88,6 +88,7 @@ export async function fetchChallenge (challengeId) { } } convertChallengePhaseFromSecondsToHours(newResponse.phases) + newResponse.phases = sortChallengePhases(newResponse.phases) return newResponse } diff --git a/src/util/date.js b/src/util/date.js index 5dcf3ad0..84618569 100644 --- a/src/util/date.js +++ b/src/util/date.js @@ -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