Skip to content

Commit

Permalink
Removed jquery and updated required email address
Browse files Browse the repository at this point in the history
  • Loading branch information
dedanade authored Apr 27, 2021
1 parent ea28d36 commit e3f1620
Showing 1 changed file with 39 additions and 36 deletions.
75 changes: 39 additions & 36 deletions embed-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,22 @@ if (onePriceQty > 0) {
justify_delivery_info.style.display = "none";
const input = container.querySelector("input");
input.setAttribute("required", "");
$("#show_Product_Quantity").on("keyup click", function () {
const tot = $("#product_price_hidden").val() * this.value;

function showPriceString(e) {
const inputValue = e.target.value;
const tot =
document.getElementById("product_price_hidden").value * inputValue;
const total = `That's ₦${tot.toLocaleString()}`;
$("#show_Product_total").val(total);
document.getElementById("show_Product_total").value = total;
}

const showProductQTY = document.getElementById("show_Product_Quantity");

showProductQTY.addEventListener("keyup", (e) => {
showPriceString(e);
});
showProductQTY.addEventListener("click", (e) => {
showPriceString(e);
});
} else {
const newVariantPrice = document.getElementById("product-variant-price")
Expand Down Expand Up @@ -38,7 +50,6 @@ if (onePriceQty > 0) {
const locPromoPriceValue = parseInt(promoPriceValue);
const deliveryTotalInfo = document.getElementById("show_total_price");
deliveryTotalInfo.innerHTML = `₦${locPromoPriceValue.toLocaleString()}`;
// console.log(locPromoPriceValue);
});
}

Expand Down Expand Up @@ -89,24 +100,21 @@ if (creaEmbedOrderForm)
creaEmbedOrderForm.addEventListener("submit", (e) => {
e.preventDefault();
const submitButton = creaEmbedOrderForm.querySelector('[type="submit"]');
const email = (document.getElementById("embedEmail") || {}).value;
const name = (document.getElementById("embedName") || {}).value;
const address = (document.getElementById("embedAddress") || {}).value;
const state = (document.getElementById("embedState") || {}).value;
const area = (document.getElementById("embedArea") || {}).value;
const phone = (document.getElementById("embedPhone") || {}).value;
const altPhone = (document.getElementById("embedPhone2") || {}).value;
const qty = (document.getElementById("embedQty") || {}).value;
const size = (selectSizes.options[selectSizes.selectedIndex] || {}).value;
const colour = (selectColours.options[selectColours.selectedIndex] || {})
const submitButtonText = document.getElementById("submitButtonText").value;
const email = document.getElementById("embedEmail").value;
const name = document.getElementById("embedName").value;
const address = document.getElementById("embedAddress").value;
const state = document.getElementById("embedState").value;
const area = document.getElementById("embedArea").value;
const phone = document.getElementById("embedPhone").value;
const altPhone = document.getElementById("embedPhone2").value;
const size = selectSizes.options[selectSizes.selectedIndex].value;
const colour = selectColours.options[selectColours.selectedIndex].value;
const product = document.getElementById("embedProduct").value;
const businessAccount = document.getElementById("embedBusinessAccount")
.value;
const product = (document.getElementById("embedProduct") || {}).value;
const businessAccount = (
document.getElementById("embedBusinessAccount") || {}
).value;

const onePriceQty = (document.getElementById("product_price_hidden") || {})
.value;
const onePriceQty = document.getElementById("product_price_hidden").value;

if (onePriceQty > 0) {
var productEmbedQty = document.getElementById("show_Product_Quantity")
Expand All @@ -124,13 +132,8 @@ if (creaEmbedOrderForm)
const total = productQtyValue.split("= ₦")[1];
var productEmbedTotal = parseInt(total);
}

submitButton.classList.add("btnLoadingSpiner");
submitButton.disabled = true;
setTimeout(() => {
submitButton.classList.remove("btnLoadingSpiner"),
(submitButton.disabled = false);
}, 200000);
console.log(submitButtonText);
submitButton.innerHTML = "Processing Order...";
createOrderAPI(
businessAccount,
product,
Expand All @@ -145,15 +148,11 @@ if (creaEmbedOrderForm)
productEmbedTotal,
colour,
size,
submitButton
submitButton,
submitButtonText
);
});

const stopLoadingBtnSpinner = (submitButton) => {
submitButton.classList.remove("btnLoadingSpiner");
submitButton.disabled = false;
};

const createOrderAPI = async (
businessAccount,
product,
Expand All @@ -168,7 +167,8 @@ const createOrderAPI = async (
total,
colour,
size,
submitButton
submitButton,
submitButtonText
) => {
try {
const res = await axios({
Expand Down Expand Up @@ -209,9 +209,12 @@ const createOrderAPI = async (
}
}
} catch (err) {
stopLoadingBtnSpinner(submitButton);
submitButton.innerHTML = submitButtonText;

if (err.response) {
alert(err.response.data.message);
} else alert(`Unable to create this order, kindly retry. Thanks`);
console.log(err.response.data.message);
} else console.log(err);
alert(`Unable to create this order, kindly retry. Thanks`);
}
};

0 comments on commit e3f1620

Please sign in to comment.