development #10

Merged
DaviKlein merged 18 commits from development into main 2022-12-19 02:48:45 +00:00
4 changed files with 419 additions and 26 deletions
Showing only changes of commit 6bf66ea9c0 - Show all commits

View File

@ -31,10 +31,7 @@ export default class CheckoutUI {
toggleFooterDropdown(event) {
event.target.classList.toggle("closed");
event.target.nextElementSibling.classList.toggle(
"dropdown__content--closed"
);
event.target.nextElementSibling.classList.toggle("dropdown__content--closed");
}
init() {
@ -56,14 +53,7 @@ export default class CheckoutUI {
resizeImages() {
$(".product-image img").each((i, el) => {
const $el = $(el);
$el.attr(
"src",
alterarTamanhoImagemSrcVtex(
$el.attr("src"),
this.width,
this.height
)
);
$el.attr("src", alterarTamanhoImagemSrcVtex($el.attr("src"), this.width, this.height));
});
}
}

View File

@ -7,34 +7,276 @@ export default class Footer {
async init() {
await this.selectors();
// this.onUpdate();
this.events();
this.onUpdate();
this.createPaymentsIcons();
this.createVtexpciIcon();
this.createDevIcons();
// await this.addCarrossel();
}
events() {
window.addEventListener("hashchange", () => {
this.onUpdate();
if (window.location.hash != "#/cart") {
if (document.querySelector(".footerTitle") != null) {
document.querySelector(".footerTitle").style.display = "none";
}
this.cartTitle.style.display = "none";
}
if (window.location.hash == "#/cart" && this.checkoutVazio.style.display == "none") {
if (document.querySelector(".footerTitle") != null) {
document.querySelector(".footerTitle").style.display = "block";
}
this.cartTitle.style.display = "block";
}
console.log("HASHCHANGE FOOTER");
if (window.location.hash == "#/cart" && this.checkoutVazio.style.display == "none") {
this.list.style.display = "flex";
}
if (window.location.hash != "#/cart") {
this.list.style.display = "none";
}
});
addEventListener("resize", () => {
this.addCarrossel();
});
}
async selectors() {
//Para verificar se o carrinho está vazio e remover a prateleira de produtos:
// vocês devem olhar a doc fornecida no Desafio para aprender a usar o waitElement
this.list = await waitElement(".footerCheckout__prateleira", {
timeout: 5000,
interval: 1000,
});
// this.slick = await waitElement(".slick-test");
// this.footerTitle = await waitElement(".footerTitle", {
// timeout: 5000,
// interval: 1000,
// });
this.allList = await waitElement(".footerCheckout");
this.checkoutVazio = await waitElement(".empty-cart-content");
this.payments = await waitElement(".footerCheckout__payments");
this.vtexpci = await waitElement(".footerCheckout__vtexpci");
this.devIncons = await waitElement(".footerCheckout__developedBy");
this.listaPrateleira = await waitElement(".footerCheckout__prateleira");
this.cartTitle = await waitElement("#cart-title");
}
onUpdate() {
//Função qeu fará a verificação se o carrinho está vazio para remover a prateleira de produtos:
// vocês devem olhar a doc fornecida no Desafio para aprender a usar a MutationObserver
// sempre que o carrinho estiver vazio o elemento chcekoutVazio fica display: none e isso pode ser usado como atributo para a MutationObserver
let target = this.checkoutVazio;
let lista = this.list;
let cartTitle = this.cartTitle;
console.log("title:", cartTitle);
if (target.style.display == "none" && window.location.hash == "#/cart") {
lista.style.display = "flex";
cartTitle.style.display = "block";
if (!this.list.classList.contains("fetch")) {
console.log("PRIMEIRO NAO TEM FETCH");
this.fetchApiData();
}
} else {
lista.style.display = "none";
cartTitle.style.display = "none";
}
let config = { childList: true, attributes: true };
let observer = new MutationObserver((mutations) => {
mutations.forEach(function (mutation) {
console.log(mutation.type);
});
if (window.location.hash == "#/cart") {
console.log("listairai", this.list.classList);
if (!lista.classList.contains("fetch")) {
console.log("SEGUNDO NAO TEM FETCH");
this.fetchApiData();
}
mutations.forEach(function (mutation) {
if (target.style.display != "none") {
if (document.querySelector(".footerTitle") != null) {
document.querySelector(".footerTitle").style.display = "none";
}
cartTitle.style.display = "none";
lista.style.display = "none";
} else {
if (document.querySelector(".footerTitle") != null) {
document.querySelector(".footerTitle").style.display = "block";
}
lista.style.display = "flex";
cartTitle.style.display = "block";
}
console.log(mutation.type);
});
}
});
observer.observe(target, config);
}
async addCarrossel() {
const elemento = await waitElement("#my-element");
$(elemento).slick({
slidesToShow: 4,
slidesToScroll: 1,
});
console.log("start slick");
const elemento = await waitElement(".slick-test");
if ($(elemento).hasClass("slick-initialized")) {
$(elemento).slick("unslick");
}
if (window.innerWidth > 1024) {
$(elemento).not(".slick-initialized").slick({
slidesToShow: 4,
slidesToScroll: 1,
});
} else if (window.innerWidth > 375) {
$(elemento).not(".slick-initialized").slick({
slidesToShow: 3,
slidesToScroll: 1,
});
} else if (window.innerWidth <= 375) {
$(elemento).not(".slick-initialized").slick({
slidesToShow: 2,
slidesToScroll: 1,
});
}
console.log("end slick");
}
fetchApiData() {
console.log("COMEÇO FETCH");
fetch(
"https://m3academy.myvtex.com/api/catalog_system/pub/products/search/?fq=productClusterIds:319"
)
.then((response) => response.json())
.then((data) => {
console.log(data);
const ul = document.createElement("ul");
ul.classList.add("slick-test");
this.list.appendChild(ul);
const footerCheckout = document.querySelector(".footerCheckout");
const footerTitle = document.createElement("p");
footerTitle.classList.add("footerTitle");
footerTitle.innerText = "Você também pode gostar:";
footerCheckout.insertBefore(footerTitle, this.list);
data.map((item) => {
let colors = "";
for (let i = 0; i < item.items.length; i++) {
console.log(colors);
colors += `<p>${item.items[i].name}</p>`;
}
const li = document.createElement("li");
li.setAttribute("name", item.itemId);
li.classList.add("itemList");
li.innerHTML = `<img class="productImg" src="${item.items[0].images[0].imageUrl}">
<p class="productName">${item.productName}</p>
<div class="itemSku">
${colors}
</div>
<a class="productLink" type="button" href="${item.link}">VER PRODUTO</a>`;
console.log(item.productName, colors);
console.log("adiciona li");
ul.appendChild(li);
this.list.classList.add("fetch");
console.log(this.list);
ul.style.width = "100%";
});
})
.then(() => {
this.addCarrossel();
});
console.log("FIM FETCH");
}
createPaymentsIcons() {
this.payments.innerHTML = `
<ul class="payments-icons-wrapper">
<li>
<figure>
<img
src="https://agenciamagma.vteximg.com.br/arquivos/masterCardM3Academy.png"
alt=""
/>
</figure>
</li>
<li>
<figure>
<img
src="https://agenciamagma.vteximg.com.br/arquivos/visaM3Academy.png"
alt=""
/>
</figure>
</li>
<li>
<figure>
<img
src="https://agenciamagma.vteximg.com.br/arquivos/amexM3Academy.png"
alt=""
/>
</figure>
</li>
<li>
<figure>
<img
src="https://agenciamagma.vteximg.com.br/arquivos/eloM3Academy.png"
alt=""
/>
</figure>
</li>
<li>
<figure>
<img
src="https://agenciamagma.vteximg.com.br/arquivos/hiperCardM3Academy.png"
alt=""
/>
</figure>
</li>
<li>
<figure>
<img
src="https://agenciamagma.vteximg.com.br/arquivos/payPalM3Academy.png"
alt=""
/>
</figure>
</li>
<li>
<figure>
<img
src="https://agenciamagma.vteximg.com.br/arquivos/boletoM3Academy.png"
alt=""
/>
</figure>
</li>
</ul>
`;
}
createVtexpciIcon() {
this.vtexpci.innerHTML = `
<figure class="vtex-icon">
<img
src="https://agenciamagma.vteximg.com.br/arquivos/vtexPCIM3Academy.png"
alt=""
/>
</figure>
`;
}
createDevIcons() {
this.devIncons.innerHTML = `
<li>
<a href="https://vtex.com/br-pt/">
<span>Powered By</span>
<figure>
<img class="vtex-icon" src="https://agenciamagma.vteximg.com.br/arquivos/logoVTEXM3Academy.png" alt="">
</figure>
</a>
</li>
<li>
<a href="https://agenciam3.com/">
<span>Developed By</span>
<figure>
<img class="m3-icon" src="https://agenciamagma.vteximg.com.br/arquivos/logoM3M3Academy.png" alt="">
</figure>
</a>
</li>
`;
}
}

View File

@ -8,14 +8,174 @@ export default class Header {
async init() {
await this.selectors();
console.log(this.item);
this.events();
this.createProgressBar();
await this.progressBarProgress();
}
async selectors() {
this.item = await waitElement("#my-element", {
this.item = await waitElement("#progressBar", {
//#my-element pode ser a class ou o id do elemento html qeu vocÊ quer pegar
timeout: 5000, // vai esperar 5 segundos antes de rejeitar a promise
interval: 1000, // vai verificar a cada 1 segundo se o elemento existe
});
this.header = await waitElement(".headerCheckout");
this.progressBar = await waitElement("#progressBar");
}
events() {
addEventListener("resize", () => {
this.createProgressBar();
this.progressBarProgress();
});
}
createProgressBar() {
if (this.progressBar && window.innerWidth > 1024) {
this.progressBar.innerHTML = `
<ul class="">
<li>
<div class="containerLi">
<div>
<p class="progress-bar-text">Meu Carrinho</p>
<p id="progress-bar-circle-1" class="progress-bar-circle-1"></p>
<p class="progress-bar-line-1"></p>
</div>
</div>
</li>
<li class="central">
<div class="containerLi">
<div>
<p class="progress-bar-text">Dados Pessoais</p>
<p id="progress-bar-circle-2" class="progress-bar-circle-2"></p>
</div>
</div>
</li>
<li>
<div class="containerLi">
<div>
<p class="progress-bar-text">Pagamento</p>
<p id="progress-bar-circle-3" class="progress-bar-circle-3"></p>
<p class="progress-bar-line-2"></p>
</div>
</div>
</li>
</ul>
`;
}
if (this.progressBar && window.innerWidth <= 1024) {
this.progressBar.innerHTML = ``;
}
}
async progressBarProgress() {
this.circle1 = await waitElement(".progress-bar-circle-1");
this.circle2 = await waitElement(".progress-bar-circle-2");
this.circle3 = await waitElement(".progress-bar-circle-3");
if (this.progressBar && window.innerWidth > 1024) {
const progressBarList = document.querySelectorAll("#progressBar ul li");
progressBarList.forEach((li) => {
if (window.location.href === "https://m3academy.myvtex.com/checkout/#/cart") {
if (this.circle1) {
this.circle1.classList.add("active");
}
if (this.circle2) {
if (this.circle2.classList.contains("active")) {
this.circle2.classList.remove("active");
}
}
if (this.circle3) {
if (this.circle3.classList.contains("active")) {
this.circle3.classList.remove("active");
}
}
} else if (
window.location.href === "https://m3academy.myvtex.com/checkout/#/email" ||
window.location.href === "https://m3academy.myvtex.com/checkout/#/profile" ||
window.location.href === "https://m3academy.myvtex.com/checkout/#/shipping"
) {
if (this.circle1) {
if (this.circle1.classList.contains("active")) {
this.circle1.classList.remove("active");
}
console.log("email shipping");
console.log(this.circle1);
if (this.circle2) {
this.circle2.classList.add("active");
console.log("teste dados");
}
console.log(this.circle2);
console.log(this.circle3);
if (this.circle3) {
if (this.circle3.classList.contains("active")) {
this.circle3.classList.remove("active");
}
}
}
} else if (
window.location.href === "https://m3academy.myvtex.com/checkout/#/payment"
) {
if (this.circle1) {
if (this.circle1.classList.contains("active")) {
this.circle1.classList.remove("active");
}
}
if (this.circle2) {
if (this.circle2.classList.contains("active")) {
this.circle2.classList.remove("active");
}
}
if (this.circle3) {
this.circle3.classList.add("active");
}
}
window.addEventListener("hashchange", () => {
if (window.location.hash == "#/cart") {
if (this.circle1) {
this.circle1.classList.add("active");
}
if (this.circle2) {
if (this.circle2.classList.contains("active")) {
this.circle2.classList.remove("active");
}
}
if (this.circle3) {
if (this.circle3.classList.contains("active")) {
this.circle3.classList.remove("active");
}
}
} else if (
window.location.hash == "#/email" ||
window.location.hash == "#/profile" ||
window.location.hash == "#/shipping"
) {
if (this.circle1) {
if (this.circle1.classList.contains("active")) {
this.circle1.classList.remove("active");
}
}
if (this.circle2) {
this.circle2.classList.add("active");
}
if (this.circle3) {
if (this.circle3.classList.contains("active")) {
this.circle3.classList.remove("active");
}
}
} else if (window.location.hash == "#/payment") {
if (this.circle1) {
if (this.circle1.classList.contains("active")) {
this.circle1.classList.remove("active");
}
}
if (this.circle2) {
if (this.circle2.classList.contains("active")) {
this.circle2.classList.remove("active");
}
}
if (this.circle3) {
this.circle3.classList.add("active");
}
}
});
});
}
}
}

View File

@ -2,4 +2,5 @@
@import "./lib/slick";
@import "./partials/header";
@import "./partials/footer";
@import "./partials/prateleira.scss";
@import "./checkout/checkout.scss";