summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/groups/components/invite_members_banner.vue
blob: 747cea6a46e3594ecf8e6e8d791464ee2b4b432b (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
<script>
import { GlBanner } from '@gitlab/ui';
import { parseBoolean, setCookie, getCookie } from '~/lib/utils/common_utils';
import { s__ } from '~/locale';
import Tracking from '~/tracking';

const trackingMixin = Tracking.mixin();

export default {
  components: {
    GlBanner,
  },
  mixins: [trackingMixin],
  inject: ['svgPath', 'inviteMembersPath', 'isDismissedKey', 'trackLabel'],
  data() {
    return {
      isDismissed: parseBoolean(getCookie(this.isDismissedKey)),
      tracking: {
        label: this.trackLabel,
      },
    };
  },
  created() {
    this.$nextTick(() => {
      this.addTrackingAttributesToButton();
    });
  },
  mounted() {
    this.trackOnShow();
  },
  methods: {
    handleClose() {
      setCookie(this.isDismissedKey, true);
      this.isDismissed = true;
      this.track(this.$options.dismissEvent);
    },
    trackOnShow() {
      this.$nextTick(() => {
        if (!this.isDismissed) this.track(this.$options.displayEvent);
      });
    },
    addTrackingAttributesToButton() {
      if (this.$refs.banner === undefined) return;

      const button = this.$refs.banner.$el.querySelector(`[href='${this.inviteMembersPath}']`);

      if (button) {
        button.setAttribute('data-track-event', this.$options.buttonClickEvent);
        button.setAttribute('data-track-label', this.trackLabel);
      }
    },
  },
  i18n: {
    title: s__('InviteMembersBanner|Collaborate with your team'),
    body: s__(
      "InviteMembersBanner|We noticed that you haven't invited anyone to this group. Invite your colleagues so you can discuss issues, collaborate on merge requests, and share your knowledge.",
    ),
    button_text: s__('InviteMembersBanner|Invite your colleagues'),
  },
  displayEvent: 'invite_members_banner_displayed',
  buttonClickEvent: 'invite_members_banner_button_clicked',
  dismissEvent: 'invite_members_banner_dismissed',
};
</script>

<template>
  <gl-banner
    v-if="!isDismissed"
    ref="banner"
    :title="$options.i18n.title"
    :button-text="$options.i18n.button_text"
    :svg-path="svgPath"
    :button-link="inviteMembersPath"
    @close="handleClose"
  >
    <p>{{ $options.i18n.body }}</p>
  </gl-banner>
</template>