debian-mirror-gitlab/app/assets/javascripts/terms/components/app.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

111 lines
3.3 KiB
Vue
Raw Normal View History

2021-12-11 22:18:48 +05:30
<script>
2023-03-04 22:38:38 +05:30
import { GlButton, GlIntersectionObserver } from '@gitlab/ui';
import SafeHtml from '~/vue_shared/directives/safe_html';
2021-12-11 22:18:48 +05:30
import { isLoggedIn } from '~/lib/utils/common_utils';
import { __ } from '~/locale';
import csrf from '~/lib/utils/csrf';
2022-08-13 15:12:31 +05:30
import { trackTrialAcceptTerms } from '~/google_tag_manager';
2023-03-04 22:38:38 +05:30
import { renderGFM } from '~/behaviors/markdown/render_gfm';
2021-12-11 22:18:48 +05:30
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,
2023-04-23 21:23:45 +05:30
observer: new MutationObserver(() => {
this.setScrollableViewportHeight();
}),
2021-12-11 22:18:48 +05:30
};
},
computed: {
isLoggedIn,
},
mounted() {
this.renderGFM();
this.setScrollableViewportHeight();
2023-04-23 21:23:45 +05:30
this.observer.observe(document.body, { childList: true, subtree: true });
2021-12-11 22:18:48 +05:30
},
beforeDestroy() {
2023-04-23 21:23:45 +05:30
this.observer.disconnect();
2021-12-11 22:18:48 +05:30
},
methods: {
renderGFM() {
2023-03-04 22:38:38 +05:30
renderGFM(this.$refs.gfmContainer);
2021-12-11 22:18:48 +05:30
},
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)`;
},
2022-08-13 15:12:31 +05:30
trackTrialAcceptTerms,
2021-12-11 22:18:48 +05:30
},
};
</script>
<template>
<div>
2023-03-04 22:38:38 +05:30
<div class="gl-relative gl-pb-0 gl-px-0" data-qa-selector="terms_content">
2021-12-11 22:18:48 +05:30
<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>
2023-04-23 21:23:45 +05:30
<div v-if="isLoggedIn" class="gl-display-flex gl-justify-content-end gl-p-5">
2021-12-11 22:18:48 +05:30
<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>
2022-08-13 15:12:31 +05:30
<form
v-if="permissions.canAccept"
class="gl-ml-3"
method="post"
:action="paths.accept"
@submit="trackTrialAcceptTerms"
>
2021-12-11 22:18:48 +05:30
<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>