Welcome to mirror list, hosted at ThFree Co, Russian Federation.

app.vue « components « terms « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 29099bcc366154178a4cc6fb689e5a43ad680824 (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
<script>
import { GlButton, GlIntersectionObserver } from '@gitlab/ui';
import SafeHtml from '~/vue_shared/directives/safe_html';

import { isLoggedIn } from '~/lib/utils/common_utils';
import { __ } from '~/locale';
import csrf from '~/lib/utils/csrf';
import { trackTrialAcceptTerms } from 'ee_else_ce/google_tag_manager';
import { renderGFM } from '~/behaviors/markdown/render_gfm';

export default {
  name: 'TermsApp',
  i18n: {
    accept: __('Accept terms'),
    continue: __('Continue'),
    decline: __('Decline and sign out'),
  },
  flashElements: [],
  csrf,
  directives: {
    SafeHtml,
  },
  components: { GlButton, GlIntersectionObserver },
  inject: ['terms', 'permissions', 'paths'],
  data() {
    return {
      acceptDisabled: true,
      observer: new MutationObserver(() => {
        this.setScrollableViewportHeight();
      }),
    };
  },
  computed: {
    isLoggedIn,
  },
  mounted() {
    this.renderGFM();
    this.setScrollableViewportHeight();
    this.observer.observe(document.body, { childList: true, subtree: true });
  },
  beforeDestroy() {
    this.observer.disconnect();
  },
  methods: {
    renderGFM() {
      renderGFM(this.$refs.gfmContainer);
    },
    handleBottomReached() {
      this.acceptDisabled = false;
    },
    setScrollableViewportHeight() {
      // Reset `max-height` inline style
      this.$refs.scrollableViewport.style.maxHeight = '';

      const { scrollHeight, clientHeight } = document.documentElement;

      // Set `max-height` to 100vh minus all elements that are NOT the scrollable viewport (header, footer, alerts, etc)
      this.$refs.scrollableViewport.style.maxHeight = `calc(100vh - ${
        scrollHeight - clientHeight
      }px)`;
    },
    trackTrialAcceptTerms,
  },
};
</script>

<template>
  <div>
    <div class="gl-relative gl-pb-0 gl-px-0" data-qa-selector="terms_content">
      <div
        class="terms-fade gl-absolute gl-left-5 gl-right-5 gl-bottom-0 gl-h-11 gl-pointer-events-none"
      ></div>
      <div
        ref="scrollableViewport"
        data-testid="scrollable-viewport"
        class="gl-h-100vh gl-overflow-y-auto gl-pb-11 gl-px-5"
      >
        <div ref="gfmContainer" v-safe-html="terms"></div>
        <gl-intersection-observer @appear="handleBottomReached">
          <div></div>
        </gl-intersection-observer>
      </div>
    </div>
    <div v-if="isLoggedIn" class="gl-display-flex gl-justify-content-end gl-p-5">
      <form v-if="permissions.canDecline" method="post" :action="paths.decline">
        <gl-button type="submit">{{ $options.i18n.decline }}</gl-button>
        <input :value="$options.csrf.token" type="hidden" name="authenticity_token" />
      </form>
      <form
        v-if="permissions.canAccept"
        class="gl-ml-3"
        method="post"
        :action="paths.accept"
        @submit="trackTrialAcceptTerms"
      >
        <gl-button
          type="submit"
          variant="confirm"
          :disabled="acceptDisabled"
          data-qa-selector="accept_terms_button"
          >{{ $options.i18n.accept }}</gl-button
        >
        <input :value="$options.csrf.token" type="hidden" name="authenticity_token" />
      </form>
      <gl-button v-else class="gl-ml-3" :href="paths.root" variant="confirm">{{
        $options.i18n.continue
      }}</gl-button>
    </div>
  </div>
</template>