summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_multiversion/index.vue
blob: 5ff75e19425dd55eaef430ee71f6f7459845d3f8 (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 { mapMutations } from 'vuex';
import { GlButton } from '@gitlab/ui';
import { s__ } from '~/locale';

import { reloadPage, persistBaseUrl, retrieveBaseUrl } from '~/jira_connect/subscriptions/utils';
import { updateInstallation, setApiBaseURL } from '~/jira_connect/subscriptions/api';
import { I18N_UPDATE_INSTALLATION_ERROR_MESSAGE } from '~/jira_connect/subscriptions/constants';
import { SET_ALERT } from '~/jira_connect/subscriptions/store/mutation_types';

import SignInOauthButton from '../../../components/sign_in_oauth_button.vue';
import VersionSelectForm from './version_select_form.vue';

export default {
  name: 'SignInGitlabMultiversion',
  components: {
    GlButton,
    SignInOauthButton,
    VersionSelectForm,
  },
  data() {
    return {
      gitlabBasePath: null,
      loadingVersionSelect: false,
    };
  },
  computed: {
    hasSelectedVersion() {
      return this.gitlabBasePath !== null;
    },
    subtitle() {
      return this.hasSelectedVersion
        ? this.$options.i18n.signInSubtitle
        : this.$options.i18n.versionSelectSubtitle;
    },
  },
  mounted() {
    this.gitlabBasePath = retrieveBaseUrl();
    setApiBaseURL(this.gitlabBasePath);
  },
  methods: {
    ...mapMutations({
      setAlert: SET_ALERT,
    }),
    resetGitlabBasePath() {
      this.gitlabBasePath = null;
      setApiBaseURL();
    },
    onVersionSelect(gitlabBasePath) {
      this.loadingVersionSelect = true;
      updateInstallation(gitlabBasePath)
        .then(() => {
          persistBaseUrl(gitlabBasePath);
          reloadPage();
        })
        .catch(() => {
          this.setAlert({
            message: I18N_UPDATE_INSTALLATION_ERROR_MESSAGE,
            variant: 'danger',
          });
          this.loadingVersionSelect = false;
        });
    },
    onSignInError() {
      this.$emit('error');
    },
  },
  i18n: {
    title: s__('JiraService|Welcome to GitLab for Jira'),
    signInSubtitle: s__('JiraService|Sign in to GitLab to link namespaces.'),
    versionSelectSubtitle: s__('JiraService|What version of GitLab are you using?'),
    changeVersionButtonText: s__('JiraService|Change GitLab version'),
  },
};
</script>

<template>
  <div>
    <div class="gl-text-center">
      <h2>{{ $options.i18n.title }}</h2>
      <p data-testid="subtitle">{{ subtitle }}</p>
    </div>

    <version-select-form
      v-if="!hasSelectedVersion"
      class="gl-mt-7"
      :loading="loadingVersionSelect"
      @submit="onVersionSelect"
    />

    <div v-else class="gl-text-center">
      <sign-in-oauth-button
        class="gl-mb-5"
        :gitlab-base-path="gitlabBasePath"
        @sign-in="$emit('sign-in-oauth', $event)"
        @error="onSignInError"
      />

      <div>
        <gl-button category="tertiary" variant="confirm" @click="resetGitlabBasePath">
          {{ $options.i18n.changeVersionButtonText }}
        </gl-button>
      </div>
    </div>
  </div>
</template>