const FORWARD_PARAMS = ["utm_source","utm_medium","utm_campaign","utm_term","utm_content","gclid","fbclid"]; const bookingUrl = (cls, isLp = false) => { const qs = new URLSearchParams(); qs.set("classId", cls.id); qs.set("teacher", cls.teacherInfo?.name ?? ""); qs.set("time", cls.classDateTime); if (!isLp) { qs.set("signLabel", "Book a Free Class"); qs.set("packageId", "67ea76adea89798f74a19b4a"); } const here = new URLSearchParams(location.search); FORWARD_PARAMS.forEach((k) => here.has(k) && qs.set(k, here.get(k))); return ("https://app.shvasa.com/book-class?" + qs.toString().replace(/\+/g, "%20")) .replace(/&/g, "&"); }; // SHOW UPCOMING CLASSES // // currentDate const today = new Date(); // All tab links const tabs = document.querySelectorAll(".upcoming-classes-tab-link"); // All tabs container const container = [...document.querySelectorAll(".tab-content-wrapper")]; container.forEach((div) => (div.textContent = "")); // Days Difference Calculate const calcDaysDifference = (date2, date1) => Math.round(Math.abs((date2 - date1) / (1000 * 60 * 60 * 24))); // Tab links setup [...tabs].reduce((acc, link, i) => { // creating current Date const date = new Date(acc); // Get days different const daysDifference = calcDaysDifference(date, today); // Attribute Value const attributeValue = `${date}`.slice(4, 15).split(" ").join("-"); if (daysDifference === 0) { link.textContent = "Today"; } else if (daysDifference === 1) { link.textContent = "Tomorrow"; } else { link.textContent = `${date}`.slice(4, 10).split(" ").reverse().join(" "); } // set data attribution link.setAttribute("data-tab-index", `${attributeValue}`); container[i].setAttribute("data-tabe-pane", `${attributeValue}`); // date for accumulator return date.setDate(date.getDate() + 1); }, `${today}`); let classesData; const nextDay = new Date(); nextDay.setDate(nextDay.getDate() + 1); let selectedDate = `${nextDay}`.slice(4, 15).split(" ").join("-"); console.log(selectedDate); // Fetch classes Data const tillDate = new Date(); tillDate.setDate(tillDate.getDate() + 5); const url = "https://services.shvasa.com/api/product/getGroupClassesForWebflow"; const headers = { "Content-Type": "application/json", }; const body = { fromDate: new Date(), tillDate: tillDate, }; const fetchClassesData = function (selectedDate) { fetch(url, { method: "POST", headers: headers, body: JSON.stringify(body), }) .then((response) => response.json()) .then((data) => { classesData = data.body; //console.log(classesData); showClasses(selectedDate); }) .catch((error) => { console.error("Error fetching class data:", error); }); }; fetchClassesData(selectedDate); // Fetch Classes and display them const showClasses = function (selectedDate) { const tabContainer = document.querySelector( `.tab-content-wrapper[data-tabe-pane = "${selectedDate}"]` ); let html; tabContainer.textContent = ""; classesData ?.filter( (item) => // Filter Date new Date(item.classDateTime).getDate() === new Date(selectedDate).getDate() ) ?.forEach((item, i) => { if (i > 8) return; //update Class details const classDate = new Date(item?.classDateTime); const timeZone = `${classDate}` .slice(`${classDate}`.indexOf("(") + 1) .split(" ") .map((value) => value.at(0)) .join(""); const hours = `${classDate.getHours()}`.padStart(2, 0); const minutes = `${classDate.getMinutes()}`.padEnd(2, 0); // HTML Card html = `