summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/jira_connect/subscriptions/components/app.vue
blob: 413424be28db0559cef3cc1bf8e412bae6cb433d (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<script>
import { GlAlert, GlButton, GlLink, GlModal, GlModalDirective, GlSprintf } from '@gitlab/ui';
import { mapState, mapMutations } from 'vuex';
import { retrieveAlert, getLocation } from '~/jira_connect/subscriptions/utils';
import { __ } from '~/locale';
import { SET_ALERT } from '../store/mutation_types';
import GroupsList from './groups_list.vue';
import SubscriptionsList from './subscriptions_list.vue';

export default {
  name: 'JiraConnectApp',
  components: {
    GlAlert,
    GlButton,
    GlLink,
    GlModal,
    GlSprintf,
    GroupsList,
    SubscriptionsList,
  },
  directives: {
    GlModalDirective,
  },
  inject: {
    usersPath: {
      default: '',
    },
  },
  data() {
    return {
      location: '',
    };
  },
  computed: {
    ...mapState(['alert']),
    usersPathWithReturnTo() {
      if (this.location) {
        return `${this.usersPath}?return_to=${this.location}`;
      }

      return this.usersPath;
    },
    shouldShowAlert() {
      return Boolean(this.alert?.message);
    },
  },
  modal: {
    cancelProps: {
      text: __('Cancel'),
    },
  },
  created() {
    this.setInitialAlert();
    this.setLocation();
  },
  methods: {
    ...mapMutations({
      setAlert: SET_ALERT,
    }),
    async setLocation() {
      this.location = await getLocation();
    },
    setInitialAlert() {
      const { linkUrl, title, message, variant } = retrieveAlert() || {};
      this.setAlert({ linkUrl, title, message, variant });
    },
  },
};
</script>

<template>
  <div>
    <gl-alert
      v-if="shouldShowAlert"
      class="gl-mb-7"
      :variant="alert.variant"
      :title="alert.title"
      @dismiss="setAlert"
    >
      <gl-sprintf v-if="alert.linkUrl" :message="alert.message">
        <template #link="{ content }">
          <gl-link :href="alert.linkUrl" target="_blank">{{ content }}</gl-link>
        </template>
      </gl-sprintf>

      <template v-else>
        {{ alert.message }}
      </template>
    </gl-alert>

    <h2 class="gl-text-center">{{ s__('JiraService|GitLab for Jira Configuration') }}</h2>

    <div class="jira-connect-app-body gl-my-7 gl-px-5 gl-pb-4">
      <div class="gl-display-flex gl-justify-content-end">
        <gl-button
          v-if="usersPath"
          category="primary"
          variant="info"
          class="gl-align-self-center"
          :href="usersPathWithReturnTo"
          target="_blank"
          >{{ s__('Integrations|Sign in to add namespaces') }}</gl-button
        >
        <template v-else>
          <gl-button
            v-gl-modal-directive="'add-namespace-modal'"
            category="primary"
            variant="info"
            class="gl-align-self-center"
            >{{ s__('Integrations|Add namespace') }}</gl-button
          >
          <gl-modal
            modal-id="add-namespace-modal"
            :title="s__('Integrations|Link namespaces')"
            :action-cancel="$options.modal.cancelProps"
          >
            <groups-list />
          </gl-modal>
        </template>
      </div>

      <subscriptions-list />
    </div>
  </div>
</template>