Skip to content

Commit 4eacd45

Browse files
authored
Merge pull request #418 from topcoder-platform/PROD-2066_challenge-statuses
PROD-2066 challenge statuses -> qa
2 parents fac249c + bf43eb8 commit 4eacd45

File tree

3 files changed

+61
-7
lines changed

3 files changed

+61
-7
lines changed

src-ts/lib/work-provider/work-functions/work-factory/work.factory.ts

+41-5
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,29 @@ function findMetadata(challenge: Challenge, metadataName: ChallengeMetadataName)
7373
return challenge.metadata?.find((item: ChallengeMetadata) => item.name === metadataName)
7474
}
7575

76+
function findOpenPhase(challenge: Challenge): ChallengePhase | undefined {
77+
78+
// sort the phases descending by start date
79+
const sortedPhases: Array<ChallengePhase> = challenge.phases
80+
.sort((a, b) => new Date(b.actualStartDate).getTime() - new Date(a.actualStartDate).getTime())
81+
82+
const now: Date = new Date()
83+
// if we have an open phase, just use that
84+
const openPhase: ChallengePhase | undefined = sortedPhases.find(phase => phase.isOpen)
85+
// otherwise, find the phase that _should_ be open now based on its start/end datetimes
86+
|| sortedPhases
87+
.find(phase => {
88+
return new Date(phase.actualEndDate) > now && new Date(phase.actualStartDate) < now
89+
})
90+
// otherwise, find the most recently started phase that's in the past
91+
|| sortedPhases
92+
.find(phase => {
93+
return new Date(phase.actualStartDate) < now
94+
})
95+
96+
return openPhase
97+
}
98+
7699
function findPhase(challenge: Challenge, phases: Array<string>): ChallengePhase | undefined {
77100
let phase: ChallengePhase | undefined
78101
let index: number = 0
@@ -102,7 +125,7 @@ function getCost(challenge: Challenge, type: WorkType): number | undefined {
102125
pageCount * (deviceCount - 1) * DesignPrices.PER_PAGE_COST
103126

104127
// case WorkType.findData:
105-
// return FindDataPrices.PROMOTIONAL_PRODUCT_PRICE || FindDataPrices.BASE_PRODUCT_PRICE
128+
// return FindDataPrices.PROMOTIONAL_PRODUCT_PRICE || FindDataPrices.BASE_PRODUCT_PRICE
106129
}
107130
}
108131

@@ -161,9 +184,22 @@ function getProgressStepActive(challenge: Challenge, workStatus: WorkStatus): nu
161184
switch (challenge.status) {
162185

163186
case ChallengeStatus.active:
164-
const submissionIsOpen: boolean = !!findPhase(challenge, [ChallengePhaseName.submission])?.isOpen
165-
const submissionEndDate: Date | undefined = getProgressStepDateEnd(challenge, [ChallengePhaseName.submission])
166-
return submissionIsOpen && new Date() > (submissionEndDate as Date) ? 1 : 2
187+
case ChallengeStatus.approved:
188+
189+
const openPhase: ChallengePhase | undefined = findOpenPhase(challenge)
190+
// if we don't have an open phase, just return submitted
191+
if (!openPhase) {
192+
return 0
193+
}
194+
195+
switch (openPhase.name) {
196+
case ChallengePhaseName.registration:
197+
return 0
198+
case ChallengePhaseName.submission:
199+
return 1
200+
default:
201+
return 2
202+
}
167203

168204
case ChallengeStatus.completed:
169205
return workStatus === WorkStatus.ready ? 3 : 4
@@ -239,7 +275,7 @@ function getTypeCategory(type: WorkType): WorkTypeCategory {
239275
switch (type) {
240276

241277
case WorkType.data:
242-
// case WorkType.findData:
278+
// case WorkType.findData:
243279
return WorkTypeCategory.data
244280

245281
case WorkType.design:

src-ts/tools/work/work-detail-solutions/WorkDetailSolutions.tsx

+15-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,20 @@ interface WorkDetailSolutionsProps {
1414
const WorkDetailSolutions: FC<WorkDetailSolutionsProps> = (props: WorkDetailSolutionsProps) => {
1515

1616
const workContextData: WorkContextData = useContext(workContext)
17+
18+
if (!props.challenge) {
19+
return <></>
20+
}
21+
1722
const work: Work = workContextData.createFromChallenge(props.challenge)
1823

1924
const isSolutionsReady: boolean = useMemo(() => {
2025
const activeStepName: string = work.progress.steps[work.progress.activeStepIndex]?.name
2126
return (activeStepName === WorkStatus.ready || activeStepName === WorkStatus.done)
22-
}, [work, props.solutions])
27+
}, [
28+
work,
29+
props.solutions,
30+
])
2331

2432
return (
2533
<div className={styles.wrap}>
@@ -33,7 +41,12 @@ const WorkDetailSolutions: FC<WorkDetailSolutionsProps> = (props: WorkDetailSolu
3341
</p>
3442
</div>
3543
)}
36-
<WorkSolutionsList isSolutionsReady={isSolutionsReady} work={work} solutions={props.solutions} onDownload={props.onDownload} />
44+
<WorkSolutionsList
45+
isSolutionsReady={isSolutionsReady}
46+
onDownload={props.onDownload}
47+
solutions={props.solutions}
48+
work={work}
49+
/>
3750
</div>
3851
)
3952
}

src-ts/tools/work/work-detail-summary/WorkDetailSummary.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ interface WorkDetailSummaryProps {
1414
const WorkDetailSummary: FC<WorkDetailSummaryProps> = (props: WorkDetailSummaryProps) => {
1515

1616
const workContextData: WorkContextData = useContext(workContext)
17+
18+
if (!props.challenge) {
19+
return <></>
20+
}
21+
1722
const work: Work = workContextData.createFromChallenge(props.challenge)
1823

1924
const progressElement: JSX.Element = props.status === WorkStatus.transferred

0 commit comments

Comments
 (0)