From a054423233e0e8569c008b9f532aa24bf48f5cb2 Mon Sep 17 00:00:00 2001 From: Abrasimov Yaroslav Date: Wed, 4 Dec 2024 18:58:43 +0100 Subject: [PATCH] Fix eslint errors --- blocks/header/renderAuthDropdown.js | 65 ++++++++++++++--------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/blocks/header/renderAuthDropdown.js b/blocks/header/renderAuthDropdown.js index 8a1ce3d1f..6b458a0b9 100644 --- a/blocks/header/renderAuthDropdown.js +++ b/blocks/header/renderAuthDropdown.js @@ -1,10 +1,10 @@ /* eslint-disable import/prefer-default-export */ -import * as authApi from "@dropins/storefront-auth/api.js"; -import { render as authRenderer } from "@dropins/storefront-auth/render.js"; -import { SignIn } from "@dropins/storefront-auth/containers/SignIn.js"; -import { events } from "@dropins/tools/event-bus.js"; -import { getCookie } from "../../scripts/configs.js"; -import { CUSTOMER_FORGOTPASSWORD_PATH } from "../../scripts/constants.js"; +import * as authApi from '@dropins/storefront-auth/api.js'; +import { render as authRenderer } from '@dropins/storefront-auth/render.js'; +import { SignIn } from '@dropins/storefront-auth/containers/SignIn.js'; +import { events } from '@dropins/tools/event-bus.js'; +import { getCookie } from '../../scripts/configs.js'; +import { CUSTOMER_FORGOTPASSWORD_PATH } from '../../scripts/constants.js'; function checkAndRedirect(redirections) { Object.entries(redirections).some(([currentPath, redirectPath]) => { @@ -19,7 +19,7 @@ function checkAndRedirect(redirections) { function renderSignIn(element) { authRenderer.render(SignIn, { onSuccessCallback: () => {}, - formSize: "small", + formSize: 'small', routeForgotPassword: () => CUSTOMER_FORGOTPASSWORD_PATH, })(element); } @@ -42,32 +42,31 @@ export function renderAuthDropdown(navTools) { navTools.append(dropdownElement); - const authDropDownPanel = navTools.querySelector(".nav-auth-menu-panel"); + const authDropDownPanel = navTools.querySelector('.nav-auth-menu-panel'); const authDropDownMenuList = navTools.querySelector( - ".authenticated-user-menu" + '.authenticated-user-menu', ); - const authDropinContainer = navTools.querySelector("#auth-dropin-container"); - const loginButton = navTools.querySelector(".nav-dropdown-button"); + const authDropinContainer = navTools.querySelector('#auth-dropin-container'); + const loginButton = navTools.querySelector('.nav-dropdown-button'); const logoutButtonElement = navTools.querySelector( - ".authenticated-user-menu > li > button" + '.authenticated-user-menu > li > button', ); - authDropDownPanel.addEventListener("click", (e) => e.stopPropagation()); + authDropDownPanel.addEventListener('click', (e) => e.stopPropagation()); async function toggleDropDownAuthMenu(state) { - const show = - state ?? !authDropDownPanel.classList.contains("nav-tools-panel--show"); - - authDropDownPanel.classList.toggle("nav-tools-panel--show", show); - authDropDownPanel.setAttribute("role", "dialog"); - authDropDownPanel.setAttribute("aria-hidden", "false"); - authDropDownPanel.setAttribute("aria-labelledby", "modal-title"); - authDropDownPanel.setAttribute("aria-describedby", "modal-description"); + const show = state ?? !authDropDownPanel.classList.contains('nav-tools-panel--show'); + + authDropDownPanel.classList.toggle('nav-tools-panel--show', show); + authDropDownPanel.setAttribute('role', 'dialog'); + authDropDownPanel.setAttribute('aria-hidden', 'false'); + authDropDownPanel.setAttribute('aria-labelledby', 'modal-title'); + authDropDownPanel.setAttribute('aria-describedby', 'modal-description'); authDropDownPanel.focus(); } - loginButton.addEventListener("click", () => toggleDropDownAuthMenu()); - document.addEventListener("click", async (e) => { + loginButton.addEventListener('click', () => toggleDropDownAuthMenu()); + document.addEventListener('click', async (e) => { const clickOnDropDownPanel = authDropDownPanel.contains(e.target); const clickOnLoginButton = loginButton.contains(e.target); @@ -76,27 +75,27 @@ export function renderAuthDropdown(navTools) { } }); - logoutButtonElement.addEventListener("click", async () => { + logoutButtonElement.addEventListener('click', async () => { await authApi.revokeCustomerToken(); checkAndRedirect({ - "/customer": "/customer/login", - "/order-details": "/", + '/customer': '/customer/login', + '/order-details': '/', }); }); renderSignIn(authDropinContainer); const updateDropDownUI = (isAuthenticated) => { - const getUserTokenCookie = getCookie("auth_dropin_user_token"); - const getUserNameCookie = getCookie("auth_dropin_firstname"); + const getUserTokenCookie = getCookie('auth_dropin_user_token'); + const getUserNameCookie = getCookie('auth_dropin_firstname'); if (isAuthenticated || getUserTokenCookie) { - authDropDownMenuList.style.display = "block"; - authDropinContainer.style.display = "none"; + authDropDownMenuList.style.display = 'block'; + authDropinContainer.style.display = 'none'; loginButton.textContent = `Hi, ${getUserNameCookie}`; } else { - authDropDownMenuList.style.display = "none"; - authDropinContainer.style.display = "block"; + authDropDownMenuList.style.display = 'none'; + authDropinContainer.style.display = 'block'; loginButton.innerHTML = ` { + events.on('authenticated', (isAuthenticated) => { updateDropDownUI(isAuthenticated); });