@@ -32,6 +32,7 @@ import {
3232 createPhaseAndMilestones ,
3333 createPhaseWithoutTimeline ,
3434 getChallengesByIds ,
35+ approveMilestone ,
3536} from '../../actions/project'
3637import { addProductAttachment , updateProductAttachment , removeProductAttachment } from '../../actions/projectAttachment'
3738
@@ -67,7 +68,8 @@ import {
6768 SCREEN_BREAKPOINT_MD ,
6869 CODER_BOT_USERID ,
6970 PROJECT_TYPE_TALENT_AS_A_SERVICE ,
70- PHASE_PRODUCT_TEMPLATE_ID
71+ PHASE_PRODUCT_TEMPLATE_ID ,
72+ PHASE_STATUS_REVIEWED
7173} from '../../../config/constants'
7274
7375const SYSTEM_USER = {
@@ -83,7 +85,8 @@ class DashboardContainer extends React.Component {
8385
8486 this . state = {
8587 open : false ,
86- createGameplanPhases : null
88+ createGameplanPhases : null ,
89+ visiblePhases : null
8790 }
8891 this . onNotificationRead = this . onNotificationRead . bind ( this )
8992 this . toggleDrawer = this . toggleDrawer . bind ( this )
@@ -151,18 +154,32 @@ class DashboardContainer extends React.Component {
151154 }
152155
153156 onApproveMilestones ( { type, comment, milestones} ) {
154- const { executePhaseApproval } = this . props
157+ const { executePhaseApproval, approveMilestone } = this . props
155158 const reqs = [ ]
156159 milestones . forEach ( ms => {
157160 reqs . push (
158161 executePhaseApproval ( ms . projectId , ms . id , { decision : type , comment} )
159162 )
160163 console . log ( 'type-comment' , type , comment , ms )
161164 } )
162- Promise . all ( reqs ) . then ( ( ...args ) => { console . log ( 'onApproveMilestones t' , args ) } )
163- . catch ( e => console . log ( 'onApproveMilestones f' , e ) )
165+ const updatedPhases = this . state . createGameplanPhases || this . state . visiblePhases || [ ]
166+ Promise . all ( reqs ) . then ( ( ) => {
167+ milestones . forEach ( ms => {
168+ const index = updatedPhases . findIndex ( phase => phase . id === ms . id )
169+ updatedPhases . splice ( index , 1 , {
170+ ...updatedPhases [ index ] ,
171+ status : PHASE_STATUS_REVIEWED
172+ } )
173+ } )
174+
175+ approveMilestone ( )
176+ } )
177+ . catch ( ( e ) => {
178+ console . log ( 'onApproveMilestones f' , e )
179+ approveMilestone ( false )
180+ } )
164181 . finally ( ( ) => {
165- this . onChangeMilestones ( null )
182+ this . onChangeMilestones ( updatedPhases )
166183 } )
167184 }
168185
@@ -350,6 +367,7 @@ class DashboardContainer extends React.Component {
350367 const visiblePhases = phases && phases . filter ( ( phase ) => (
351368 hasPermission ( PERMISSIONS . VIEW_DRAFT_PHASES ) || phase . status !== PHASE_STATUS_DRAFT
352369 ) )
370+ this . state . visiblePhases = visiblePhases
353371 const visiblePhasesIds = _ . map ( visiblePhases , 'id' )
354372 const visiblePhasesNonDirty = phasesNonDirty && phasesNonDirty . filter ( ( phaseNonDirty ) => (
355373 _ . includes ( visiblePhasesIds , phaseNonDirty . id )
@@ -565,7 +583,8 @@ const mapDispatchToProps = {
565583 removeProjectAttachment,
566584 updatePhase,
567585 updatePhaseMembers,
568- executePhaseApproval
586+ executePhaseApproval,
587+ approveMilestone
569588}
570589
571590export default connect ( mapStateToProps , mapDispatchToProps ) ( withRouter ( DashboardContainer ) )
0 commit comments