-
Notifications
You must be signed in to change notification settings - Fork 6
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-fe: Sidebar 컴포넌트 개선 #773
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1861d0c
Create draft PR for #772
github-actions[bot] 790165b
test: 스토리북 LocalStorage의 clubId 설정
lurgi 2faf3ae
test: DashboardLayout 스토리 수정
lurgi a6e01fa
test: DashboardLayout 스토리 북 Outlet 추가
lurgi 6ed96ad
feat: 사이드 바 여닫는 기능 구현
lurgi 3a25b0d
test: DashboardSidebar 수정
lurgi 8a48712
feat: 사이드바 디자인 변경
lurgi 6cbc365
test: DashboardLayout 스토리 수정
lurgi b930ca6
feat: useElementRect 구현 및 적용
lurgi 143c228
chore: div외부 p태그 삭제
lurgi 7b78b69
refactor: 사이드바 아이콘 매핑
lurgi 3684b48
feat: 피드백 반영 icons크기 조절 및 수정
lurgi 08c3f0e
feat: 불필요한 로직 삭제
lurgi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 128 additions & 26 deletions
154
frontend/src/components/dashboard/DashboardSidebar/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,147 @@ | ||
import { useMemo } from 'react'; | ||
|
||
import Logo from '@assets/images/logo.svg'; | ||
import Accordion from '@components/_common/molecules/Accordion'; | ||
import { routes } from '@router/path'; | ||
import { Link } from 'react-router-dom'; | ||
import { Link, useLocation } from 'react-router-dom'; | ||
|
||
import type { RecruitmentStatusObject } from '@utils/compareTime'; | ||
|
||
import { Fragment } from 'react/jsx-runtime'; | ||
import { HiChevronDoubleLeft, HiOutlineHome } from 'react-icons/hi2'; | ||
import { HiOutlineMenu } from 'react-icons/hi'; | ||
import { GrDocumentLocked, GrDocumentTime, GrDocumentUser } from 'react-icons/gr'; | ||
import type { IconType } from 'react-icons'; | ||
|
||
import IconButton from '@components/_common/atoms/IconButton'; | ||
import LogoutButton from './LogoutButton'; | ||
|
||
import S from './style'; | ||
|
||
interface Option { | ||
text: string; | ||
isSelected: boolean; | ||
applyFormId: string; | ||
dashboardId: string; | ||
status: RecruitmentStatusObject; | ||
} | ||
|
||
interface SidebarStyle { | ||
isSidebarOpen: boolean; | ||
onClickSidebarToggle: () => void; | ||
} | ||
|
||
interface DashboardSidebarProps { | ||
options: Option[]; | ||
sidebarStyle: SidebarStyle; | ||
options?: Option[]; | ||
} | ||
|
||
export default function DashboardSidebar({ options }: DashboardSidebarProps) { | ||
export default function DashboardSidebar({ sidebarStyle, options }: DashboardSidebarProps) { | ||
const pendingPosts = useMemo(() => options?.filter(({ status }) => status.isPending), [options]); | ||
const onGoingPosts = useMemo(() => options?.filter(({ status }) => status.isOngoing), [options]); | ||
const closedPosts = useMemo(() => options?.filter(({ status }) => status.isClosed), [options]); | ||
|
||
const sidebarContentList = [ | ||
{ title: '모집 예정 공고 목록', posts: pendingPosts }, | ||
{ title: '진행 중 공고 목록', posts: onGoingPosts }, | ||
{ title: '마감 된 공고 목록', posts: closedPosts }, | ||
]; | ||
|
||
const location = useLocation(); | ||
|
||
const IconObj: Record<RecruitmentStatusObject['status'], IconType> = { | ||
Pending: GrDocumentTime, | ||
Ongoing: GrDocumentUser, | ||
Closed: GrDocumentLocked, | ||
}; | ||
|
||
return ( | ||
<S.Container> | ||
<Link to={routes.dashboard.list()}> | ||
<S.Logo | ||
src={Logo} | ||
alt="크루루 로고" | ||
/> | ||
</Link> | ||
|
||
<S.Contents> | ||
<Accordion title={<Link to={routes.dashboard.list()}>공고</Link>}> | ||
{options.map(({ text, isSelected, applyFormId, dashboardId }, index) => ( | ||
// eslint-disable-next-line react/no-array-index-key | ||
<Accordion.ListItem key={index}> | ||
<S.LinkContainer isSelected={isSelected}> | ||
<Link to={routes.dashboard.post({ dashboardId, applyFormId })}>{text}</Link> | ||
</S.LinkContainer> | ||
</Accordion.ListItem> | ||
))} | ||
</Accordion> | ||
</S.Contents> | ||
|
||
<LogoutButton /> | ||
<S.Container isSidebarOpen={sidebarStyle.isSidebarOpen}> | ||
<S.SidebarHeader> | ||
{sidebarStyle.isSidebarOpen && ( | ||
<Link to={routes.dashboard.list()}> | ||
<S.Logo | ||
src={Logo} | ||
alt="크루루 로고" | ||
/> | ||
</Link> | ||
)} | ||
|
||
<IconButton | ||
size="sm" | ||
outline={false} | ||
onClick={sidebarStyle.onClickSidebarToggle} | ||
> | ||
<S.SidebarToggleIcon> | ||
{sidebarStyle.isSidebarOpen ? ( | ||
<HiChevronDoubleLeft | ||
size={24} | ||
strokeWidth={0.8} | ||
/> | ||
) : ( | ||
<HiOutlineMenu | ||
size={24} | ||
strokeWidth={2.4} | ||
/> | ||
)} | ||
</S.SidebarToggleIcon> | ||
</IconButton> | ||
</S.SidebarHeader> | ||
|
||
<nav> | ||
<S.Contents> | ||
<S.SidebarItem> | ||
<Link to={routes.dashboard.list()}> | ||
<S.SidebarItemLink | ||
isSelected={location.pathname === routes.dashboard.list()} | ||
isSidebarOpen={sidebarStyle.isSidebarOpen} | ||
> | ||
<S.IconContainer> | ||
<HiOutlineHome | ||
size={22} | ||
strokeWidth={2} | ||
/> | ||
</S.IconContainer> | ||
{sidebarStyle.isSidebarOpen && <S.SidebarItemTextHeader>모집 공고</S.SidebarItemTextHeader>} | ||
</S.SidebarItemLink> | ||
</Link> | ||
</S.SidebarItem> | ||
|
||
{!!options?.length && <S.Divider />} | ||
|
||
{sidebarContentList.map(({ title, posts }) => { | ||
if (posts?.length === 0) return null; | ||
return ( | ||
<Fragment key={title}> | ||
<S.ContentSubTitle>{sidebarStyle.isSidebarOpen ? title : <S.Circle />}</S.ContentSubTitle> | ||
{posts?.map(({ text, isSelected, applyFormId, dashboardId, status }) => { | ||
const Icon = IconObj[status.status]; | ||
|
||
return ( | ||
<S.SidebarItem key={applyFormId}> | ||
<Link to={routes.dashboard.post({ dashboardId, applyFormId })}> | ||
<S.SidebarItemLink | ||
isSelected={isSelected} | ||
isSidebarOpen={sidebarStyle.isSidebarOpen} | ||
> | ||
<S.IconContainer> | ||
<Icon | ||
size={16} | ||
strokeWidth={4} | ||
/> | ||
</S.IconContainer> | ||
{sidebarStyle.isSidebarOpen && <S.SidebarItemText>{text}</S.SidebarItemText>} | ||
</S.SidebarItemLink> | ||
</Link> | ||
</S.SidebarItem> | ||
); | ||
})} | ||
</Fragment> | ||
); | ||
})} | ||
</S.Contents> | ||
</nav> | ||
|
||
{sidebarStyle.isSidebarOpen && <LogoutButton />} | ||
</S.Container> | ||
); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useMemo
👍