Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/components/layout/header/cow-bell/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Link from 'next/link';

import { Icon } from '@/components/icon';
import { cn } from '@/lib/utils';
import { useNotification } from '@/providers';

export const CowBell = () => {
const { unReadCount, receivedNewNotification } = useNotification();

return (
<Link href={'/notification'} className='flex-center relative h-10 w-10'>
<Icon
id='bell-read'
className={cn(
'size-10 text-gray-700 transition-colors duration-200',
receivedNewNotification && 'animate-ring text-mint-500',
)}
/>
{unReadCount > 0 && (
<>
<span
className={cn(
'bg-mint-300 absolute top-1 right-1.75 aspect-square size-3.5 rounded-full',
receivedNewNotification && 'animate-ping',
)}
/>
<span className='bg-mint-500 text-mono-white text-text-2xs-semibold flex-center absolute top-1 right-1.75 aspect-square size-3.5 rounded-full'>
{unReadCount}
</span>
</>
)}
</Link>
);
};
9 changes: 9 additions & 0 deletions src/components/layout/header/header-login/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Link from 'next/link';

export const HeaderLogin = () => {
return (
<Link href={'/login'} className='text-text-sm-semibold px-2 py-1 text-gray-500'>
로그인
</Link>
);
};
45 changes: 6 additions & 39 deletions src/components/layout/header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,55 +1,22 @@
'use client';

import Link from 'next/link';
import { useRouter } from 'next/navigation';

import { Icon } from '@/components/icon';
import { cn } from '@/lib/utils';
import { useAuth, useNotification } from '@/providers';
import { CowBell } from '@/components/layout/header/cow-bell';
import { HeaderLogin } from '@/components/layout/header/header-login';
import { useAuth } from '@/providers';

export const Header = () => {
const { isAuthenticated } = useAuth();
const { unReadCount, receivedNewNotification } = useNotification();
const router = useRouter();

const onLogoClick = (e: React.MouseEvent<HTMLAnchorElement>) => {
e.preventDefault();
router.push('/');
};

return (
<header className={`sticky top-0 z-100 w-full bg-white`}>
<nav className='flex-between px-4 py-2'>
<Link href={'/'} onClick={onLogoClick}>
<Link href={'/'}>
<Icon id='wego-logo' width={92} height={40} />
</Link>
<div className='flex-center gap-2'>
<Link
href={'/notification'}
prefetch={isAuthenticated}
className='flex-center relative h-10 w-10'
>
<Icon
id='bell-read'
className={cn(
'size-10 text-gray-700 transition-colors duration-200',
receivedNewNotification && 'animate-ring text-mint-500',
)}
/>
{unReadCount > 0 && (
<>
<span
className={cn(
'bg-mint-300 absolute top-1 right-1.75 aspect-square size-3.5 rounded-full',
receivedNewNotification && 'animate-ping',
)}
/>
<span className='bg-mint-500 text-mono-white text-text-2xs-semibold flex-center absolute top-1 right-1.75 aspect-square size-3.5 rounded-full'>
{unReadCount}
</span>
</>
)}
</Link>
</div>
<div className='flex-center gap-2'>{isAuthenticated ? <CowBell /> : <HeaderLogin />}</div>
</nav>
</header>
);
Expand Down
2 changes: 1 addition & 1 deletion src/providers/provider-auth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface Props {
}

export const AuthProvider = ({ children, hasRefreshToken }: Props) => {
const [isAuthenticated, setIsAuthenticated] = useState(false);
const [isAuthenticated, setIsAuthenticated] = useState(hasRefreshToken);

// 초기값 설정
// 페이지가 새로고침 될 때 accessToken이 없으면 refresh 시도, state update 실행
Expand Down