@@ -8,6 +8,9 @@ import messages from '../../../common/messages';
88import CommentInlineError from '../comment/CommentInlineError' ;
99import IconTaskApproval from '../../../../icons/two-toned/IconTaskApproval' ;
1010import IconTaskGeneral from '../../../../icons/two-toned/IconTaskGeneral' ;
11+ import { withAPIContext } from '../../../common/api-context' ;
12+
13+ import API from '../../../../api/APIFactory' ;
1114import {
1215 TASK_NEW_APPROVED ,
1316 TASK_NEW_REJECTED ,
@@ -30,6 +33,7 @@ import './Task.scss';
3033
3134type Props = { |
3235 ...TaskNew ,
36+ api : API ,
3337 currentUser : User ,
3438 error ?: ActionItemError ,
3539 features ?: FeatureConfig ,
@@ -47,7 +51,10 @@ type Props = {|
4751| } ;
4852
4953type State = {
54+ assigned_to : TaskAssigneeCollection ,
5055 isEditing : boolean ,
56+ isLoading : boolean ,
57+ loadCollabError : ?ActionItemError ,
5158 modalError : ?ElementsXhrError ,
5259} ;
5360
@@ -67,12 +74,23 @@ const getMessageForTask = (isCurrentUser: boolean, taskType: TaskType) => {
6774
6875class Task extends React . Component < Props , State > {
6976 state = {
77+ loadCollabError : undefined ,
78+ assigned_to : this . props . assigned_to ,
7079 modalError : undefined ,
7180 isEditing : false ,
81+ isLoading : false ,
7282 } ;
7383
74- handleEditClick = ( ) : void => {
75- this . setState ( { isEditing : true } ) ;
84+ handleEditClick = async ( ) => {
85+ const { assigned_to } = this . state ;
86+
87+ if ( assigned_to . next_marker ) {
88+ this . fetchTaskCollaborators ( ) . then ( ( ) => {
89+ this . setState ( { isEditing : true } ) ;
90+ } ) ;
91+ } else {
92+ this . setState ( { isEditing : true } ) ;
93+ }
7694 } ;
7795
7896 handleModalClose = ( ) => {
@@ -88,7 +106,7 @@ class Task extends React.Component<Props, State> {
88106 } ;
89107
90108 getUsersFromTask = ( ) : SelectorItems => {
91- const { assigned_to } = this . props ;
109+ const { assigned_to } = this . state ;
92110
93111 return (
94112 assigned_to &&
@@ -105,9 +123,48 @@ class Task extends React.Component<Props, State> {
105123 ) ;
106124 } ;
107125
126+ fetchTaskCollaborators = ( ) : Promise < any > => {
127+ const { id, api, task_links } = this . props ;
128+ const { entries } = task_links ;
129+ let fileId = '' ;
130+
131+ if ( entries [ 0 ] && entries [ 0 ] . target ) {
132+ fileId = entries [ 0 ] . target . id ;
133+ }
134+
135+ if ( ! fileId ) {
136+ return Promise . reject ( ) ;
137+ }
138+
139+ this . setState ( { isLoading : true } ) ;
140+
141+ return new Promise ( ( resolve , reject ) => {
142+ api . getTaskCollaboratorsAPI ( false ) . getTaskCollaborators ( {
143+ task : { id } ,
144+ file : { id : fileId } ,
145+ errorCallback : ( ) => {
146+ const { errorOccured, taskCollaboratorLoadErrorMessage } = messages ;
147+
148+ this . setState (
149+ {
150+ isLoading : false ,
151+ loadCollabError : {
152+ message : taskCollaboratorLoadErrorMessage ,
153+ title : errorOccured ,
154+ } ,
155+ } ,
156+ reject ,
157+ ) ;
158+ } ,
159+ successCallback : assigned_to => {
160+ this . setState ( { assigned_to, isLoading : false } , resolve ) ;
161+ } ,
162+ } ) ;
163+ } ) ;
164+ } ;
165+
108166 render ( ) {
109167 const {
110- assigned_to ,
111168 created_at,
112169 created_by,
113170 currentUser,
@@ -131,7 +188,7 @@ class Task extends React.Component<Props, State> {
131188 translations,
132189 } = this . props ;
133190
134- const { modalError , isEditing } = this . state ;
191+ const { assigned_to , modalError, isEditing, isLoading , loadCollabError } = this . state ;
135192
136193 const taskPermissions = {
137194 ...permissions ,
@@ -151,13 +208,14 @@ class Task extends React.Component<Props, State> {
151208 ( status === TASK_NEW_NOT_STARTED || status === TASK_NEW_IN_PROGRESS ) ;
152209
153210 const TaskTypeIcon = task_type === TASK_TYPE_APPROVAL ? IconTaskApproval : IconTaskGeneral ;
211+ const inlineError = loadCollabError || error ;
154212
155213 return (
156214 < div className = "bcs-task-container" >
157- { error ? < CommentInlineError { ...error } /> : null }
215+ { inlineError ? < CommentInlineError { ...inlineError } /> : null }
158216 < div
159217 className = { classNames ( 'bcs-task' , {
160- 'bcs-is-pending' : isPending || error ,
218+ 'bcs-is-pending' : isPending || isLoading ,
161219 } ) }
162220 data-testid = "task-card"
163221 >
@@ -249,4 +307,4 @@ class Task extends React.Component<Props, State> {
249307}
250308
251309export { Task as TaskComponent } ;
252- export default flow ( [ withFeatureConsumer ] ) ( Task ) ;
310+ export default flow ( [ withFeatureConsumer , withAPIContext ] ) ( Task ) ;
0 commit comments