@@ -286,12 +286,14 @@ function createProductsTimelineAndMilestone(project) {
286286 *
287287 * @return {Promise } project
288288 */
289- export function createProjectPhaseAndProduct ( project , productTemplate , status = PHASE_STATUS_DRAFT , startDate , endDate , createTimeline = true ) {
289+ export function createProjectPhaseAndProduct ( project , productTemplate , status = PHASE_STATUS_DRAFT , startDate , endDate , createTimeline = true , budget , details ) {
290290 const param = {
291291 status,
292292 name : productTemplate . name ,
293293 description : productTemplate . description ,
294- productTemplateId : productTemplate . id
294+ productTemplateId : productTemplate . id ,
295+ budget,
296+ details,
295297 }
296298 if ( startDate ) {
297299 param [ 'startDate' ] = startDate . format ( 'YYYY-MM-DD' )
@@ -356,12 +358,12 @@ function createPhaseAndMilestonesRequest(project, productTemplate, status = PHAS
356358 * @param {* } startDate
357359 * @param {* } endDate
358360 */
359- export function createPhaseWithoutTimeline ( project , productTemplate , status , startDate , endDate ) {
361+ export function createPhaseWithoutTimeline ( project , productTemplate , status , startDate , endDate , budget , details ) {
360362 return ( dispatch ) => {
361363 console . log ( CREATE_PROJECT_PHASE )
362364 return dispatch ( {
363365 type : CREATE_PROJECT_PHASE ,
364- payload : createProjectPhaseAndProduct ( project , productTemplate , status , startDate , endDate , false )
366+ payload : createProjectPhaseAndProduct ( project , productTemplate , status , startDate , endDate , false , budget , details )
365367 } )
366368 }
367369}
@@ -505,75 +507,78 @@ export function updatePhase(projectId, phaseId, updatedProps, phaseIndex) {
505507 updatedProps . endDate = moment ( updatedProps . endDate ) . format ( 'YYYY-MM-DD' )
506508 }
507509
510+ let result
508511 return dispatch ( {
509512 type : UPDATE_PHASE ,
510513 payload : updatePhaseAPI ( projectId , phaseId , updatedProps , phaseIndex ) . then ( )
511- } ) . then ( ( ) => {
514+ } )
515+ . then ( res => result = res )
516+ . then ( ( ) => {
512517 // finds active milestone, if exists in timeline
513- const activeMilestone = timeline ? _ . find ( timeline . milestones , m => m . status === PHASE_STATUS_ACTIVE ) : null
514- // this will be done after updating timeline (if timeline update is required)
515- // or immediately if timeline update is not required
516- // update product milestone strictly after updating timeline
517- // otherwise it could happened like this:
518- // - send request to update timeline
519- // - send request to update milestone
520- // - get updated milestone
521- // - get updated timeline (without updated milestone)
522- // so otherwise we can end up with the timeline without updated milestone
523- const optionallyUpdateFirstMilestone = ( ) => {
518+ const activeMilestone = timeline ? _ . find ( timeline . milestones , m => m . status === PHASE_STATUS_ACTIVE ) : null
519+ // this will be done after updating timeline (if timeline update is required)
520+ // or immediately if timeline update is not required
521+ // update product milestone strictly after updating timeline
522+ // otherwise it could happened like this:
523+ // - send request to update timeline
524+ // - send request to update milestone
525+ // - get updated milestone
526+ // - get updated timeline (without updated milestone)
527+ // so otherwise we can end up with the timeline without updated milestone
528+ const optionallyUpdateFirstMilestone = ( ) => {
524529 // update first product milestone only if
525530 // - there is a milestone, obviously
526531 // - phase's status is changed
527532 // - phase's status is changed to active
528533 // - there is not active milestone alreay (this can happen when phase is made active more than once
529534 // e.g. Active => Paused => Active)
530- if ( projectVersion !== 'v4' && timeline && ! activeMilestone && phaseActivated ) {
535+ if ( projectVersion !== 'v4' && timeline && ! activeMilestone && phaseActivated ) {
536+ dispatch (
537+ updateProductMilestone (
538+ productId ,
539+ timeline . id ,
540+ timeline . milestones [ 0 ] . id ,
541+ { status :MILESTONE_STATUS . ACTIVE }
542+ )
543+ )
544+ }
545+ }
546+
547+ if ( timeline && ( startDateChanged || phaseActivated ) ) {
531548 dispatch (
532- updateProductMilestone (
549+ updateProductTimeline (
533550 productId ,
534551 timeline . id ,
535- timeline . milestones [ 0 ] . id ,
536- { status :MILESTONE_STATUS . ACTIVE }
552+ {
553+ name : timeline . name ,
554+ startDate : updatedProps . startDate ,
555+ reference : timeline . reference ,
556+ referenceId : timeline . referenceId ,
557+ }
537558 )
538- )
559+ ) . then ( optionallyUpdateFirstMilestone )
560+ } else {
561+ optionallyUpdateFirstMilestone ( )
539562 }
540- }
541-
542- if ( timeline && ( startDateChanged || phaseActivated ) ) {
543- dispatch (
544- updateProductTimeline (
545- productId ,
546- timeline . id ,
547- {
548- name : timeline . name ,
549- startDate : updatedProps . startDate ,
550- reference : timeline . reference ,
551- referenceId : timeline . referenceId ,
552- }
553- )
554- ) . then ( optionallyUpdateFirstMilestone )
555- } else {
556- optionallyUpdateFirstMilestone ( )
557- }
558563
559- // update project caused by phase updates
560- } ) . then ( ( ) => {
561- const project = state . projectState . project
564+ // update project caused by phase updates
565+ } ) . then ( ( ) => {
566+ const project = state . projectState . project
562567
563- // if one phase moved to ACTIVE status, make project ACTIVE too
564- if (
565- _ . includes ( [ PROJECT_STATUS_DRAFT , PROJECT_STATUS_IN_REVIEW , PROJECT_STATUS_REVIEWED ] , project . status ) &&
568+ // if one phase moved to ACTIVE status, make project ACTIVE too
569+ if (
570+ _ . includes ( [ PROJECT_STATUS_DRAFT , PROJECT_STATUS_IN_REVIEW , PROJECT_STATUS_REVIEWED ] , project . status ) &&
566571 phase . status !== PHASE_STATUS_ACTIVE &&
567572 updatedProps . status === PHASE_STATUS_ACTIVE &&
568573 hasPermission ( PERMISSIONS . EDIT_PROJECT_STATUS )
569- ) {
570- dispatch (
571- updateProject ( projectId , {
572- status : PROJECT_STATUS_ACTIVE
573- } , true )
574- )
575- }
576- } )
574+ ) {
575+ dispatch (
576+ updateProject ( projectId , {
577+ status : PROJECT_STATUS_ACTIVE
578+ } , true )
579+ )
580+ }
581+ } ) . then ( ( ) => result )
577582 }
578583}
579584
0 commit comments