Skip to content

Commit

Permalink
Merge pull request JetBrains#4169 from JetBrains/fix-issues
Browse files Browse the repository at this point in the history
Add Core API form feedback
  • Loading branch information
zoobestik authored May 3, 2024
2 parents 8bb0764 + a7dce18 commit eae2ad2
Show file tree
Hide file tree
Showing 5 changed files with 1,794 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ object StdlibPrepareDokkaTemplates: BuildType({
param("env.ALGOLIA_INDEX_NAME", "api-core")
param("env.DOKKA_NOINDEX", "true")
param("env.DOKKA_CUSTOM_BODY", "core-api")
param("env.DOKKA_FEEDBACK", "true")
}
})
65 changes: 65 additions & 0 deletions dokka-templates/base.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@
</div>
<div id="main">
<@content/>
<#if "${process.env.DOKKA_FEEDBACK}" == "true">
<div class="feedback-wrapper">
<div class="feedback">
<div class="feedback__block" data-test="feedback-left"><p class="feedback__text">Thanks for your feedback!</p></div>
<div class="feedback__block feedback__block--active" data-test="feedback">
<div class="wt-row wt-row_size_xs wt-row_wide wt-row_wrap wt-row_justify_start">
<div class="wt-col-inline feedback__text">Was this page helpful?</div>
<div class="wt-col-inline">
<button data-test="feedback-yes" type="button" class="_main_joawza_17 _modeOutline_joawza_356 _sizeS_joawza_92 _alignIconLeft_joawza_77 feedback__button">Yes</button>
<button data-test="feedback-no" type="button" class="_main_joawza_17 _modeOutline_joawza_356 _sizeS_joawza_92 _alignIconLeft_joawza_77 feedback__button">No</button>
</div>
</div>
</div>
</div>
</div>
</#if>
<@footer.display/>
</div>
</div>
Expand All @@ -49,5 +65,54 @@
<script defer src="/_assets/dokka-template.js" type="text/javascript"></script>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','GTM-5P98');</script>
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5P98" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<#if "${process.env.DOKKA_FEEDBACK}" == "true">
<div class="feedback__popup-wrapper app-feedback-popup app-feedback-popup_close">
<div class="feedback__popup feedback__popup--theme-light" data-test="feedback-popup">
<form autocomplete="on">
<div class="feedback__head feedback__head--theme-light" data-test="feedback-head">
<legend class="feedback__legend">How can we improve?</legend>
<div class="feedback__close-button">
<button data-test="feedback-close" aria-label="Close" title="Close" type="button" class="_main_joawza_17 _modeClear_joawza_434 _sizeS_joawza_92 _alignIconLeft_joawza_77 _withIcon_joawza_119 _withoutText_joawza_113">
<svg viewBox="0 0 24 24" class="wt-icon wt-icon_size_s _icon_joawza_525">
<path d="M19.707 5.707l-1.414-1.414L12 10.586 5.707 4.293 4.293 5.707 10.586 12l-6.293 6.293 1.414 1.414L12 13.414l6.293 6.293 1.414-1.414L13.414 12l6.293-6.293z"></path>
</svg>
</button>
</div>
</div>
<div class="feedback__field"><label class="_labelWrapper_hvg13z_44 _sizeM_hvg13z_98" data-test="textarea">
<div class="_wrapper_hvg13z_48">
<textarea name="content" placeholder="Tell us what you think would make this page better" data-test-id="feedback-textarea" title="Content" class="_inner_hvg13z_61" aria-invalid="false" data-test="textarea__input" style="height: 112px !important;"></textarea>
</div>
</label></div>
<div class="feedback__field"><div class="feedback__description feedback__description--theme-light">
Enter your name and email address if you would like to receive a&nbsp;follow-up message or&nbsp;<a class="link"
data-test="feedback-support-link" href="https://kotl.in/issue"
rel="noreferrer" target="_blank">contact our support</a>.</div></div>
<div class="feedback__field">
<div class="_container_1fowpgw_10 _container_1fowpgw_10 _classic_1fowpgw_44 _sizeM_1fowpgw_125 _enabled_1fowpgw_27" data-test="input"><label>
<div class="_wrapper_1fowpgw_14"><div class="_field_1fowpgw_161">
<input name="name" data-test="input__inner" autocomplete="name" title="Name" class="_inner_1fowpgw_171" type="text" placeholder="Name" aria-invalid="false" value=""></div>
</div>
</label></div>
</div>
<div class="feedback__field">
<div class="_container_1fowpgw_10 _container_1fowpgw_10 _classic_1fowpgw_44 _sizeM_1fowpgw_125 _enabled_1fowpgw_27" data-test="input"><label>
<div class="_wrapper_1fowpgw_14"><div class="_field_1fowpgw_161">
<input name="email" data-test-id="feedback-email" data-test="input__inner" title="Email address" class="_inner_1fowpgw_171" type="email" placeholder="Email address" aria-invalid="false" value="">
</div></div>
</label></div>
</div>
<div class="feedback__field feedback__description feedback__description--theme-light" data-test="feedback-policy">
By submitting this form, I agree that JetBrains s.r.o. ("JetBrains") may use my name, email address, phone number, and country of residence to provide support. I agree that JetBrains may process said data using <a href="https://www.jetbrains.com/legal/privacy/third-parties.html"
target="_blank">third-party services</a> for this purpose in accordance with the <a
href="https://www.jetbrains.com/company/privacy.html" target="_blank">JetBrains Privacy Policy</a>.
</div>
<div class="feedback__footer">
<button data-test="feedback-send" title="Send feedback" name="send" type="submit" disabled="disabled" class="_main_joawza_17 _modeClassic_joawza_135 _sizeM_joawza_99 _alignIconLeft_joawza_77 _disabled_joawza_61 button_disabled">Send feedback</button>
</div>
</form>
</div>
</div>
</#if>
</body>
</html>
90 changes: 90 additions & 0 deletions static/js/page/dokka-template/feedback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
function closePopup() {
document.querySelector('.app-feedback-popup').classList.add('app-feedback-popup_close');
}

function showThanks() {
document.querySelector('.feedback__block--active').classList.remove('feedback__block--active');
document.querySelector('[data-test="feedback-left"]').classList.add('feedback__block--active');
}

function toggleEmail(val) {
const email = document.querySelector('[data-test-id="feedback-email"]');
email.setAttribute('aria-invalid', String(!val));

const classes = email.parentNode.parentNode.parentNode.parentNode.classList;
classes.toggle('_error_1fowpgw_83', !val);
classes.toggle('input_error', !val);
}

function toggleSubmit(val) {
const submit = document.querySelector('[data-test="feedback-send"]');
submit.toggleAttribute('disabled', !val);

const classes = submit.classList;
classes.toggle('_disabled_joawza_61', !val);
classes.toggle('button_disabled', !val);
}

export function initFeedback() {
const feedback = document.querySelector('.feedback');

if (feedback) {
feedback.querySelector('[data-test="feedback-yes"]').addEventListener('click', function(e) {
e.preventDefault();
closePopup();
showThanks();
});

feedback.querySelector('[data-test="feedback-no"]').addEventListener('click', function(e) {
e.preventDefault();
document.querySelector('.app-feedback-popup').classList.remove('app-feedback-popup_close');
});
}

const form = document.querySelector('.app-feedback-popup form');

if (form) {
const fields = form.elements;

form.querySelector('[data-test="feedback-close"]').addEventListener('click', function(e) {
e.preventDefault();
closePopup();
});

form.addEventListener('input', function() {
const emailValid = fields.email.value === '' || fields.email.validity.valid;

toggleEmail(emailValid);
toggleSubmit(fields.content.value !== '' && emailValid);
});

form.addEventListener('submit', function(e) {
e.preventDefault();

const content= document.getElementById('content');
const articleId = content && content.getAttribute('pageids');
const titleNode = document.querySelector('h1.cover');
const title = titleNode && titleNode.textContent;

window.fetch('https://forms-service.jetbrains.com/feedback', {
method: 'POST',
mode: 'cors',
credentials: 'omit',
headers: {
'content-type': 'application/json',
},
body: JSON.stringify({
content: fields.content.value || '',
name: fields.name.value || '',
email: fields.email.value || '',
url: document.location.href || '',
articleId: articleId || 'core-api',
title: title || 'Core API: Untitled'
})
});

showThanks();
closePopup();
});
}
}
Loading

0 comments on commit eae2ad2

Please sign in to comment.