-
Notifications
You must be signed in to change notification settings - Fork 731
Expand file tree
/
Copy pathgitlab-connect.vue
More file actions
100 lines (88 loc) · 2.95 KB
/
gitlab-connect.vue
File metadata and controls
100 lines (88 loc) · 2.95 KB
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
<template>
<div class="flex items-center gap-4">
<!-- <lf-button type="secondary-ghost" @click="isDetailsModalOpen = true">-->
<!-- <lf-icon name="circle-info" type="regular" />-->
<!-- Details-->
<!-- </lf-button>-->
<lf-button type="outline" @click="connect()">
<lf-icon name="link-simple" />
<slot>Connect</slot>
</lf-button>
</div>
</template>
<script setup lang="ts">
import {
defineProps, computed, onMounted, ref,
} from 'vue';
import { useRoute } from 'vue-router';
import config from '@/config';
import ConfirmDialog from '@/shared/dialog/confirm-dialog';
import { AuthService } from '@/modules/auth/services/auth.service';
import LfIcon from '@/ui-kit/icon/Icon.vue';
import LfButton from '@/ui-kit/button/Button.vue';
import { mapActions } from '@/shared/vuex/vuex.helpers';
const route = useRoute();
const props = defineProps<{
integration: any,
segmentId: string | null,
grandparentId: string | null,
}>();
const { doGitlabConnect } = mapActions('integration');
const isFinishingModalOpen = ref(false);
const connectUrl = computed(() => `${config.backendUrl}/gitlab/connect?crowdToken=${AuthService.getToken()}&segments[]=${props.segmentId}`);
const connect = async () => {
try {
if (props.grandparentId && props.segmentId) {
localStorage.setItem('segmentId', props.segmentId);
localStorage.setItem('segmentGrandparentId', props.grandparentId);
}
const result = await ConfirmDialog({
type: 'notification',
title: 'Are you the admin of your GitLab organization?',
titleClass: 'text-lg pt-2',
message: `Only GitLab users with admin permissions are able to connect LFX's GitLab integration.
If you are an organization member, you will need an approval from the GitLab workspace admin.`,
icon: 'fa-circle-info fa-light',
confirmButtonText: "I'm the GitLab organization admin",
cancelButtonText: 'Invite organization admin to this workspace',
verticalCancelButtonClass: 'hidden',
verticalConfirmButtonClass: 'btn btn--md btn--primary w-full !mb-2',
vertical: true,
distinguishCancelAndClose: true,
autofocus: false,
messageClass: 'text-xs !leading-5 !mt-1 text-gray-600',
});
if (result) {
window.open(connectUrl.value, '_self');
}
} catch (error) {
console.error('Error connecting to GitLab:', error);
// Handle error (e.g., show an error message to the user)
}
};
const finallizeGitlabConnect = () => {
const {
code, source, state,
} = route.query;
if (code && source === 'gitlab') {
isFinishingModalOpen.value = true;
doGitlabConnect({
code,
state,
segmentId: props.segmentId,
grandparentId: props.grandparentId,
})
.then(() => {
isFinishingModalOpen.value = false;
});
}
};
onMounted(() => {
finallizeGitlabConnect();
});
</script>
<script lang="ts">
export default {
name: 'LfGitlabConnect',
};
</script>