Skip to content

Commit b3cf374

Browse files
authored
Merge pull request #3323 from rashmi73/issue_3210
Issue #3210 fix
2 parents ca65dce + 7eb7837 commit b3cf374

File tree

4 files changed

+81
-29
lines changed

4 files changed

+81
-29
lines changed

src/projects/detail/components/PhaseCard/EditStageForm.jsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import Tooltip from 'appirio-tech-react-components/components/Tooltip/Tooltip'
2020
import { TOOLTIP_DEFAULT_DELAY } from '../../../../config/constants'
2121
import { getPhaseActualData } from '../../../../helpers/projectHelper'
2222
import DeletePhase from './DeletePhase'
23+
import {
24+
ROLE_CONNECT_ADMIN,
25+
ROLE_ADMINISTRATOR,
26+
} from '../../../../config/constants'
2327

2428
const moment = extendMoment(Moment)
2529
const phaseStatuses = PHASE_STATUS.map(ps => ({
@@ -33,7 +37,7 @@ class EditStageForm extends React.Component {
3337

3438
this.state = {
3539
isUpdating: false,
36-
isEdittable: _.get(props, 'phase.status') !== PHASE_STATUS_COMPLETED,
40+
isEdittable: (_.get(props, 'phase.status') !== PHASE_STATUS_COMPLETED) || (_.get(props, 'isAdmin')),
3741
disableActiveStatusFields: _.get(props, 'phase.status') !== PHASE_STATUS_ACTIVE,
3842
showPhaseOverlapWarning: false,
3943
phaseIsdirty: false,
@@ -83,7 +87,7 @@ class EditStageForm extends React.Component {
8387
componentWillReceiveProps(nextProps) {
8488
this.setState({
8589
isUpdating: nextProps.isUpdating,
86-
isEdittable: nextProps.phase.status !== PHASE_STATUS_COMPLETED,
90+
isEdittable: nextProps.phase.status !== PHASE_STATUS_COMPLETED || nextProps.isAdmin,
8791
disableActiveStatusFields: nextProps.phase.status !== PHASE_STATUS_ACTIVE,
8892
})
8993

@@ -399,11 +403,18 @@ EditStageForm.propTypes = {
399403
phaseIndex: PT.number
400404
}
401405

402-
const mapStateToProps = ({projectState, productsTimelines}) => ({
403-
isUpdating: projectState.processing,
404-
phases: projectState.phases,
405-
productsTimelines
406-
})
406+
const mapStateToProps = ({projectState, productsTimelines, loadUser}) => {
407+
const adminRoles = [
408+
ROLE_ADMINISTRATOR,
409+
ROLE_CONNECT_ADMIN,
410+
]
411+
return {
412+
isUpdating: projectState.processing,
413+
phases: projectState.phases,
414+
productsTimelines,
415+
isAdmin: _.intersection(loadUser.user.roles, adminRoles).length > 0
416+
}
417+
}
407418

408419
const actionCreators = {
409420
updatePhaseAction,

src/projects/detail/components/PhaseCard/PhaseCard.jsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import {
1919
PROJECT_STATUS_CANCELLED,
2020
SCREEN_BREAKPOINT_MD,
2121
EVENT_TYPE,
22+
ROLE_CONNECT_ADMIN,
23+
ROLE_ADMINISTRATOR,
2224
} from '../../../../config/constants'
2325

2426
import ProjectProgress from '../../../../components/ProjectProgress/ProjectProgress'
@@ -93,15 +95,16 @@ class PhaseCard extends React.Component {
9395
hasUnseen,
9496
phaseId,
9597
isExpanded,
96-
project
98+
project,
99+
isAdmin
97100
} = this.props
98101
const progressInPercent = attr.progressInPercent || 0
99102

100103
let status = attr && attr.status ? attr.status : PHASE_STATUS_DRAFT
101104
status = _.find(PHASE_STATUS, s => s.value === status) ? status : PHASE_STATUS_DRAFT
102105
const statusDetails = _.find(PHASE_STATUS, s => s.value === status)
103106

104-
const phaseEditable = checkPermission(PERMISSIONS.EDIT_PROJECT_PLAN, project) && status !== PHASE_STATUS_COMPLETED && projectStatus !== PROJECT_STATUS_CANCELLED && projectStatus !== PROJECT_STATUS_COMPLETED
107+
const phaseEditable = checkPermission(PERMISSIONS.EDIT_PROJECT_PLAN, project) && (status !== PHASE_STATUS_COMPLETED || (isAdmin)) && projectStatus !== PROJECT_STATUS_CANCELLED && projectStatus !== PROJECT_STATUS_COMPLETED
105108

106109
return (
107110
<div styleName={'phase-card ' + (isExpanded ? ' expanded ' : ' ')} id={`phase-${phaseId}`}>
@@ -280,9 +283,14 @@ PhaseCard.propTypes = {
280283

281284

282285
const mapStateToProps = ({loadUser, projectState}) => {
286+
const adminRoles = [
287+
ROLE_ADMINISTRATOR,
288+
ROLE_CONNECT_ADMIN,
289+
]
283290
return {
284291
currentUserRoles: loadUser.user.roles,
285-
isUpdating: projectState.processing
292+
isUpdating: projectState.processing,
293+
isAdmin: _.intersection(loadUser.user.roles, adminRoles).length > 0
286294
}
287295
}
288296

src/projects/detail/components/timeline/FormFieldDate/FormFieldDate.jsx

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,21 @@
55
*/
66
import React from 'react'
77
import PT from 'prop-types'
8-
import _ from 'lodash'
9-
import cn from 'classnames'
108

119
import FormsyForm from 'appirio-tech-react-components/components/Formsy'
10+
import './FormFieldDate.scss'
1211
const TCFormFields = FormsyForm.Fields
1312

14-
import styles from './FormFieldDate.scss'
1513

16-
const FormFieldDate = ({ startDate, endDate, theme }) => {
17-
const startDateProps = _.omit(startDate, 'label')
18-
startDateProps.type = 'date'
19-
startDateProps.wrapperClass = styles['field-wrapper']
20-
21-
const endDateProps = _.omit(endDate, 'label')
22-
endDateProps.type = 'date'
23-
endDateProps.wrapperClass = styles['field-wrapper']
14+
const FormFieldDate = (props) => {
2415

2516
return (
26-
<div styleName={cn('milestone-post', theme)}>
17+
<div styleName="milestone-post">
2718
<div styleName="col-left">
28-
<label styleName="label-title">{startDate.label}</label>
19+
<label styleName="label-title">{props.label}</label>
2920
</div>
3021
<div styleName="col-right">
31-
<TCFormFields.TextInput {...startDateProps} />
32-
<label styleName="label-title">{endDate.label}</label>
33-
<TCFormFields.TextInput {...endDateProps} />
22+
<TCFormFields.TextInput {...props} />
3423
</div>
3524
</div>
3625
)

src/projects/detail/components/timeline/Milestone/Milestone.jsx

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,32 @@ class Milestone extends React.Component {
102102
this.setState({ isMobileEditing: true })
103103
}
104104

105+
isActualStartDateEditable() {
106+
const { milestone, currentUser } = this.props
107+
const isActive = milestone.status === MILESTONE_STATUS.ACTIVE
108+
const isCompleted = milestone.status === MILESTONE_STATUS.COMPLETED
109+
return (isActive || isCompleted) && currentUser.isAdmin
110+
111+
}
112+
113+
isCompletionDateEditable() {
114+
const { milestone, currentUser } = this.props
115+
const isCompleted = milestone.status === MILESTONE_STATUS.COMPLETED
116+
return isCompleted && currentUser.isAdmin
117+
}
118+
105119
updateMilestoneWithData(values) {
106120
const { milestone, updateMilestone } = this.props
107-
108-
updateMilestone(milestone.id, values)
121+
let milestoneData = {
122+
...values
123+
};
124+
if (values.actualStartDate) {
125+
milestoneData.actualStartDate = moment.utc(new Date(values.actualStartDate))
126+
}
127+
if (values.completionDate) {
128+
milestoneData.completionDate = moment.utc(new Date(values.completionDate))
129+
}
130+
updateMilestone(milestone.id, milestoneData)
109131
}
110132

111133
milestoneEditorChanged(values) {
@@ -211,6 +233,8 @@ class Milestone extends React.Component {
211233
const date = startDate.format('D')
212234
const title = milestone.name
213235
const isUpdating = milestone.isUpdating
236+
const isActualDateEditable = this.isActualStartDateEditable()
237+
const isCompletionDateEditable = this.isCompletionDateEditable()
214238
const editForm = (
215239
<Form
216240
fields={[{
@@ -278,7 +302,27 @@ class Milestone extends React.Component {
278302
isRequired: true
279303
},
280304
validationError: 'Completed text is required',
281-
}]}
305+
}, ...( isActualDateEditable && [{
306+
label: 'Actual Start date',
307+
placeholder: 'Actual Start date',
308+
name: 'actualStartDate',
309+
value: moment.utc(milestone.actualStartDate).format('YYYY-MM-DD'),
310+
type: 'date',
311+
validations: {
312+
isRequired: true
313+
},
314+
validationError: 'Actual Start date is required',
315+
}]), ...( isCompletionDateEditable && [{
316+
label: 'Completion date',
317+
placeholder: 'Completion date',
318+
name: 'completionDate',
319+
value: moment.utc(milestone.completionDate).format('YYYY-MM-DD'),
320+
type: 'date',
321+
validations: {
322+
isRequired: true
323+
},
324+
validationError: 'Completion date is required',
325+
}])]}
282326
onCancelClick={this.closeEditForm}
283327
onSubmit={this.updateMilestoneWithData}
284328
onChange={this.milestoneEditorChanged}

0 commit comments

Comments
 (0)