From 818442cfd1d42c68137fcc388541e823834d6484 Mon Sep 17 00:00:00 2001 From: lunarkid <4476442+dedywahyudi@users.noreply.github.com> Date: Tue, 20 Sep 2022 12:27:38 +0700 Subject: [PATCH 1/3] fix: challenge status missing --- .../challenge-detail/Header/index.jsx | 72 ++++++++++++++++++- .../challenge-detail/Header/style.scss | 48 +++++++++++-- 2 files changed, 113 insertions(+), 7 deletions(-) diff --git a/src/shared/components/challenge-detail/Header/index.jsx b/src/shared/components/challenge-detail/Header/index.jsx index 9898b37059..de9b90b2fb 100644 --- a/src/shared/components/challenge-detail/Header/index.jsx +++ b/src/shared/components/challenge-detail/Header/index.jsx @@ -30,6 +30,10 @@ import TabSelector from './TabSelector'; import style from './style.scss'; +/* Holds day and hour range in ms. */ +const HOUR_MS = 60 * 60 * 1000; +const DAY_MS = 24 * HOUR_MS; + export default function ChallengeHeader(props) { const { isLoggedIn, @@ -128,6 +132,26 @@ export default function ChallengeHeader(props) { */ const hasSubmissions = !_.isEmpty(mySubmissions); + const openPhases = sortedAllPhases.filter(p => p.isOpen); + let nextPhase = openPhases[0]; + if (hasRegistered && openPhases[0] && openPhases[0].name === 'Registration') { + nextPhase = openPhases[1] || {}; + } + const nextDeadline = nextPhase && nextPhase.name; + + const deadlineEnd = moment(nextPhase && phaseEndDate(nextPhase)); + const currentTime = moment(); + + let timeLeft = deadlineEnd.isAfter(currentTime) + ? deadlineEnd.diff(currentTime) : 0; + + let format; + if (timeLeft > DAY_MS) format = 'D[d] H[h]'; + else if (timeLeft > HOUR_MS) format = 'H[h] m[min]'; + else format = 'm[min] s[s]'; + + timeLeft = moment.duration(timeLeft).format(format); + let relevantPhases = []; if (showDeadlineDetail) { @@ -202,6 +226,41 @@ export default function ChallengeHeader(props) { const checkpointCount = checkpoints && checkpoints.numberOfPassedScreeningSubmissions; + let nextDeadlineMsg; + switch ((status || '').toLowerCase()) { + case 'active': + nextDeadlineMsg = ( +