Skip to content

Commit

Permalink
[Common] [Hotfix] 헤더 로그인 사항 적용안된 부분 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
suwonthugger committed Nov 10, 2024
1 parent 11ed3ae commit 6babf13
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions apps/web/src/shared/components/layout/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import Link from 'next/link';
import React, { useRef, useState } from 'react';
import useClickOutside from '@/shared/hooks/useClickOutside';
import { useGetUserInfo } from '@/shared/apis/auth/queries';
import { getAuthHeader } from '@/shared/utils/auth';
import CloseIcon from '@/shared/assets/svgs/close_icon.svg';
import Logo from '@/shared/assets/svgs/logo_sm.svg';
import HamburgerIcon from '@/shared/assets/svgs/menu_icon.svg';
Expand Down Expand Up @@ -32,6 +34,8 @@ const Header = () => {

const menuRef = useRef(null);

useClickOutside(menuRef, handleMenuClose);

React.useEffect(() => {
const isMobile = () => {
return /Mobi|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
Expand All @@ -44,6 +48,8 @@ const Header = () => {
window.location.replace(newUrl);
}

setIsLoggedIn(!!getAuthHeader());

const handleResize = () => {
if (window.innerWidth <= 700) {
console.log('화면 너비가 700px 이하입니다.');
Expand Down
23 changes: 23 additions & 0 deletions apps/web/src/shared/hooks/useClickOutside.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { RefObject, useEffect } from 'react';

const useClickOutside = (
ref: RefObject<HTMLElement>,
callback: () => void,
enable: boolean = true,
) => {
useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
if (!enable) return;
if (ref.current && !ref.current.contains(event.target as Node)) {
callback();
}
};

document.addEventListener('mousedown', handleClickOutside);
return () => {
document.removeEventListener('mousedown', handleClickOutside);
};
}, [ref, callback, enable]);
};

export default useClickOutside;

0 comments on commit 6babf13

Please sign in to comment.