Welcome to mirror list, hosted at ThFree Co, Russian Federation.

oauth_secret.vue « components « oauth_application « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c4a928c5e07b7fe1f8d29ca822089810876e99a7 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<script>
import { GlButton, GlModal } from '@gitlab/ui';
import { createAlert, VARIANT_SUCCESS, VARIANT_WARNING } from '~/alert';
import axios from '~/lib/utils/axios_utils';
import InputCopyToggleVisibility from '~/vue_shared/components/form/input_copy_toggle_visibility.vue';
import {
  CONFIRM_MODAL,
  CONFIRM_MODAL_TITLE,
  COPY_SECRET,
  DESCRIPTION_SECRET,
  RENEW_SECRET,
  RENEW_SECRET_FAILURE,
  RENEW_SECRET_SUCCESS,
  WARNING_NO_SECRET,
} from '../constants';

export default {
  CONFIRM_MODAL,
  CONFIRM_MODAL_TITLE,
  COPY_SECRET,
  DESCRIPTION_SECRET,
  RENEW_SECRET,
  name: 'OAuthSecret',
  components: {
    GlButton,
    GlModal,
    InputCopyToggleVisibility,
  },
  inject: ['initialSecret', 'renewPath'],
  data() {
    return {
      secret: this.initialSecret,
      alert: null,
      isModalVisible: false,
      isLoading: false,
    };
  },
  computed: {
    actionPrimary() {
      return {
        text: this.$options.RENEW_SECRET,
        attributes: {
          variant: 'confirm',
          loading: this.isLoading,
        },
      };
    },
  },
  created() {
    if (!this.secret) {
      this.alert = createAlert({ message: WARNING_NO_SECRET, variant: VARIANT_WARNING });
    }
  },
  methods: {
    displayModal() {
      this.isModalVisible = true;
    },
    async renewSecret(event) {
      event.preventDefault();
      this.isLoading = true;
      this.alert?.dismiss();

      try {
        const { data } = await axios.put(this.renewPath);
        this.alert = createAlert({ message: RENEW_SECRET_SUCCESS, variant: VARIANT_SUCCESS });
        this.secret = data.secret;
      } catch {
        this.alert = createAlert({ message: RENEW_SECRET_FAILURE });
      } finally {
        this.isLoading = false;
        this.isModalVisible = false;
      }
    },
  },
};
</script>

<template>
  <div class="gl-display-flex gl-flex-wrap gl-gap-5">
    <input-copy-toggle-visibility
      v-if="secret"
      :copy-button-title="$options.COPY_SECRET"
      :value="secret"
      class="gl-mt-n3 gl-mb-0"
    >
      <template #description>
        {{ $options.DESCRIPTION_SECRET }}
      </template>
    </input-copy-toggle-visibility>

    <gl-button category="secondary" class="gl-align-self-start" @click="displayModal">{{
      $options.RENEW_SECRET
    }}</gl-button>

    <gl-modal
      v-model="isModalVisible"
      :title="$options.CONFIRM_MODAL_TITLE"
      size="sm"
      modal-id="modal-renew-secret"
      :action-primary="actionPrimary"
      @primary="renewSecret"
    >
      {{ $options.CONFIRM_MODAL }}
    </gl-modal>
  </div>
</template>