From 1001f1fe0e2ae2bcbf1bfbbbf0f160082beaded3 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Fri, 15 Nov 2024 15:45:48 +0530 Subject: [PATCH] fix: added trial banner in desk --- frappe/hooks.py | 1 + frappe/public/js/billing.bundle.js | 96 ++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 frappe/public/js/billing.bundle.js diff --git a/frappe/hooks.py b/frappe/hooks.py index fa709fdb96..8c50c93aef 100644 --- a/frappe/hooks.py +++ b/frappe/hooks.py @@ -27,6 +27,7 @@ app_include_js = [ "controls.bundle.js", "report.bundle.js", "telemetry.bundle.js", + "billing.bundle.js", ] app_include_css = [ diff --git a/frappe/public/js/billing.bundle.js b/frappe/public/js/billing.bundle.js new file mode 100644 index 0000000000..68beefba15 --- /dev/null +++ b/frappe/public/js/billing.bundle.js @@ -0,0 +1,96 @@ +$(document).ready(function () { + if ( + frappe.boot.fc_communication_secret && + frappe.boot.setup_complete === 1 && + !frappe.is_mobile() && + frappe.user.has_role("System Manager") + ) { + frappe.call({ + method: "frappe.integrations.frappe_providers.frappecloud_billing.current_site_info", + callback: (r) => { + const response = r.message; + if (response.trial_end_date) { + $(".layout-main-section").before( + generateTrialSubscriptionBanner(response.trial_end_date) + ); + } + }, + }); + } +}); + +function generateTrialSubscriptionBanner(trialEndDate) { + const trial_end_date = new Date(trialEndDate); + const today = new Date(); + const diffTime = trial_end_date - today; + const trial_end_days = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); + const trial_end_string = + trial_end_days > 1 ? `${trial_end_days} days` : `${trial_end_days} day`; + + return $(` + + +`); +}