         resolve { invites, admins }
       else
         resolve { invites }
-
-
-getNewInvitations = (invites, pendingInvitations) ->
-  new Promise (resolve, reject) ->
-    pendingEmails=[]
-
-    pendingInvitations.map (invite) ->
-      pendingEmails.push invite.get('email')
-
-    newInvitations = (invite for invite, i in invites when invite.email not in pendingEmails)
-    resolve { newInvitations }
-
-
-
-updateInviteInput = (index, inputType, value) ->
-
-  { reactor } = kd.singletons
-
-
-  reactor.dispatch actions.SET_TEAM_INVITE_INPUT_VALUE, { index, inputType, value }
-
-
-fetchMembers = (options = {}) ->
-
-  { groupsController, reactor } = kd.singletons
-
-  team = groupsController.getCurrentGroup()
-  reactor.dispatch actions.FETCH_TEAM_MEMBERS_BEGIN, { team }
-
-  team.fetchMembersWithEmail {}, options, (err, users) ->
-    reactor.dispatch actions.FETCH_TEAM_MEMBERS_SUCCESS, { users }
-
-
-fetchMembersRole = ->
-
-  { groupsController, reactor } = kd.singletons
-
-  team = groupsController.getCurrentGroup()
-  reactor.dispatch actions.FETCH_TEAM_MEMBERS_ROLES_BEGIN, { team }
-
-  myId = whoami().getId()
-  teamMemberIds = reactor.evaluate getters.TeamMembersIdStore
-  
-  ids = teamMemberIds.toArray()
-  ids.push myId
-  
-  team.fetchUserRoles ids, (err, roles) ->
-    reactor.dispatch actions.FETCH_TEAM_MEMBERS_ROLES_SUCCESS, roles
 
 
 loadPendingInvites = (invites) ->

  admins  = []

  new Promise (resolve, reject) ->
    whoami().fetchEmail (err, ownEmail) =>

      inviteInputs.forEach (inviteInput) ->
        email = inviteInput.get('email').trim()

        return  unless email

        validatedEmail = validateEmail email

        if email.toLowerCase() is ownEmail

          return reject { message: 'You can not invite yourself!'}

        if email and not validatedEmail

          return reject { message: 'That doesn\'t seem like a valid email address.'}


      resolve { message }


updateInviteInput = (index, inputType, value) ->

  { reactor } = kd.singletons


  reactor.dispatch actions.SET_TEAM_INVITE_INPUT_VALUE, { index, inputType, value }


fetchMembers = (options = {}) ->

  { groupsController, reactor } = kd.singletons

  team = groupsController.getCurrentGroup()
  reactor.dispatch actions.FETCH_TEAM_MEMBERS_BEGIN, { team }

  team.fetchMembersWithEmail {}, options, (err, users) ->
    reactor.dispatch actions.FETCH_TEAM_MEMBERS_SUCCESS, { users }


fetchMembersRole = ->

  { groupsController, reactor } = kd.singletons

  team = groupsController.getCurrentGroup()
  reactor.dispatch actions.FETCH_TEAM_MEMBERS_ROLES_BEGIN, { team }

  myId = whoami().getId()
  teamMemberIds = reactor.evaluate getters.TeamMembersIdStore

  ids = teamMemberIds.toArray()
  ids.push myId

  team.fetchUserRoles ids, (err, roles) ->
    reactor.dispatch actions.FETCH_TEAM_MEMBERS_ROLES_SUCCESS, roles


inviteMembers = (inviteInputs) ->
