@@ -6,6 +6,7 @@ import PT from 'prop-types'
66import moment from 'moment'
77import FormsyForm from 'appirio-tech-react-components/components/Formsy'
88import _ from 'lodash'
9+ import { components } from 'react-select'
910import { isValidStartEndDates } from '../../../../../../helpers/utils'
1011import FormsySelect from '../../../../../../components/Select/FormsySelect'
1112// import MilestoneCopilots from '../MilestoneCopilots'
@@ -16,8 +17,8 @@ import { PHASE_STATUS_OPTIONS } from '../../../../../../config/constants'
1617import IconCheck from '../../../../../../assets/icons/icon-check-thin.svg'
1718import IconXMark from '../../../../../../assets/icons/icon-x-mark-thin.svg'
1819import IconPencil from '../../../../../../assets/icons/icon-ui-pencil.svg'
19-
2020import IconDots from '../../../../../../assets/icons/icon-dots.svg'
21+ import IconArrowDown from '../../../../../../assets/icons/arrow-6px-carret-down-normal.svg'
2122
2223import styles from './MilestoneRow.scss'
2324
@@ -47,14 +48,13 @@ function MilestoneRow({
4748 copilots = copilots . concat ( missingCopilots )
4849 }
4950
50-
5151 let milestoneRef
5252 let startDateRef
5353 let endDateRef
5454 let budgetRef
5555
5656 return edit ? (
57- < tr styleName = "milestone-row" >
57+ < tr styleName = "milestone-row" className = "edit-milestone-row" >
5858 < td styleName = "checkbox" >
5959 < TCFormFields . Checkbox
6060 name = { `select-${ rowId } ` }
@@ -69,10 +69,13 @@ function MilestoneRow({
6969 validations = { {
7070 isRequired : true ,
7171 checkDuplicatedTitles ( values ) {
72+ if ( ! milestone . editting ) {
73+ return true
74+ }
7275 const existingTitles = allMilestones
7376 . filter ( i => i . id !== milestone . id )
74- . map ( i => i . name . toLowerCase ( ) )
75- const inputtingTitle = values [ `title-${ rowId } ` ] . toLowerCase ( )
77+ . map ( i => i . name . toLowerCase ( ) . trim ( ) )
78+ const inputtingTitle = values [ `title-${ rowId } ` ] . toLowerCase ( ) . trim ( )
7679 return existingTitles . indexOf ( inputtingTitle ) === - 1
7780 }
7881 } }
@@ -89,10 +92,11 @@ function MilestoneRow({
8992 if ( ! milestone . origin ) {
9093 milestone . origin = { ...milestone }
9194 }
92- onChange ( { ...milestone , name : value } )
95+ onChange ( { ...milestone , name : value , editting : true , editted : true } )
9396 } }
9497 wrapperClass = { styles . textInput }
9598 innerRef = { ref => milestoneRef = ref }
99+ isPristine = { ( ) => ! milestone . editted }
96100 />
97101 </ td >
98102 < td styleName = "description" >
@@ -181,14 +185,28 @@ function MilestoneRow({
181185 } }
182186 value = { phaseStatusOptions . find ( option => option . value === milestone . status ) }
183187 isSearchable = { false }
188+ components = { {
189+ DropdownIndicator : ( props ) => (
190+ < components . DropdownIndicator { ...props } >
191+ < IconArrowDown />
192+ </ components . DropdownIndicator >
193+ )
194+ } }
184195 />
185196 </ td >
186197 < td styleName = "budget" >
198+ < span styleName = "prefix-icon" className = "milestone-budget-prefix-icon" > $</ span >
187199 < TCFormFields . TextInput
188200 validations = { {
189201 isRequired : true ,
202+ isPositive ( values ) {
203+ return ! ( values [ `budget-${ rowId } ` ] < 0 )
204+ }
190205 } }
191206 validationError = { 'Please, enter budget' }
207+ validationErrors = { {
208+ isPositive : 'Budget cannot be negative'
209+ } }
192210 required
193211 type = "number"
194212 name = { `budget-${ rowId } ` }
@@ -233,6 +251,8 @@ function MilestoneRow({
233251 className = "tc-btn tc-btn-link"
234252 styleName = "icon-button"
235253 onClick = { ( ) => {
254+ milestone . editted = true
255+ milestone . editting = true
236256 if ( milestoneRef . props . isValid ( )
237257 && startDateRef . props . isValid ( )
238258 && endDateRef . props . isValid ( )
@@ -272,18 +292,30 @@ function MilestoneRow({
272292 } }
273293 />
274294 </ td >
275- < td styleName = "milestone" > { milestone . name } </ td >
276- < td styleName = "description" > { milestone . description } </ td >
277- < td styleName = "start-date" > { moment ( milestone . startDate ) . format ( 'MM-DD-YYYY' ) } </ td >
278- < td styleName = "end-date" > { moment ( milestone . endDate ) . format ( 'MM-DD-YYYY' ) } </ td >
279- < td styleName = "status" > < MilestoneStatus status = { milestone . status } /> </ td >
280- < td styleName = "budget" > < MilestoneBudget spent = { milestone . spentBudget } budget = { milestone . budget } /> </ td >
295+ < td styleName = "milestone" >
296+ { milestone . name }
297+ </ td >
298+ < td styleName = "description" >
299+ { milestone . description }
300+ </ td >
301+ < td styleName = "start-date" >
302+ { moment ( milestone . startDate ) . format ( 'MM-DD-YYYY' ) }
303+ </ td >
304+ < td styleName = "end-date" >
305+ { moment ( milestone . endDate ) . format ( 'MM-DD-YYYY' ) }
306+ </ td >
307+ < td styleName = "status" >
308+ < MilestoneStatus status = { milestone . status } />
309+ </ td >
310+ < td styleName = "budget" >
311+ < MilestoneBudget spent = { milestone . spentBudget } budget = { milestone . budget } />
312+ </ td >
281313 { /* <td styleName="copilots">
282314 <MilestoneCopilots copilots={copilots} />
283315 </td> */ }
284- < td styleName = "action" >
285- < div styleName = "inline-menu " >
286- { isUpdatable && (
316+ { isUpdatable && (
317+ < td styleName = "action " >
318+ < div styleName = "inline-menu" >
287319 < button
288320 type = "button"
289321 className = "tc-btn tc-btn-link"
@@ -294,19 +326,17 @@ function MilestoneRow({
294326 >
295327 < IconPencil />
296328 </ button >
297- ) }
298- { isUpdatable && (
299329 < MilestoneDeleteButton
300330 onDelete = { ( ) => {
301331 onRemove ( milestone . id )
302332 } }
303333 />
304- ) }
305- < button type = "button" className = "tc-btn tc-btn-link" styleName = "icon-button" >
306- < IconDots / >
307- </ button >
308- </ div >
309- </ td >
334+ < button type = "button" className = "tc-btn tc-btn-link" styleName = "icon-button" >
335+ < IconDots / >
336+ </ button >
337+ </ div >
338+ </ td >
339+ ) }
310340 </ tr >
311341 )
312342}
0 commit comments