Skip to content

fix issue 1329 #1330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/components/ChallengeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class ChallengeEditor extends Component {
this.onDeleteChallenge = this.onDeleteChallenge.bind(this)
this.deleteModalLaunch = this.deleteModalLaunch.bind(this)
this.toggleForumOnCreate = this.toggleForumOnCreate.bind(this)
this.isPhaseEditable = this.isPhaseEditable.bind(this)
}

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

/**
* Check if current phase is active for edit
*/
isPhaseEditable (phaseIndex) {
const { challenge } = this.state
const { phases, currentPhaseNames } = challenge

let currentIndex = phases.findIndex((item) => {
return item.name !== 'Registration' && currentPhaseNames.includes(item.name) && item.isOpen
})

if (currentIndex === -1 || currentIndex > phaseIndex) return false

return true
}

render () {
const {
isLaunch,
Expand Down Expand Up @@ -1577,15 +1594,17 @@ class ChallengeEditor extends Component {
phase={phase}
phaseIndex={uuidv4()}
readOnly={false}
isActive={this.isPhaseEditable(index)}
onUpdatePhase={(item) => {
if ((item.startDate && !moment(item.startDate).isSame(phase.scheduledStartDate)) ||
(item.endDate && !moment(item.endDate).isSame(phase.scheduledEndDate))
(item.endDate && !moment(item.endDate).isSame(phase.scheduledEndDate))
) {
this.onUpdatePhaseDate(item, index)
}
}}
/>
))
)
)
}
</>
)}
Expand Down
8 changes: 8 additions & 0 deletions src/components/DurationInput/DurationInput.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@import "../../styles/includes";

.durationInput {
&:disabled {
cursor: not-allowed !important;
background-color: $inactive !important;
}
}
8 changes: 6 additions & 2 deletions src/components/DurationInput/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React, { useRef } from 'react'
import PropTypes from 'prop-types'
import styles from './DurationInput.module.scss'

const DurationInput = ({ duration, onDurationChange, index }) => {
const DurationInput = ({ duration, onDurationChange, index, isActive }) => {
const inputRef = useRef(null)

return (
<div key={`duration-${index}-edit`}>
<input
className={styles.durationInput}
id={`duration-${index}`}
key={`duration-${index}`}
ref={inputRef}
Expand All @@ -15,6 +17,7 @@ const DurationInput = ({ duration, onDurationChange, index }) => {
value={Number(duration).toString()}
onChange={e => onDurationChange(e.target.value)}
autoFocus={inputRef.current === document.activeElement}
disabled={!isActive}
/>
</div>
)
Expand All @@ -23,7 +26,8 @@ const DurationInput = ({ duration, onDurationChange, index }) => {
DurationInput.propTypes = {
duration: PropTypes.string,
onDurationChange: PropTypes.func.isRequired,
index: PropTypes.string.isRequired
index: PropTypes.string.isRequired,
isActive: PropTypes.bool.isRequired
}

export default DurationInput
7 changes: 6 additions & 1 deletion src/components/PhaseInput/PhaseInput.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,9 @@
color: black;
}


.dateTimeInput {
&:disabled {
cursor: not-allowed !important;
background-color: $inactive !important;
}
}
13 changes: 10 additions & 3 deletions src/components/PhaseInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import DurationInput from '../DurationInput'
const dateFormat = 'MM/DD/YYYY HH:mm'
const MAX_LENGTH = 5

const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {
const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex, isActive }) => {
const [startDate, setStartDate] = useState()
const [endDate, setEndDate] = useState()
const [duration, setDuration] = useState()
Expand Down Expand Up @@ -86,12 +86,14 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {
)
: (
<DateTime
className={styles.dateTimeInput}
value={moment(startDate).format(dateFormat)}
onChange={onStartDateChange}
isValidDate={(current) => {
const yesterday = subDays(new Date(), 1)
return isAfter(current, yesterday)
}}
disabled={!isActive}
/>)}
</div>
</div>
Expand All @@ -104,11 +106,13 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {
)
: (
<DateTime
className={styles.dateTimeInput}
value={moment(endDate).format(dateFormat)}
onChange={onEndDateChange}
isValidDate={(current) => {
return isAfter(current, new Date(startDate))
}}
disabled={!isActive}
/>)}
</div>
</div>
Expand All @@ -124,6 +128,7 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {
name={phase.name}
onDurationChange={onDurationChange}
index={phaseIndex}
isActive={isActive}
/>}
</div>
</div>
Expand All @@ -134,13 +139,15 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex }) => {

PhaseInput.defaultProps = {
endDate: null,
readOnly: false
readOnly: false,
isActive: false
}

PhaseInput.propTypes = {
phase: PropTypes.shape().isRequired,
onUpdatePhase: PropTypes.func.isRequired,
readOnly: PropTypes.bool,
phaseIndex: PropTypes.string.isRequired
phaseIndex: PropTypes.string.isRequired,
isActive: PropTypes.bool
}
export default PhaseInput