summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/surveys/merge_request_experience/app.vue
blob: 6e90ad2e0fd1d2d890e0f3c77dd142c0f62f2677 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<script>
import { GlButton, GlSprintf, GlTooltipDirective } from '@gitlab/ui';
import gitlabLogo from '@gitlab/svgs/dist/illustrations/gitlab_logo.svg';
import SafeHtml from '~/vue_shared/directives/safe_html';
import { s__, __ } from '~/locale';
import UserCalloutDismisser from '~/vue_shared/components/user_callout_dismisser.vue';
import SatisfactionRate from '~/surveys/components/satisfaction_rate.vue';
import Tracking from '~/tracking';

const steps = [
  {
    label: 'overall',
    question: s__('MrSurvey|Overall, how satisfied are you with merge requests?'),
  },
  {
    label: 'performance',
    question: s__(
      'MrSurvey|How satisfied are you with %{strongStart}speed/performance%{strongEnd} of merge requests?',
    ),
  },
];

const MR_RENDER_LS_KEY = 'mr_survey_rendered';

export default {
  name: 'MergeRequestExperienceSurveyApp',
  components: {
    UserCalloutDismisser,
    GlSprintf,
    GlButton,
    SatisfactionRate,
  },
  directives: {
    SafeHtml,
    tooltip: GlTooltipDirective,
  },
  mixins: [Tracking.mixin()],
  props: {
    accountAge: {
      type: Number,
      required: true,
    },
  },
  i18n: {
    survey: s__('MrSurvey|Merge request experience survey'),
    close: __('Close'),
    legal: s__(
      'MrSurvey|By continuing, you acknowledge that responses will be used to improve GitLab and in accordance with the %{linkStart}GitLab Privacy Policy%{linkEnd}.',
    ),
    thanks: s__('MrSurvey|Thank you for your feedback!'),
  },
  gitlabLogo,
  data() {
    return {
      visible: false,
      stepIndex: 0,
    };
  },
  computed: {
    step() {
      return steps[this.stepIndex];
    },
  },
  mounted() {
    document.addEventListener('keyup', this.handleKeyup);
  },
  destroyed() {
    document.removeEventListener('keyup', this.handleKeyup);
  },
  methods: {
    onQueryLoaded({ shouldShowCallout }) {
      this.visible = shouldShowCallout;
      if (!this.visible) this.$emit('close');
      else if (!localStorage?.getItem(MR_RENDER_LS_KEY)) {
        this.track('survey:mr_experience', {
          label: 'render',
          extra: {
            accountAge: this.accountAge,
          },
        });
        localStorage?.setItem(MR_RENDER_LS_KEY, '1');
      }
    },
    onRate(event) {
      this.$refs.dismisser?.dismiss();
      this.$emit('rate');
      localStorage?.removeItem(MR_RENDER_LS_KEY);
      this.track('survey:mr_experience', {
        label: this.step.label,
        value: event,
        extra: {
          accountAge: this.accountAge,
        },
      });
      this.stepIndex += 1;
      if (!this.step) {
        setTimeout(() => {
          this.$emit('close');
        }, 5000);
      }
    },
    handleKeyup(e) {
      if (e.key !== 'Escape') return;
      this.dismiss();
    },
    dismiss() {
      this.$refs.dismisser?.dismiss();
      this.$emit('close');
      this.track('survey:mr_experience', {
        label: 'dismiss',
        extra: {
          accountAge: this.accountAge,
        },
      });
      localStorage?.removeItem(MR_RENDER_LS_KEY);
    },
  },
};
</script>

<template>
  <user-callout-dismisser
    ref="dismisser"
    feature-name="mr_experience_survey"
    @queryResult.once="onQueryLoaded"
  >
    <aside
      class="mr-experience-survey-wrapper gl-fixed gl-bottom-0 gl-right-0 gl-p-5"
      :aria-label="$options.i18n.survey"
    >
      <transition name="survey-slide-up">
        <div
          v-if="visible"
          class="mr-experience-survey-body gl-relative gl-display-flex gl-flex-direction-column gl-bg-white gl-p-5 gl-border gl-rounded-base"
        >
          <gl-button
            v-tooltip="$options.i18n.close"
            :aria-label="$options.i18n.close"
            variant="default"
            category="tertiary"
            class="gl-top-4 gl-right-3 gl-absolute"
            icon="close"
            @click="dismiss"
          />
          <div
            v-if="stepIndex === 0"
            class="mr-experience-survey-legal gl-border-t gl-mt-5 gl-pt-3 gl-text-gray-500 gl-font-sm"
            role="note"
          >
            <p class="gl-m-0">
              <gl-sprintf :message="$options.i18n.legal">
                <template #link="{ content }">
                  <a
                    class="gl-text-decoration-underline gl-text-gray-500"
                    href="https://about.gitlab.com/privacy/"
                    target="_blank"
                    rel="noreferrer nofollow"
                    v-text="content"
                  ></a>
                </template>
              </gl-sprintf>
            </p>
          </div>
          <div class="gl-relative">
            <div class="gl-absolute">
              <div
                v-safe-html="$options.gitlabLogo"
                aria-hidden="true"
                class="mr-experience-survey-logo"
              ></div>
            </div>
          </div>
          <section v-if="step">
            <p id="mr_survey_question" ref="question" class="gl-m-0 gl-px-7">
              <gl-sprintf :message="step.question">
                <template #strong="{ content }">
                  <strong>{{ content }}</strong>
                </template>
              </gl-sprintf>
            </p>
            <satisfaction-rate
              aria-labelledby="mr_survey_question"
              class="gl-mt-5"
              @rate="onRate"
            />
          </section>
          <section v-else class="gl-px-7">
            {{ $options.i18n.thanks }}
          </section>
        </div>
      </transition>
    </aside>
  </user-callout-dismisser>
</template>