@@ -9,6 +9,7 @@ import CoderBot from '../../../../components/CoderBot/CoderBot'
99import ProjectListNavHeader from './ProjectListNavHeader'
1010import ProjectsGridView from './ProjectsGridView'
1111import ProjectsCardView from '../../../components/projectsCard/ProjectsCardView'
12+ import { acceptOrRefuseInvite } from '../../../actions/projectMember'
1213import { loadProjects , setInfiniteAutoload , setProjectsListView } from '../../../actions/loadProjects'
1314import { loadProjectsMetadata } from '../../../../actions/templates'
1415import { sortProjects } from '../../../actions/sortProjects'
@@ -18,7 +19,9 @@ import { updateProject } from '../../../actions/project'
1819import { getNewProjectLink } from '../../../../helpers/projectHelper'
1920import { ROLE_CONNECT_MANAGER , ROLE_CONNECT_ACCOUNT_MANAGER , ROLE_CONNECT_COPILOT , ROLE_ADMINISTRATOR ,
2021 ROLE_CONNECT_ADMIN , PROJECT_STATUS , PROJECT_STATUS_CANCELLED ,
21- PROJECT_LIST_DEFAULT_CRITERIA , PROJECTS_LIST_VIEW , PROJECTS_LIST_PER_PAGE , SCREEN_BREAKPOINT_MD } from '../../../../config/constants'
22+ PROJECT_LIST_DEFAULT_CRITERIA , PROJECTS_LIST_VIEW , PROJECTS_LIST_PER_PAGE , SCREEN_BREAKPOINT_MD ,
23+ PROJECT_MEMBER_INVITE_STATUS_ACCEPTED , PROJECT_MEMBER_INVITE_STATUS_REFUSED ,
24+ } from '../../../../config/constants'
2225import TwoColsLayout from '../../../../components/TwoColsLayout'
2326import UserSidebar from '../../../../components/UserSidebar/UserSidebar'
2427
@@ -37,7 +40,9 @@ const EnhancedCards = dataLoadHandler(errorHandler(ProjectsCardView))
3740class Projects extends Component {
3841 constructor ( props ) {
3942 super ( props )
40- this . state = { }
43+ this . state = {
44+ isAcceptingInvite : { }
45+ }
4146 this . sortHandler = this . sortHandler . bind ( this )
4247 this . onChangeStatus = this . onChangeStatus . bind ( this )
4348 this . onPageChange = this . onPageChange . bind ( this )
@@ -47,6 +52,7 @@ class Projects extends Component {
4752 this . changeView = this . changeView . bind ( this )
4853 this . init = this . init . bind ( this )
4954 this . removeScrollPosition = this . removeScrollPosition . bind ( this )
55+ this . callInviteRequest = this . callInviteRequest . bind ( this )
5056 }
5157
5258 componentWillUnmount ( ) {
@@ -191,9 +197,37 @@ class Projects extends Component {
191197 this . props . loadProjects ( criteria )
192198 }
193199
200+ /**
201+ * Call request to accept or decline invite
202+ * @param {Object } project project info
203+ * @param {Bool } isAccept is accept invite
204+ */
205+ callInviteRequest ( project , isAccept ) {
206+ const isAcceptingInvite = ( isAcception ) => {
207+ const { isAcceptingInvite } = this . state
208+ isAcceptingInvite [ project . id ] = isAcception
209+ this . setState ( { isAcceptingInvite } )
210+ }
211+
212+ isAcceptingInvite ( true )
213+
214+ this . props . acceptOrRefuseInvite ( project . id , {
215+ userId : this . props . currentUser . userId ,
216+ email : this . props . currentUser . email ,
217+ status : isAccept ? PROJECT_MEMBER_INVITE_STATUS_ACCEPTED : PROJECT_MEMBER_INVITE_STATUS_REFUSED
218+ } , this . props . currentUser ) . then ( ( ) => {
219+ isAcceptingInvite ( false )
220+ } ) . catch ( ( err ) => {
221+ // if we fail to accept invite
222+ console . log ( err )
223+ isAcceptingInvite ( false )
224+ } )
225+ }
226+
194227 render ( ) {
195228 const { isPowerUser, isCustomer, isLoading, totalCount, criteria, projectsListView, setProjectsListView,
196229 setInfiniteAutoload, loadProjects, history, orgConfig, allProjectsCount, user } = this . props
230+ const { isAcceptingInvite } = this . state
197231 // show walk through if user is customer and no projects were returned
198232 // for default filters
199233 const showWalkThrough = ! isLoading && ! isPowerUser && totalCount === 0 && allProjectsCount === 0 &&
@@ -212,6 +246,8 @@ class Projects extends Component {
212246 setFilter = { this . setFilter }
213247 criteria = { criteria }
214248 isCustomer = { isCustomer }
249+ callInviteRequest = { this . callInviteRequest }
250+ isAcceptingInvite = { isAcceptingInvite }
215251 />
216252 )
217253 const cardView = (
@@ -224,6 +260,8 @@ class Projects extends Component {
224260 onChangeStatus = { this . onChangeStatus }
225261 projectsStatus = { getStatusCriteriaText ( criteria ) }
226262 newProjectLink = { getNewProjectLink ( orgConfig ) }
263+ callInviteRequest = { this . callInviteRequest }
264+ isAcceptingInvite = { isAcceptingInvite }
227265 />
228266 )
229267 let projectsView
@@ -324,6 +362,14 @@ const mapStateToProps = ({ projectSearch, members, loadUser, projectState, templ
324362 }
325363}
326364
327- const actionsToBind = { loadProjects, setInfiniteAutoload, updateProject, setProjectsListView, sortProjects, loadProjectsMetadata }
365+ const actionsToBind = {
366+ loadProjects,
367+ setInfiniteAutoload,
368+ updateProject,
369+ setProjectsListView,
370+ sortProjects,
371+ loadProjectsMetadata,
372+ acceptOrRefuseInvite
373+ }
328374
329375export default withRouter ( connect ( mapStateToProps , actionsToBind ) ( Projects ) )
0 commit comments