summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/jira_connect/subscriptions/components/user_link.vue
blob: 5e2c83aff651474109a00df9349f522deb3118f3 (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
<script>
import { GlLink, GlSprintf } from '@gitlab/ui';
import { __ } from '~/locale';
import { getGitlabSignInURL } from '~/jira_connect/subscriptions/utils';

export default {
  components: {
    GlLink,
    GlSprintf,
  },
  inject: {
    usersPath: {
      default: '',
    },
    gitlabUserPath: {
      default: '',
    },
  },
  props: {
    userSignedIn: {
      type: Boolean,
      required: true,
    },
    hasSubscriptions: {
      type: Boolean,
      required: true,
    },
    user: {
      type: Object,
      required: false,
      default: null,
    },
  },
  data() {
    return {
      signInURL: '',
    };
  },
  computed: {
    gitlabUserName() {
      return gon.current_username ?? this.user?.username;
    },
    gitlabUserHandle() {
      return this.gitlabUserName ? `@${this.gitlabUserName}` : undefined;
    },
    gitlabUserLink() {
      return this.gitlabUserPath ?? `${gon.relative_root_url}/${this.gitlabUserName}`;
    },
    signedInText() {
      return this.gitlabUserHandle
        ? this.$options.i18n.signedInAsUserText
        : this.$options.i18n.signedInText;
    },
  },
  async created() {
    this.signInURL = await getGitlabSignInURL(this.usersPath);
  },
  i18n: {
    signInText: __('Sign in to GitLab'),
    signedInAsUserText: __('Signed in to GitLab as %{user_link}'),
    signedInText: __('Signed in to GitLab'),
  },
};
</script>
<template>
  <div class="jira-connect-user gl-font-base">
    <gl-sprintf v-if="userSignedIn" :message="signedInText">
      <template #user_link>
        <gl-link data-testid="gitlab-user-link" :href="gitlabUserLink" target="_blank">
          {{ gitlabUserHandle }}
        </gl-link>
      </template>
    </gl-sprintf>

    <gl-link
      v-else-if="hasSubscriptions"
      data-testid="sign-in-link"
      :href="signInURL"
      target="_blank"
    >
      {{ $options.i18n.signInText }}
    </gl-link>
  </div>
</template>