summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_shared/components/dismissible_feedback_alert.vue
blob: 2a28b13e7bf74f0b250d0ec6e3feb0c20cb1e6b5 (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
<script>
import { GlAlert, GlSprintf, GlLink } from '@gitlab/ui';
import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue';
import { slugifyWithUnderscore } from '~/lib/utils/text_utility';

export default {
  components: {
    GlAlert,
    GlSprintf,
    GlLink,
    LocalStorageSync,
  },
  props: {
    featureName: {
      type: String,
      required: true,
    },
    feedbackLink: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      isDismissed: false,
    };
  },
  computed: {
    storageKey() {
      return `${slugifyWithUnderscore(this.featureName)}_feedback_dismissed`;
    },
    showAlert() {
      return !this.isDismissed;
    },
  },
  methods: {
    dismissFeedbackAlert() {
      this.isDismissed = true;
    },
  },
};
</script>

<template>
  <div v-show="showAlert">
    <local-storage-sync v-model="isDismissed" :storage-key="storageKey" as-json />
    <gl-alert v-if="showAlert" class="gl-mt-5" @dismiss="dismissFeedbackAlert">
      <gl-sprintf
        :message="
          __(
            'Please share your feedback about %{featureName} %{linkStart}in this issue%{linkEnd} to help us improve the experience.',
          )
        "
      >
        <template #featureName>{{ featureName }}</template>
        <template #link="{ content }">
          <gl-link :href="feedbackLink" target="_blank">{{ content }}</gl-link>
        </template>
      </gl-sprintf>
    </gl-alert>
  </div>
</template>