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
|
<script>
import { mapActions } from 'vuex';
import { GlButton } from '@gitlab/ui';
import { addSubscription } from '~/jira_connect/subscriptions/api';
import { persistAlert, reloadPage } from '~/jira_connect/subscriptions/utils';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import GroupItemName from '../group_item_name.vue';
import {
INTEGRATIONS_DOC_LINK,
I18N_ADD_SUBSCRIPTION_SUCCESS_ALERT_TITLE,
I18N_ADD_SUBSCRIPTION_SUCCESS_ALERT_MESSAGE,
I18N_ADD_SUBSCRIPTIONS_ERROR_MESSAGE,
} from '../../constants';
export default {
components: {
GlButton,
GroupItemName,
},
mixins: [glFeatureFlagMixin()],
inject: {
addSubscriptionsPath: {
default: '',
},
subscriptionsPath: {
default: '',
},
},
props: {
group: {
type: Object,
required: true,
},
disabled: {
type: Boolean,
required: false,
default: false,
},
},
data() {
return {
isLoading: false,
};
},
computed: {
oauthEnabled() {
return this.glFeatures.jiraConnectOauth;
},
},
methods: {
...mapActions(['addSubscription']),
async onClick() {
if (this.oauthEnabled) {
this.isLoading = true;
await this.addSubscription({
namespacePath: this.group.full_path,
subscriptionsPath: this.subscriptionsPath,
});
this.isLoading = false;
} else {
this.deprecatedAddSubscription();
}
},
deprecatedAddSubscription() {
this.isLoading = true;
addSubscription(this.addSubscriptionsPath, this.group.full_path)
.then(() => {
persistAlert({
title: I18N_ADD_SUBSCRIPTION_SUCCESS_ALERT_TITLE,
message: I18N_ADD_SUBSCRIPTION_SUCCESS_ALERT_MESSAGE,
linkUrl: INTEGRATIONS_DOC_LINK,
variant: 'success',
});
reloadPage();
})
.catch((error) => {
this.$emit('error', error?.response?.data?.error || I18N_ADD_SUBSCRIPTIONS_ERROR_MESSAGE);
this.isLoading = false;
});
},
},
};
</script>
<template>
<li class="gl-border-b-1 gl-border-b-solid gl-border-b-gray-100">
<div class="gl-display-flex gl-align-items-center gl-py-3">
<div class="gl-min-w-0 gl-display-flex gl-flex-grow-1 gl-flex-shrink-1 gl-align-items-center">
<div class="gl-min-w-0 gl-flex-grow-1 flex-shrink-1">
<group-item-name :group="group" />
</div>
<gl-button
category="secondary"
variant="confirm"
:loading="isLoading"
:disabled="disabled"
@click.prevent="onClick"
>
{{ __('Link') }}
</gl-button>
</div>
</div>
</li>
</template>
|