Skip to content

Commit 72f2128

Browse files
authored
Merge pull request #1330 from nursoltan-s/issue-1329
fix issue 1329
2 parents 1d4c52e + b470702 commit 72f2128

File tree

5 files changed

+51
-8
lines changed

5 files changed

+51
-8
lines changed

src/components/ChallengeEditor/index.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class ChallengeEditor extends Component {
139139
this.onDeleteChallenge = this.onDeleteChallenge.bind(this)
140140
this.deleteModalLaunch = this.deleteModalLaunch.bind(this)
141141
this.toggleForumOnCreate = this.toggleForumOnCreate.bind(this)
142+
this.isPhaseEditable = this.isPhaseEditable.bind(this)
142143
}
143144

144145
componentDidMount () {
@@ -1216,6 +1217,22 @@ class ChallengeEditor extends Component {
12161217
return _.filter(timelineTemplates, tt => availableTemplateIds.indexOf(tt.id) !== -1)
12171218
}
12181219

1220+
/**
1221+
* Check if current phase is active for edit
1222+
*/
1223+
isPhaseEditable (phaseIndex) {
1224+
const { challenge } = this.state
1225+
const { phases, currentPhaseNames } = challenge
1226+
1227+
let currentIndex = phases.findIndex((item) => {
1228+
return item.name !== 'Registration' && currentPhaseNames.includes(item.name) && item.isOpen
1229+
})
1230+
1231+
if (currentIndex === -1 || currentIndex > phaseIndex) return false
1232+
1233+
return true
1234+
}
1235+
12191236
render () {
12201237
const {
12211238
isLaunch,
@@ -1577,15 +1594,17 @@ class ChallengeEditor extends Component {
15771594
phase={phase}
15781595
phaseIndex={uuidv4()}
15791596
readOnly={false}
1597+
isActive={this.isPhaseEditable(index)}
15801598
onUpdatePhase={(item) => {
15811599
if ((item.startDate && !moment(item.startDate).isSame(phase.scheduledStartDate)) ||
1582-
(item.endDate && !moment(item.endDate).isSame(phase.scheduledEndDate))
1600+
(item.endDate && !moment(item.endDate).isSame(phase.scheduledEndDate))
15831601
) {
15841602
this.onUpdatePhaseDate(item, index)
15851603
}
15861604
}}
15871605
/>
1588-
))
1606+
)
1607+
)
15891608
}
15901609
</>
15911610
)}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@import "../../styles/includes";
2+
3+
.durationInput {
4+
&:disabled {
5+
cursor: not-allowed !important;
6+
background-color: $inactive !important;
7+
}
8+
}

src/components/DurationInput/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import React, { useRef } from 'react'
22
import PropTypes from 'prop-types'
3+
import styles from './DurationInput.module.scss'
34

4-
const DurationInput = ({ duration, onDurationChange, index }) => {
5+
const DurationInput = ({ duration, onDurationChange, index, isActive }) => {
56
const inputRef = useRef(null)
67

78
return (
89
<div key={`duration-${index}-edit`}>
910
<input
11+
className={styles.durationInput}
1012
id={`duration-${index}`}
1113
key={`duration-${index}`}
1214
ref={inputRef}
@@ -15,6 +17,7 @@ const DurationInput = ({ duration, onDurationChange, index }) => {
1517
value={Number(duration).toString()}
1618
onChange={e => onDurationChange(e.target.value)}
1719
autoFocus={inputRef.current === document.activeElement}
20+
disabled={!isActive}
1821
/>
1922
</div>
2023
)
@@ -23,7 +26,8 @@ const DurationInput = ({ duration, onDurationChange, index }) => {
2326
DurationInput.propTypes = {
2427
duration: PropTypes.string,
2528
onDurationChange: PropTypes.func.isRequired,
26-
index: PropTypes.string.isRequired
29+
index: PropTypes.string.isRequired,
30+
isActive: PropTypes.bool.isRequired
2731
}
2832

2933
export default DurationInput

src/components/PhaseInput/PhaseInput.module.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,9 @@
146146
color: black;
147147
}
148148

149-
149+
.dateTimeInput {
150+
&:disabled {
151+
cursor: not-allowed !important;
152+
background-color: $inactive !important;
153+
}
154+
}

src/components/PhaseInput/index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import DurationInput from '../DurationInput'
1414
const dateFormat = 'MM/DD/YYYY HH:mm'
1515
const MAX_LENGTH = 5
1616

17-
const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {
17+
const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex, isActive }) => {
1818
const [startDate, setStartDate] = useState()
1919
const [endDate, setEndDate] = useState()
2020
const [duration, setDuration] = useState()
@@ -86,12 +86,14 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {
8686
)
8787
: (
8888
<DateTime
89+
className={styles.dateTimeInput}
8990
value={moment(startDate).format(dateFormat)}
9091
onChange={onStartDateChange}
9192
isValidDate={(current) => {
9293
const yesterday = subDays(new Date(), 1)
9394
return isAfter(current, yesterday)
9495
}}
96+
disabled={!isActive}
9597
/>)}
9698
</div>
9799
</div>
@@ -104,11 +106,13 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {
104106
)
105107
: (
106108
<DateTime
109+
className={styles.dateTimeInput}
107110
value={moment(endDate).format(dateFormat)}
108111
onChange={onEndDateChange}
109112
isValidDate={(current) => {
110113
return isAfter(current, new Date(startDate))
111114
}}
115+
disabled={!isActive}
112116
/>)}
113117
</div>
114118
</div>
@@ -124,6 +128,7 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {
124128
name={phase.name}
125129
onDurationChange={onDurationChange}
126130
index={phaseIndex}
131+
isActive={isActive}
127132
/>}
128133
</div>
129134
</div>
@@ -134,13 +139,15 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {
134139

135140
PhaseInput.defaultProps = {
136141
endDate: null,
137-
readOnly: false
142+
readOnly: false,
143+
isActive: false
138144
}
139145

140146
PhaseInput.propTypes = {
141147
phase: PropTypes.shape().isRequired,
142148
onUpdatePhase: PropTypes.func.isRequired,
143149
readOnly: PropTypes.bool,
144-
phaseIndex: PropTypes.string.isRequired
150+
phaseIndex: PropTypes.string.isRequired,
151+
isActive: PropTypes.bool
145152
}
146153
export default PhaseInput

0 commit comments

Comments
 (0)