Commit e0d5deb1 by Ravindra Kanojiya

header onclick issue resolved

1 parent 9bfe74c0
import { getSession, signOut } from "next-auth/react";
import Image from "next/image";
import Link from "next/link";
import React, { useEffect, useState } from "react";
import React, { useEffect, useRef, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { cleanImage } from "../../services/imageHandling";
import { Button, Container, Form, Nav, Navbar } from "react-bootstrap";
......@@ -24,9 +24,9 @@ const Header = () => {
// console.log("user", loadedUser);
const [isSticky, setIsSticky] = useState(false);
const router = useRouter();
const toggleGridViewDropdown = () => {
setIsGridViewOpen(!isGridViewOpen);
};
// const toggleGridViewDropdown = () => {
// setIsGridViewOpen(!isGridViewOpen);
// };
useEffect(() => {
const handleScroll = () => {
// Check if the scroll position is greater than a certain threshold
......@@ -49,6 +49,38 @@ const Header = () => {
useEffect(() => {
if (endUser) dispatch(getWishlists({ endUser: endUser.id }));
}, [endUser]);
////
// const [isGridViewOpen, setIsGridViewOpen] = useState(false);
const innerBoxRef = useRef(null); // Ref to hold reference to inner-box div
const logoutBkRef = useRef(null);
// Function to toggle the dropdown visibility
const toggleGridViewDropdown = () => {
setIsGridViewOpen(!isGridViewOpen); // Toggle the state
};
// Function to handle click outside
const handleClickOutside = (event) => {
if (
logoutBkRef.current &&
!logoutBkRef.current.contains(event.target) &&
innerBoxRef.current &&
!innerBoxRef.current.contains(event.target)
) {
setIsGridViewOpen(false); // Close if clicked outside
}
};
// Effect to add click event listener when component mounts
useEffect(() => {
document.addEventListener('mousedown', handleClickOutside);
return () => {
document.removeEventListener('mousedown', handleClickOutside);
};
}, []);
return (
<header className={`header_wrap ${isSticky ? "stick" : ""}`}>
{isSticky && <div style={{ height: 76 }} className="bg-transparent"></div>}
......@@ -61,7 +93,7 @@ const Header = () => {
</Navbar.Brand>
{loadedUser && loadedUser.id ? (
<div className="top-btn hide-on-desktop">
<div className="logout-bk">
<div className="logout-bk" >
<a onClick={toggleGridViewDropdown} className="user-icon">
<span className="image-container user-pic">
<Image layout="fill" priority alt="" className="image img-fluid" src="/images/icons/user.svg" />
......@@ -71,7 +103,7 @@ const Header = () => {
</span>
</a>
{/* <p>{loadedUser.phone}</p> */}
<div className={`inner-box ${isGridViewOpen ? "open" : ""}`}>
<div ref={logoutBkRef} className={`inner-box ${isGridViewOpen ? "open" : ""}`}>
<div className="user-info">
<div className="pic">
<span className="image-container">
......@@ -267,7 +299,7 @@ const Header = () => {
</span>
</a>
{/* <p>{loadedUser.phone}</p> */}
<div className={`inner-box ${isGridViewOpen ? "open" : ""}`}>
<div ref={innerBoxRef} className={`inner-box ${isGridViewOpen ? "open" : ""}`}>
<div className="user-info">
<div className="pic">
<span className="image-container">
......
......@@ -1920,6 +1920,7 @@ span.form-error,
.vendorDetails p.pview {
color: #0070bd;
text-decoration: underline;
word-wrap: break-word;
}
.vendorDetails .borderLeft {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!