<commit_before>import Ember from 'ember';
import ENV from 'irene/config/environment';
import { translationMacro as t } from 'ember-i18n';

const TeamDetailsComponent = Ember.Component.extend({

  i18n: Ember.inject.service(),
  ajax: Ember.inject.service(),
  notify: Ember.inject.service('notification-messages-service'),
  showHide: true,
  editSave: false,
  identification: "",
  isAddingMember: false,
  organizationTeam: null,
  isInvitingMember: false,
  isSearchingMember: false,

  tEmptyEmailId: t("emptyEmailId"),
  tTeamMemberInvited: t("teamMemberInvited"),
  tOrganizationTeamNameUpdated: t("organizationTeamNameUpdated"),

  orgTeam: (function() {
    const orgId = this.get("organization.id");
    const teamId = this.get("team.teamId");
    return this.get("store").queryRecord('organization-team', {orgId: orgId, teamId: teamId});
  }).property(),

  teamMembers: (function() {
    const orgId = this.get("organization.id");
    const teamId = this.get("team.teamId");
    return this.get("store").query('team-member', {orgId: orgId, teamId: teamId});
  }).property(),

  teamProjects: (function() {
    const orgId = this.get("organization.id");
    const teamId = this.get("team.teamId");
    return this.get("store").query('team-project', {orgId: orgId, teamId: teamId});
  }).property(),

  searchMember() {
    const searchText = this.get("identification");
    const searchQuery = `q=${searchText}`;
    const url = [ENV.endpoints.userSearch, searchQuery].join('?');
    this.set("isSearchingMember", true);
    const that = this;
    this.get("ajax").request(url)
    .then(function(response) {
      if(!that.isDestroyed) {
        that.set("isSearchingMember", false);
      }
      const allUsers = response.data;
      const allUsersData = allUsers.map((user) => ({
        id: user.id,
        username: user.attributes.username,
        email: user.attributes.email
      }));
      that.set("users", allUsersData);
    })
    .catch(function(error) {
      that.set("isSearchingMember", false);
      that.get("notify").error(error.payload.message);
    });
  },

  actions: {

    openAddMemberModal() {
      this.set("showAddMemberModal", true);
    },

    searchQuery() {
      Ember.run.debounce(this, this.searchMember, 500);
    },

    addMember(userId) {
      const teamId = this.get("organizationTeam.id");
      const orgId = this.get("organizationTeam.organization.id");
      const url = [ENV.endpoints.organizations, orgId, ENV.endpoints.teams, teamId, ENV.endpoints.members, userId].join("/");
      const that = this;
      this.set("isAddingMember", true);
      this.get("ajax").put(url)
      .then(function(data){
        that.get("notify").success("Team member added");
        if(!that.isDestroyed) {
          that.set("isAddingMember", false);
          that.set("identification", "");
          that.set("showAddMemberModal", false);
          that.store.pushPayload(data);
        }
      })
      .catch(function(error){
        that.set("isAddingMember", false);
        that.get("notify").error(error.payload.message);
      });
    },

    inviteMember() {
      const identification = this.get("identification");
      const tTeamMemberInvited = this.get("tTeamMemberInvited");
      if(Ember.isEmpty(identification)) {
        const tEmptyEmailId = this.get("tEmptyEmailId");
        return this.get("notify").error(tEmptyEmailId);
      }
      const data = {
        identification: identification,
        team_id: this.get("organizationTeam.id")
      };
      this.set("isInvitingMember", true);
      this.get("ajax").post(url, {data})
      .then((data) => {
        if (__guard__(data != null ? data.data : undefined, x => x.type) === "team") {
          this.store.pushPayload(data);
          this.get("notify").success(tTeamMemberAdded);
        } else {
          this.get("notify").success(tTeamMemberInvited);
        }
        if(!this.isDestroyed) {
          this.set("isInvitingMember", false);
          this.set("teamMember", "");
          this.set("showAddMemberModal", false);
        }
      }, (error) => {
        this.set("isInvitingMember", false);
        this.get("notify").error(error.payload.message);<commit_msg>fix: add org member to team and invite member to team<commit_after>import Ember from 'ember';
import ENV from 'irene/config/environment';
import { translationMacro as t } from 'ember-i18n';

const TeamDetailsComponent = Ember.Component.extend({

  i18n: Ember.inject.service(),
  ajax: Ember.inject.service(),
  notify: Ember.inject.service('notification-messages-service'),
  showHide: true,
  editSave: false,
  identification: "",
  isAddingMember: false,
  organizationTeam: null,
  isInvitingMember: false,
  isSearchingMember: false,

  tEmptyEmailId: t("emptyEmailId"),
  tTeamMemberInvited: t("teamMemberInvited"),
  tOrganizationTeamNameUpdated: t("organizationTeamNameUpdated"),

  orgTeam: (function() {
    const orgId = this.get("organization.id");
    const teamId = this.get("team.teamId");
    return this.get("store").queryRecord('organization-team', {orgId: orgId, teamId: teamId});
  }).property(),

  teamMembers: (function() {
    const orgId = this.get("organization.id");
    const teamId = this.get("team.teamId");
    return this.get("store").query('team-member', {orgId: orgId, teamId: teamId});
  }).property(),

  teamProjects: (function() {
    const orgId = this.get("organization.id");
    const teamId = this.get("team.teamId");
    return this.get("store").query('team-project', {orgId: orgId, teamId: teamId});
  }).property(),

  searchMember() {
    const searchText = this.get("identification");
    const searchQuery = `q=${searchText}`;
    const url = [ENV.endpoints.userSearch, searchQuery].join('?');
    this.set("isSearchingMember", true);
    const that = this;
    this.get("ajax").request(url)
    .then(function(response) {
      if(!that.isDestroyed) {
        that.set("isSearchingMember", false);
      }
      const allUsers = response.data;
      const allUsersData = allUsers.map((user) => ({
        id: user.id,
        username: user.attributes.username,
        email: user.attributes.email
      }));
      that.set("users", allUsersData);
    })
    .catch(function(error) {
      that.set("isSearchingMember", false);
      that.get("notify").error(error.payload.message);
    });
  },

  actions: {

    openAddMemberModal() {
      this.set("showAddMemberModal", true);
    },

    searchQuery() {
      Ember.run.debounce(this, this.searchMember, 500);
    },

    addMember(userId) {
      const orgId = this.get("organization.id");
      const teamId = this.get("team.teamId");
      const url = [ENV.endpoints.organizations, orgId, ENV.endpoints.teams, teamId, ENV.endpoints.members, userId].join("/");
      const that = this;
      this.set("isAddingMember", true);
      this.get("ajax").put(url)
      .then(function(data){
        that.get("notify").success("Team member added");
        if(!that.isDestroyed) {
          that.set("isAddingMember", false);
          that.set("identification", "");
          that.set("showAddMemberModal", false);
          that.store.pushPayload(data);
        }
      })
      .catch(function(error){
        that.set("isAddingMember", false);
        that.get("notify").error(error.payload.message);
      });
    },

    inviteMember() {
      const identification = this.get("identification");
      const tTeamMemberInvited = this.get("tTeamMemberInvited");
      if(Ember.isEmpty(identification)) {
        const tEmptyEmailId = this.get("tEmptyEmailId");
        return this.get("notify").error(tEmptyEmailId);
      }
      const data = {
        identification: identification,
        team_id: this.get("team.teamId")
      };
      this.set("isInvitingMember", true);
      this.get("ajax").post(url, {data})
      .then((data) => {
        if (__guard__(data != null ? data.data : undefined, x => x.type) === "team") {
          this.store.pushPayload(data);
          this.get("notify").success(tTeamMemberAdded);
        } else {
          this.get("notify").success(tTeamMemberInvited);
        }
        if(!this.isDestroyed) {
          this.set("isInvitingMember", false);
          this.set("teamMember", "");
          this.set("showAddMemberModal", false);
        }
      }, (error) => {
        this.set("isInvitingMember", false);
        this.get("notify").error(error.payload.message);
{'fraction_non_alphanumeric': 0.16229683236445605, 'fraction_numerical': 0.0016609324949578834, 'mean_word_length': 3.144542772861357, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '99182', 'n_tokens_mistral': 2598, 'n_tokens_neox': 2556, 'n_words': 441}