<commit_before><template>
  <div>
    <h1><i18n>Invite Members</i18n></h1>
    <input
      type="text"
      name="invitee"
      class="input"
      v-model="currentInvitee"
    >
    <button
      @click.prevent="addInvitee()"
    >
      <i18n>Add</i18n>
    </button>
    <ul>
      <li v-for="invitee in invitees">{{ invitee }}</li>
    </ul>
    <p><i18n>Who would you like to include in your group?</i18n></p>
  </div>
</template>
<script>
export default {
  name: 'CreateGroupInvitees',
  props: {
    value: {type: Array}
  },
  data: function () {
    return {
      invitees: this.value,
      currentInvitee: ''
    }
  },
  methods: {
    addInvitee: function () {
      this.invitees.push(this.currentInvitee)
      this.currentInvitee = ''
      this.$emit('input', this.invitees)
    }
  }
}
</script><commit_msg>invite step now checks if user exists<commit_after><template>
  <div>
    <h1><i18n>Invite Members</i18n></h1>
    <input
      type="text"
      name="invitee"
      class="input"
      v-model="searchUser"
    >
    <button
      @click.prevent="addInvitee()"
    >
      <i18n>Add</i18n>
    </button>

    <p><i18n>Who would you like to include in your group?</i18n></p>

    <p v-if="userErrorMsg" class="help is-danger">{{ userErrorMsg }}</p>

    <table
            class="table is-bordered is-striped is-narrow"
            v-if="invitees.length"
    >
      <thead>
      <tr>
        <th class="table-header"><i18n>Initial Invitees</i18n></th>
      </tr>
      </thead>
      <tbody>
      <tr v-for="(invitee, index) in invitees" class="member">
        <td>
          <div class="media">
            <div class="media-left">
              <p class="image is-64x64">
                <!-- TODO: use responsive figure:
              http://bulma.io/documentation/elements/image/ -->
                <!-- TODO: ideally these would be loaded from cache -->
                <img :src="invitee.state.attributes.picture" width="64" height="64">
              </p>
            </div>
            <div class="media-content">
              <strong>{{invitee.state.attributes.name}}</strong>
            </div>
            <div class="media-right">
              <button class="delete" @click="remove(index)"></button>
            </div>
          </div>
        </td>
      </tr>
      </tbody>
    </table>

  </div>
</template>
<style lang="scss" scoped>
.table-header {
  background-color: #fafafa;
}
.media {
  align-items: center;
}
.add-form {
  margin-bottom: 2rem;
}
.notification-icon {
  margin-right: 1rem;
}
</style>
<script>
import { latestContractState } from '../../js/state'
import { namespace } from '../../js/backend/hapi'
import L from '../../js/translations'

export default {
  name: 'CreateGroupInvitees',
  props: {
    value: {type: Array}
  },
  data: function () {
    return {
      invitees: this.value,
      searchUser: '',
      userErrorMsg: ''
    }
  },
  methods: {
    async addInvitee () {
      if (!this.searchUser) return

      if (this.searchUser === this.$store.state.loggedIn.name) {
        this.userErrorMsg = L('Invalid User: Cannot Invite One\'s self')
        return
      } else {
        this.userErrorMsg = ''
      }

      try {
        const contractId = await namespace.lookup(this.searchUser)
        console.log('contractId:', contractId)
        const state = await latestContractState(contractId)
        if (!this.invitees.find(invitee => invitee.state.attributes.name === this.searchUser)) {
          this.invitees.push({ state, contractId })
        }
        this.searchUser = null
        this.userErrorMsg = ''
        this.$emit('input', this.invitees)
      } catch (err) {
        console.log(err)
        this.userErrorMsg = L('Invalid User')
      }
    }
  }
}
</script>
{'fraction_non_alphanumeric': 0.1623841059602649, 'fraction_numerical': 0.011125827814569536, 'mean_word_length': 2.084967320261438, 'pattern_counts': {'":': 0, '<': 82, '<?xml version=': 0, '>': 83, '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': '5324275', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1259, 'n_words': 246}