Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added automatic hiding functionality for the survey report banner when clicking on the dismiss button #34914

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,51 @@
$(document).ready(function(){
// Function to get user ID
function getUserId() {
return $('#userIdSurvey').val();
}

// Function to get current time in milliseconds
function getCurrentTime() {
return new Date().getTime();
}

// Function to set dismissal time and expiration time in local storage
function setDismissalAndExpirationTime(userId, dismissalTime) {
let expirationTime = dismissalTime + (30 * 24 * 60 * 60 * 1000); // 30 days
localStorage.setItem('bannerDismissalTime_' + userId, dismissalTime);
localStorage.setItem('bannerExpirationTime_' + userId, expirationTime);
}

// Function to check if banner should be shown or hidden
function checkBannerVisibility() {
let userId = getUserId();
let bannerDismissalTime = localStorage.getItem('bannerDismissalTime_' + userId);
let bannerExpirationTime = localStorage.getItem('bannerExpirationTime_' + userId);
let currentTime = getCurrentTime();

if (bannerDismissalTime && bannerExpirationTime && currentTime > bannerExpirationTime) {
// Banner was dismissed and it's not within the expiration period, so show it
$('#originalContent').show();
} else if (bannerDismissalTime && bannerExpirationTime && currentTime < bannerExpirationTime) {
// Banner was dismissed and it's within the expiration period, so hide it
$('#originalContent').hide();
} else {
// Banner has not been dismissed ever so we need to show it.
$('#originalContent').show();
}
}

// Click event for dismiss button
$('#dismissButton').click(function() {
$('#originalContent').slideUp('slow', function() {
// If you want to do something after the slide-up, do it here.
// For example, you can hide the entire div:
// $(this).hide();
let userId = getUserId();
let dismissalTime = getCurrentTime();
setDismissalAndExpirationTime(userId, dismissalTime);
});
});

// Check banner visibility on page load
checkBannerVisibility();
// When the form is submitted
$("#survey_report_form").submit(function(event){
event.preventDefault(); // Prevent the form from submitting traditionally
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% block survey_report_banner %}
{% load static %}
{% if show_survey_report_banner %}
<div id="originalContent" style="border: 3px solid #06405d; margin-bottom: 50px; rgb(0 0 0 / 18%) 0px 3px 5px;">
<div id="originalContent" style="border: 3px solid #06405d; margin-bottom: 50px; rgb(0 0 0 / 18%) 0px 3px 5px; display: none;">
<div style="background-color: #06405d;padding: 17px 37px;">
<h1 style="margin: 0; color: #FFFF; font-weight: 600;">Join the Open edX Data Sharing Initiative and shape the future of learning</h1>
</div>
Expand All @@ -15,6 +15,7 @@ <h1 style="margin: 0; color: #FFFF; font-weight: 600;">Join the Open edX Data Sh
<button id="dismissButton" type="button" style="background-color:var(--close-button-bg); color: var(--button-fg); border: none; border-radius: 4px; padding: 10px 20px; margin-right: 10px; cursor: pointer;">Dismiss</button>
<form id='survey_report_form' method="POST" action="/survey_report/generate_report" style="margin: 0; padding: 0;">
{% csrf_token %}
<input type="hidden" id="userIdSurvey" value="{{ user.id }}">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

everything else being the same, could we change this to use the anonymous ID?
You could easily use

return anonymous_id_for_user(user, None)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felipemontoya: Unless you have a strong objection here, I'm inclined to merge this as-is, so that we can still try to squeeze this into Redwood. Is that okay with you?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I didn't want to leave the sequential ID stored there, but this only happens for a very small subset of users. We can go ahead and merge

<button type="submit" style="background-color: #377D4D; color: var(--button-fg); border: none; border-radius: 4px; padding: 10px 20px; cursor: pointer;">Send Report</button>
</form>
</div>
Expand Down
Loading