Skip to content

Commit

Permalink
Fix eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferri0 committed Dec 4, 2024
1 parent 6fa2b0f commit a054423
Showing 1 changed file with 32 additions and 33 deletions.
65 changes: 32 additions & 33 deletions blocks/header/renderAuthDropdown.js
Original file line number Diff line number Diff line change
@@ -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]) => {
Expand All @@ -19,7 +19,7 @@ function checkAndRedirect(redirections) {
function renderSignIn(element) {
authRenderer.render(SignIn, {
onSuccessCallback: () => {},
formSize: "small",
formSize: 'small',
routeForgotPassword: () => CUSTOMER_FORGOTPASSWORD_PATH,
})(element);
}
Expand All @@ -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);

Expand All @@ -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 = `
<svg
width="25"
Expand All @@ -111,7 +110,7 @@ export function renderAuthDropdown(navTools) {
}
};

events.on("authenticated", (isAuthenticated) => {
events.on('authenticated', (isAuthenticated) => {
updateDropDownUI(isAuthenticated);
});

Expand Down

0 comments on commit a054423

Please sign in to comment.