summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/deploy_keys/components/action_btn.vue
blob: 10548da8ec52af542311b2a4cca93d5b7732167d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<script>
import eventHub from '../eventhub';

export default {
  props: {
    deployKey: {
      type: Object,
      required: true,
    },
    type: {
      type: String,
      required: true,
    },
    btnCssClass: {
      type: String,
      required: false,
      default: 'btn-default',
    },
  },
  data() {
    return {
      isLoading: false,
    };
  },
  methods: {
    doAction() {
      this.isLoading = true;

      eventHub.$emit(`${this.type}.key`, this.deployKey, () => {
        this.isLoading = false;
      });
    },
  },
};
</script>

<template>
  <button
    :class="[{ disabled: isLoading }, btnCssClass]"
    :disabled="isLoading"
    class="btn"
    @click="doAction">
    <slot></slot>
    <gl-loading-icon
      v-if="isLoading"
      :inline="true"
    />
  </button>
</template>