Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import PT from 'prop-types'
import moment from 'moment'
import FormsyForm from 'appirio-tech-react-components/components/Formsy'
import FormsySelect from '../../../../components/Select/FormsySelect'
import { MILESTONE_TYPE, MILESTONE_TYPE_OPTIONS } from '../../../../config/constants'
import { MILESTONE_TYPE, MILESTONE_TYPE_OPTIONS, MILESTONE_STATUS } from '../../../../config/constants'
import GenericMenu from '../../../../components/GenericMenu'
import TrashIcon from '../../../../assets/icons/icon-trash.svg'
import styles from './CreatePhaseForm.scss'
Expand Down Expand Up @@ -122,6 +122,7 @@ class CreatePhaseForm extends React.Component {
})

if (publishClicked) {
milestones[0].status= MILESTONE_STATUS.ACTIVE
onSubmit('active', phaseData, milestones)
} else {
onSubmit('draft', phaseData, milestones)
Expand All @@ -139,23 +140,25 @@ class CreatePhaseForm extends React.Component {
milestones
} = this.state


const newMilestones = _.cloneDeep(milestones)

// omit phase fields
_.forEach(_.keys(_.omit(change, ['title', 'startDate', 'endDate'])), (k) => {
const arrs = k.match(/(\w+)_(\d+)/)
const arrIndex = arrs[2]
const objKey = arrs[1]
if(change[k] && change[k] !== milestones[arrIndex][objKey]) {
if(change[k] !== milestones[arrIndex][objKey]) {
// set default title with option type
if (objKey === 'type' && !milestones[arrIndex]['type']) {
milestones[arrIndex]['title'] = this.getOptionType(change[k])
if (objKey === 'type' && change[k] && !milestones[arrIndex]['title']) {
newMilestones[arrIndex]['title'] = this.getOptionType(change[k])
}
milestones[arrIndex][objKey] = change[k]
newMilestones[arrIndex][objKey] = change[k]
}
})


this.setState({milestones})
this.setState({milestones: newMilestones})
}

getOptionType(val) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,6 @@
float: initial;
}
}
div {
padding: 0!important;
}
input {
width: 100%!important;
display: block;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React from 'react'
import PT from 'prop-types'
import moment from 'moment'

import { MILESTONE_TYPE, MILESTONE_TYPE_OPTIONS } from '../../../../../config/constants'
import { MILESTONE_TYPE_OPTIONS } from '../../../../../config/constants'
import LoadingIndicator from '../../../../../components/LoadingIndicator/LoadingIndicator'
import Form from '../Form'
import './CreateMilestoneForm.scss'
Expand All @@ -14,22 +14,29 @@ class CreateMilestoneForm extends React.Component {
constructor(props) {
super(props)

const {previousMilestone} = props
this.state = {
isEditing: false,
type: MILESTONE_TYPE.REPORTING,
title: 'Reporting',
startDate: moment.utc().format('YYYY-MM-DD'),
endDate: moment.utc().add(3, 'days').format('YYYY-MM-DD')
type: '',
title: '',
startDate: moment.utc(previousMilestone.endDate).format('YYYY-MM-DD'),
endDate: moment.utc(previousMilestone.endDate).add(3, 'days').format('YYYY-MM-DD')
}

this.submitForm = this.submitForm.bind(this)
this.cancelEdit = this.cancelEdit.bind(this)
this.onAddClick = this.onAddClick.bind(this)
this.changeForm = this.changeForm.bind(this)
}

cancelEdit() {
const {previousMilestone} = this.props
this.setState({
isEditing: false
isEditing: false,
type: '',
title: '',
startDate: moment.utc(previousMilestone.endDate).format('YYYY-MM-DD'),
endDate: moment.utc(previousMilestone.endDate).add(3, 'days').format('YYYY-MM-DD')
})
}

Expand All @@ -56,6 +63,35 @@ class CreateMilestoneForm extends React.Component {
values.blockedText = 'blocked text'
onSubmit(values)
}
changeForm(values) {
const { type, title, startDate, endDate } = this.state
if (values['name'] !== title) {
this.setState({
title: values['name']
})
}
if (values['startDate'] !== startDate) {
this.setState({
startDate: values['startDate']
})
}
if (values['endDate'] !== endDate) {
this.setState({
endDate: values['endDate']
})
}
// set title when select type and title is empty
if (values['type'] !== type) {
this.setState({
type: values['type']
})
if (!title) {
this.setState({
title: values['type']
})
}
}
}

render() {
const { isAdding, isEditing, type, title, startDate, endDate } = this.state
Expand All @@ -76,7 +112,7 @@ class CreateMilestoneForm extends React.Component {
fields={[
{
label: 'Type',
placeholder: 'Type',
placeholder:'Select Type',
options: MILESTONE_TYPE_OPTIONS,
name: 'type',
value: type,
Expand All @@ -88,12 +124,7 @@ class CreateMilestoneForm extends React.Component {
name: 'name',
value: title,
type: 'text',
validations: {
isRequired: true
},
validationError: 'Name is required',
},

{
label: 'Start Date',
placeholder: 'start date',
Expand All @@ -119,7 +150,9 @@ class CreateMilestoneForm extends React.Component {
]}
onCancelClick={this.cancelEdit}
onSubmit={this.submitForm}
onChange={this.changeForm}
submitButtonTitle="Create Milestone"
disableSubmitButton={!type}
/>
)

Expand All @@ -133,6 +166,7 @@ class CreateMilestoneForm extends React.Component {

CreateMilestoneForm.propTypes = {
onSubmit: PT.func.isRequired,
previousMilestone: PT.object.isRequired
}

export default CreateMilestoneForm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,15 @@ class Timeline extends React.Component {
} else {
//Ordering milestones wrt "order" before rendering
const orderedMilestones = timeline.milestones ? _.orderBy(timeline.milestones, ['order']) : []
const allShowMilestones = _.reject(orderedMilestones, { hidden: true })
return (
<div ref={ div => { this.div = div } }>
<NotificationsReader
key="notifications-reader"
id={`phase-${phaseId}-timeline-${timeline.id}`}
criteria={buildPhaseTimelineNotificationsCriteria(timeline)}
/>
{_.reject(orderedMilestones, { hidden: true }).map((milestone, index) => (
{allShowMilestones.map((milestone, index) => (
<Milestone
key={milestone.id}
currentUser={currentUser}
Expand All @@ -176,6 +177,7 @@ class Timeline extends React.Component {
/>
))}
<CreateMilestoneForm
previousMilestone={_.last(allShowMilestones)}
onSubmit={this.createMilestone}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React from 'react'
import PT from 'prop-types'
import moment from 'moment'

import { MILESTONE_TYPE, MILESTONE_TYPE_OPTIONS } from '../../../../../config/constants'
import { MILESTONE_TYPE_OPTIONS } from '../../../../../config/constants'
import LoadingIndicator from '../../../../../components/LoadingIndicator/LoadingIndicator'
import Form from '../Form'
import './CreateMilestoneForm.scss'
Expand All @@ -14,22 +14,29 @@ class CreateMilestoneForm extends React.Component {
constructor(props) {
super(props)

const {previousMilestone} = props
this.state = {
isEditing: false,
type: MILESTONE_TYPE.REPORTING,
title: 'Reporting',
startDate: moment.utc().format('YYYY-MM-DD'),
endDate: moment.utc().add(3, 'days').format('YYYY-MM-DD')
type: '',
title: '',
startDate: moment.utc(previousMilestone.endDate).format('YYYY-MM-DD'),
endDate: moment.utc(previousMilestone.endDate).add(3, 'days').format('YYYY-MM-DD')
}

this.submitForm = this.submitForm.bind(this)
this.cancelEdit = this.cancelEdit.bind(this)
this.onAddClick = this.onAddClick.bind(this)
this.changeForm = this.changeForm.bind(this)
}

cancelEdit() {
const {previousMilestone} = this.props
this.setState({
isEditing: false
isEditing: false,
type: '',
title: '',
startDate: moment.utc(previousMilestone.endDate).format('YYYY-MM-DD'),
endDate: moment.utc(previousMilestone.endDate).add(3, 'days').format('YYYY-MM-DD')
})
}

Expand All @@ -56,6 +63,35 @@ class CreateMilestoneForm extends React.Component {
values.blockedText = 'blocked text'
onSubmit(values)
}
changeForm(values) {
const { type, title, startDate, endDate } = this.state
if (values['name'] !== title) {
this.setState({
title: values['name']
})
}
if (values['startDate'] !== startDate) {
this.setState({
startDate: values['startDate']
})
}
if (values['endDate'] !== endDate) {
this.setState({
endDate: values['endDate']
})
}
// set title when select type and title is empty
if (values['type'] !== type) {
this.setState({
type: values['type']
})
if (!title) {
this.setState({
title: values['type']
})
}
}
}

render() {
const { isAdding, isEditing, type, title, startDate, endDate } = this.state
Expand All @@ -76,7 +112,7 @@ class CreateMilestoneForm extends React.Component {
fields={[
{
label: 'Type',
placeholder: 'Type',
placeholder:'Select Type',
options: MILESTONE_TYPE_OPTIONS,
name: 'type',
value: type,
Expand All @@ -88,12 +124,7 @@ class CreateMilestoneForm extends React.Component {
name: 'name',
value: title,
type: 'text',
validations: {
isRequired: true
},
validationError: 'Name is required',
},

{
label: 'Start Date',
placeholder: 'start date',
Expand All @@ -119,7 +150,9 @@ class CreateMilestoneForm extends React.Component {
]}
onCancelClick={this.cancelEdit}
onSubmit={this.submitForm}
onChange={this.changeForm}
submitButtonTitle="Create Milestone"
disableSubmitButton={!type}
/>
)

Expand All @@ -133,6 +166,7 @@ class CreateMilestoneForm extends React.Component {

CreateMilestoneForm.propTypes = {
onSubmit: PT.func.isRequired,
previousMilestone: PT.object.isRequired
}

export default CreateMilestoneForm
Expand Down
Loading