Skip to content

Commit

Permalink
Auto commit
Browse files Browse the repository at this point in the history
  • Loading branch information
walidmahade committed Feb 19, 2024
1 parent 2885db6 commit 594d5f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
12 changes: 6 additions & 6 deletions dist/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,7 @@ const getFormattedSizes = (sizes)=>{
if (!Array.isArray(sizes)) sizes = [
sizes
];
console.log(sizes);
sizes.forEach((item)=>{
console.log(item);
let [key, value] = item.split(":");
let [start, end] = value.split("-").map(Number);
let valAvg = Math.floor((start + end) / 2);
Expand Down Expand Up @@ -945,7 +943,6 @@ $(function() {
const userType = gv(SUBSCRIBER_TYPE_KEY);
const rawPricesPerOperator = $(`[data-type='${SUBSCRIBER_TYPE[userType]}']`);
const sizes = getFormattedSizes(isFamily ? JSON.parse(gv(CHECKBOX_LABELS.subscription_size)) : gv(CHECKBOX_LABELS.subscription_size));
console.log(sizes);
rawPricesPerOperator.each(function(index, el) {
const $el = $(el);
const operatorName = $el.attr("id");
Expand All @@ -958,7 +955,6 @@ $(function() {
});
// sort by price
operatorPrices.sort((a, b)=>a.total - b.total);
console.log(operatorPrices);
// save to session storage
sv("operatorPrices", JSON.stringify(operatorPrices));
submitLeadForm();
Expand Down Expand Up @@ -1072,14 +1068,18 @@ $(function() {
* handle final form submission
*/ function submitLeadForm() {
const $form = $("#lead-form");
const excludedFields = [
"operatorPrices",
NO_LABEL_FOUND
];
const values = sessionStorage;
Object.keys(values).map((key)=>{
if (key === NO_LABEL_FOUND) return;
if (excludedFields.includes(key)) return;
if (Object.values(CHECKBOX_LABELS).includes(key)) {
const arr = getType(values[key]) === "array" ? JSON.parse(values[key]) : [
values[key]
];
const forMattedArr = arr.map((val)=>val.includes(":") ? val + " GB" : val);
const forMattedArr = arr.map((val)=>val?.includes(":") ? val.split(":")[1] + " GB" : val);
$form.append(`<input type="hidden" name="${key}" data-name="${key}" value="${forMattedArr.join(",")}">`);
} else $form.append(`<input type="hidden" name="${key}" data-name="${key}" value="${values[key]}">`);
});
Expand Down
11 changes: 5 additions & 6 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@ const getFormattedSizes = (sizes) => {
if (!Array.isArray(sizes)) {
sizes = [sizes];
}
console.log(sizes);

sizes.forEach((item) => {
console.log(item);
let [key, value] = item.split(":");
let [start, end] = value.split("-").map(Number);
let valAvg = Math.floor((start + end) / 2);
Expand Down Expand Up @@ -407,7 +405,6 @@ $(function () {
const userType = gv(SUBSCRIBER_TYPE_KEY);
const rawPricesPerOperator = $(`[data-type='${SUBSCRIBER_TYPE[userType]}']`);
const sizes = getFormattedSizes(isFamily ? JSON.parse(gv(CHECKBOX_LABELS.subscription_size)) : gv(CHECKBOX_LABELS.subscription_size));
console.log(sizes);

rawPricesPerOperator.each(function (index, el) {
const $el = $(el);
Expand All @@ -422,7 +419,7 @@ $(function () {

// sort by price
operatorPrices.sort((a, b) => a.total - b.total);
console.log(operatorPrices);

// save to session storage
sv("operatorPrices", JSON.stringify(operatorPrices));

Expand Down Expand Up @@ -568,12 +565,14 @@ $(function () {
*/
function submitLeadForm() {
const $form = $("#lead-form");
const excludedFields = ["operatorPrices", NO_LABEL_FOUND];
const values = sessionStorage;

Object.keys(values).map((key) => {
if (key === NO_LABEL_FOUND) return;
if (excludedFields.includes(key)) return;
if (Object.values(CHECKBOX_LABELS).includes(key)) {
const arr = getType(values[key]) === "array" ? JSON.parse(values[key]) : [values[key]];
const forMattedArr = arr.map((val) => (val.includes(":") ? val + " GB" : val));
const forMattedArr = arr.map((val) => (val?.includes(":") ? val.split(":")[1] + " GB" : val));
$form.append(`<input type="hidden" name="${key}" data-name="${key}" value="${forMattedArr.join(",")}">`);
} else $form.append(`<input type="hidden" name="${key}" data-name="${key}" value="${values[key]}">`);
});
Expand Down

0 comments on commit 594d5f0

Please sign in to comment.