Skip to content

Commit 17176ca

Browse files
authored
Merge pull request #1326 from nursoltan-s/issue-1319-b
Issue #1319: add phases
2 parents 68a1e28 + 0afa5a6 commit 17176ca

File tree

8 files changed

+438
-128
lines changed

8 files changed

+438
-128
lines changed

src/components/ChallengeEditor/ChallengeSchedule-Field/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import $ from 'jquery'
66
import styles from './ChallengeSchedule-Field.module.scss'
77
import cn from 'classnames'
88
import jstz from 'jstimezonedetect'
9-
import PhaseInput from '../../PhaseInput'
9+
import StartDateInput from '../../StartDateInput'
1010
import Chart from 'react-google-charts'
1111
import Select from '../../Select'
1212
import { parseSVG } from '../../../util/svg'
@@ -183,7 +183,7 @@ class ChallengeScheduleField extends Component {
183183
return (
184184
_.map(challenge.phases, (p, index) => (
185185
<div className={styles.PhaseRow} key={index}>
186-
<PhaseInput
186+
<StartDateInput
187187
phase={this.getPhaseTemplate(p)}
188188
withDuration
189189
onUpdateSelect={onUpdateSelect}
@@ -345,7 +345,7 @@ class ChallengeScheduleField extends Component {
345345
</div>
346346
</div> }
347347
<div className={styles.PhaseRow}>
348-
<PhaseInput
348+
<StartDateInput
349349
withDates
350350
phase={{
351351
name: 'Start Date',

src/components/ChallengeEditor/ChallengeView/index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ import ChallengePrizesField from '../ChallengePrizes-Field'
1616
import CopilotFeeField from '../CopilotFee-Field'
1717
import ChallengeTotalField from '../ChallengeTotal-Field'
1818
import Loader from '../../Loader'
19-
import PhaseInput from '../../PhaseInput'
2019
import AssignedMemberField from '../AssignedMember-Field'
2120
import { getResourceRoleByName } from '../../../util/tc'
2221
import { isBetaMode } from '../../../util/cookie'
2322
import { loadGroupDetails } from '../../../actions/challenges'
2423
import { REVIEW_TYPES, CONNECT_APP_URL, PHASE_PRODUCT_CHALLENGE_ID_FIELD } from '../../../config/constants'
24+
import PhaseInput from '../../PhaseInput'
25+
import { v4 as uuidv4 } from 'uuid'
2526

2627
const ChallengeView = ({
2728
projectDetail,
@@ -90,6 +91,7 @@ const ChallengeView = ({
9091
if (isLoading || _.isEmpty(metadata.challengePhases) || challenge.id !== challengeId) return <Loader />
9192
const showTimeline = false // disables the timeline for time being https://github.com/topcoder-platform/challenge-engine-ui/issues/706
9293
const isTask = _.get(challenge, 'task.isTask', false)
94+
const phases = _.get(challenge, 'phases', [])
9395

9496
return (
9597
<div className={styles.wrapper}>
@@ -188,16 +190,13 @@ const ChallengeView = ({
188190
</>
189191
)}
190192
{
191-
<div className={styles.PhaseRow}>
193+
phases.map((phase) => (
192194
<PhaseInput
193-
withDates
194-
phase={{
195-
name: 'Start Date',
196-
date: challenge.startDate
197-
}}
195+
phase={phase}
196+
phaseIndex={uuidv4()}
198197
readOnly
199198
/>
200-
</div>
199+
))
201200
}
202201
{showTimeline && (
203202
<ChallengeScheduleField

src/components/ChallengeEditor/index.js

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import React, { Component } from 'react'
44
import PropTypes from 'prop-types'
55
import { Helmet } from 'react-helmet'
66
import cn from 'classnames'
7-
import moment from 'moment'
7+
import moment from 'moment-timezone'
88
import { pick } from 'lodash/fp'
99
import { withRouter } from 'react-router-dom'
1010
import { toastr } from 'react-redux-toastr'
1111
import xss from 'xss'
12+
import { v4 as uuidv4 } from 'uuid'
1213

1314
import {
1415
VALIDATION_VALUE_TYPE,
@@ -810,6 +811,15 @@ class ChallengeEditor extends Component {
810811
this.setState({ challenge: newChallenge })
811812
}
812813

814+
onUpdatePhaseDate (phase, index) {
815+
let newChallenge = _.cloneDeep(this.state.challenge)
816+
const hourToSecond = 60 * 60
817+
newChallenge.phases[index]['duration'] = phase.duration / hourToSecond
818+
newChallenge.phases[index]['scheduledStartDate'] = phase.scheduledStartDate
819+
newChallenge.phases[index]['scheduledEndDate'] = phase.scheduledEndDate
820+
this.setState({ challenge: newChallenge })
821+
}
822+
813823
collectChallengeData (status) {
814824
const { attachments, metadata } = this.props
815825
const challenge = pick([
@@ -1280,7 +1290,7 @@ class ChallengeEditor extends Component {
12801290
let closeTaskModal = null
12811291
let draftModal = null
12821292

1283-
let { type } = challenge
1293+
let { type, phases = [] } = challenge
12841294
if (!type) {
12851295
const { typeId } = challenge
12861296
if (typeId && metadata.challengeTypes) {
@@ -1561,20 +1571,24 @@ class ChallengeEditor extends Component {
15611571
</React.Fragment>
15621572
)}
15631573
{!isTask && (
1564-
<div className={styles.PhaseRow}>
1565-
<PhaseInput
1566-
withDates
1567-
phase={{
1568-
name: 'Start Date',
1569-
date: challenge.startDate
1570-
}}
1571-
onUpdatePhase={newValue => this.onUpdateOthers({
1572-
field: 'startDate',
1573-
value: newValue.format()
1574-
})}
1575-
readOnly={false}
1576-
/>
1577-
</div>
1574+
<>
1575+
{
1576+
phases.map((phase, index) => (
1577+
<PhaseInput
1578+
phase={phase}
1579+
phaseIndex={uuidv4()}
1580+
readOnly={false}
1581+
onUpdatePhase={(item) => {
1582+
if ((item.startDate && !moment(item.startDate).isSame(phase.scheduledStartDate)) ||
1583+
(item.endDate && !moment(item.endDate).isSame(phase.scheduledEndDate))
1584+
) {
1585+
this.onUpdatePhaseDate(item, index)
1586+
}
1587+
}}
1588+
/>
1589+
))
1590+
}
1591+
</>
15781592
)}
15791593
{
15801594
this.state.isDeleteLaunch && !this.state.isConfirm && (

src/components/PhaseInput/PhaseInput.module.scss

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,26 @@
88

99
.container {
1010
display: flex;
11+
margin-bottom: 10px;
1112
}
1213

1314
.row {
1415
box-sizing: border-box;
1516
display: flex;
1617
flex-direction: row;
17-
margin: 30px 30px 0 30px;
18+
margin: 20px 30px 0 30px;
1819
align-content: space-between;
1920
justify-content: flex-start;
2021

22+
.title {
23+
display: flex;
24+
justify-content: center;
25+
flex-direction: column;
26+
margin-right: 10px;
27+
font-size: 14px;
28+
font-weight: 300;
29+
}
30+
2131
.field {
2232
@include upto-sm {
2333
display: block;
@@ -47,6 +57,7 @@
4757
&.phaseName {
4858
flex-direction: column;
4959
align-items: flex-start;
60+
font-weight: bold;
5061

5162
.previewDates {
5263
font-size: 13px;
@@ -73,7 +84,7 @@
7384
}
7485

7586
.dayPicker {
76-
width: 180px;
87+
width: 200px;
7788
margin-right: 30px;
7889

7990
:global {
@@ -90,6 +101,15 @@
90101
}
91102
}
92103

104+
.inputField {
105+
margin-right: 30px;
106+
width: 80px;
107+
108+
input {
109+
padding: 0 0 0 10px;
110+
}
111+
}
112+
93113
.timePicker {
94114
width: 90px;
95115

0 commit comments

Comments
 (0)