Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/#85 Header 컴포넌트 기능 추가 및 개선 #87

Merged
merged 2 commits into from
Oct 31, 2024
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
305 changes: 153 additions & 152 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/mockServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* - Please do NOT serve this file on production.
*/

const PACKAGE_VERSION = '2.5.2';
const PACKAGE_VERSION = '2.6.0';
const INTEGRITY_CHECKSUM = '07a8241b182f8a246a7cd39894799a9e';
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse');
const activeClientIds = new Set();
Expand Down
4 changes: 0 additions & 4 deletions src/assets/images/profile-image.svg

This file was deleted.

14 changes: 13 additions & 1 deletion src/features/layout/Header/components/LanguageFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import theme from '@/assets/theme';
import { Select, Icon, List } from '@/components/common';
import useGlobalSelect from '@/components/common/Select/hooks/useGlobalSelect';
import { responsiveStyle } from '@/utils/responsive';

const triggerStyle = { minWidth: '80px', fontSize: '16px', fontWeight: '700', color: theme.palettes.blue };
const triggerStyle = {
minWidth: '80px',
fontSize: '16px',
fontWeight: '700',
color: theme.palettes.blue,

...responsiveStyle({
mobile: {
width: '100%',
},
}),
};

const languageOptions = [
{
Expand Down
3 changes: 1 addition & 2 deletions src/features/layout/Header/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Meta, StoryObj } from '@storybook/react';
import Header from '.';
import profileImage from '@assets/images/profile-image.svg';

const meta: Meta<typeof Header> = {
title: 'features/layout/Header',
Expand All @@ -13,5 +12,5 @@ export default meta;
type Story = StoryObj<typeof Header>;

export const Default: Story = {
render: () => <Header profileImage={profileImage} />,
render: () => <Header />,
};
1 change: 1 addition & 0 deletions src/features/layout/Header/index.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const Nav = styled.nav<NavProps>`
mobile: {
flexDirection: 'column',
alignItems: 'stretch',
textAlign: 'center',
},
})}

Expand Down
74 changes: 63 additions & 11 deletions src/features/layout/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,80 @@ import {
Nav,
} from './index.styles';
import { UserData } from '@/types';
import { startTransition, useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import ROUTE_PATH from '@/routes/path';

type Props = Pick<UserData, 'profileImage'>;

export default function Header({ profileImage }: Props) {
export default function Header() {
const navigate = useNavigate();
const [menuOpen, toggleMenu] = useToggle();
const [user, setUser] = useState<UserData | null>(null);

useEffect(() => {
const userData = localStorage.getItem('user');

if (userData) {
setUser(JSON.parse(userData));
}
}, []);

const handleLogoClick = () => {
startTransition(() => {
navigate(ROUTE_PATH.HOME);
});
};

const handleLogin = () => {
navigate(ROUTE_PATH.AUTH.SIGN_IN);
};

const handleLogout = () => {
localStorage.removeItem('token');
localStorage.removeItem('user');
setUser(null);
navigate(ROUTE_PATH.HOME);
};

const handlePostNotice = () => {
navigate(ROUTE_PATH.POST_NOTICE);
};

const handleProfileClick = () => {
if (user?.type === 'employer') {
navigate(ROUTE_PATH.MY_PAGE.EMPLOYER);
} else if (user?.type === 'employee') {
navigate(ROUTE_PATH.EMPLOYEE.EMPLOYEE_PAGE);
}
};

return (
<HeaderContainer>
<Flex justifyContent="space-between" alignItems="center" css={flexStyle}>
<LogoImg />
<LogoImg onClick={handleLogoClick} />
<Flex justifyContent="flex-end" css={menuIconStyle} onClick={toggleMenu}>
{menuOpen ? <CloseIcon /> : <MenuIcon />}
</Flex>
<Nav open={menuOpen}>
<LanguageFilter />
<Button design="outlined" style={commonButtonStyle}>
채용공고 등록
</Button>
<Flex justifyContent="center" alignItems="center">
<Image url={profileImage} size={{ width: '40px', height: '40px' }} css={imageStyle} />
</Flex>
<Button style={customButtonStyle}>로그아웃</Button>
{!user ? (
<Button style={customButtonStyle} onClick={handleLogin}>
로그인
</Button>
) : (
<>
{user.type === 'employer' && (
<Button design="outlined" style={commonButtonStyle} onClick={handlePostNotice}>
채용공고 등록
</Button>
)}
<Flex justifyContent="center" alignItems="center" onClick={handleProfileClick}>
<Image url={user.profileImage} size={{ width: '40px', height: '40px' }} css={imageStyle} />
</Flex>
<Button style={customButtonStyle} onClick={handleLogout}>
로그아웃
</Button>
</>
)}
</Nav>
</Flex>
</HeaderContainer>
Expand Down
8 changes: 1 addition & 7 deletions src/features/layout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { ReactNode } from 'react';
import Footer from './Footer';
import Header from './Header';
import profileImage from '@assets/images/profile-image.svg';

const initialData = {
type: 'employer',
profileImage: profileImage,
};

export default function Layout({ children }: { children: ReactNode }) {
return (
<>
<Header profileImage={initialData.profileImage} />
<Header />
{children}
<Footer />
</>
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type ForeignerData = {
};

export type UserData = {
type: string;
type: 'first' | 'employee' | 'employer';
profileImage: string;
};

Expand Down
Loading