Skip to content

Commit

Permalink
feat: PCPanel 권한 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
junghaesung79 committed Apr 16, 2024
1 parent c948b7f commit ffb9c1c
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 63 deletions.
1 change: 0 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ function App() {
<Route path="/owner/menu-management" element={<PageNotFound />} />
<Route path="/owner/order-management" element={<PageNotFound />} />
<Route path="/owner/sales-management" element={<PageNotFound />} />
<Route path="/owner/shop-add" element={<PageNotFound />} />
<Route path="/owner/event-add/:id" element={<AddingEvent />} />
</Route>
</Route>
Expand Down
6 changes: 3 additions & 3 deletions src/component/common/Header/MobilePanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import useUserTypeStore from 'store/userType';
import { CATEGORY_COOP, CATEGORY_OWNER, HeaderCategory } from 'utils/constant/category';
import styles from './MobilePanel.module.scss';

interface Props {
interface Prop {
hideSidebar: () => void;
category: HeaderCategory;
}

function HeaderContent({ hideSidebar, category }: Props) {
function PanelContent({ hideSidebar, category }: Prop) {
const { title, submenu } = category;

return (
Expand Down Expand Up @@ -132,7 +132,7 @@ export default function MobilePanel() {
</div>

{targetCategory.map((category: HeaderCategory) => (
<HeaderContent hideSidebar={hideSidebar} category={category} />
<PanelContent hideSidebar={hideSidebar} category={category} />
))}

<img
Expand Down
134 changes: 75 additions & 59 deletions src/component/common/Header/PCPanel/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ReactComponent as LogoIcon } from 'assets/svg/common/koin-logo.svg';
import { Link, useNavigate } from 'react-router-dom';
import { CATEGORY_OWNER, HeaderCategory } from 'utils/constant/category';
import { CATEGORY_COOP, CATEGORY_OWNER, HeaderCategory } from 'utils/constant/category';
import cn from 'utils/ts/className';
import { useLogout } from 'query/auth';
import usePrevPathStore from 'store/path';
import useMegaMenu from 'component/common/Header/hooks/useMegaMenu';
import useUserTypeStore from 'store/userType';
import styles from './PCPanel.module.scss';

const ID: { [key: string]: string; } = {
Expand All @@ -13,19 +14,82 @@ const ID: { [key: string]: string; } = {
LABEL2: 'mega-menu-label-2',
};

export default function PCPanel() {
const navigate = useNavigate();

const { setPrevPath } = usePrevPathStore((state) => state);
const { logout } = useLogout();
interface Prop {
categoryArray: HeaderCategory[];
}

function HeaderContent({ categoryArray }: Prop) {
const {
panelMenuList,
isExpanded: isMegaMenuExpanded,
createOnChangeMenu,
onFocusPanel,
hideMegaMenu,
} = useMegaMenu(CATEGORY_OWNER);
} = useMegaMenu(categoryArray);

return (
<div
className={cn({
[styles['mega-menu']]: true,
[styles['header__mega-menu']]: true,
})}
onBlur={hideMegaMenu}
onMouseOut={hideMegaMenu}
>
<ul className={styles['mega-menu__trigger-list']}>
{categoryArray.map((category) => (
<li
key={category.title}
>
<button
className={styles['mega-menu__trigger']}
tabIndex={0}
type="button"
onClick={createOnChangeMenu(category.title)}
onFocus={createOnChangeMenu(category.title)}
onBlur={hideMegaMenu}
onMouseOver={createOnChangeMenu(category.title)}
onMouseOut={hideMegaMenu}
aria-expanded={isMegaMenuExpanded}
>
<span>
{category.title}
</span>
</button>
</li>
))}
</ul>

<div
id={ID.PANEL}
className={styles['mega-menu__panel']}
onFocus={onFocusPanel}
onMouseOver={onFocusPanel}
aria-hidden={!isMegaMenuExpanded}
aria-labelledby={Array.from({ length: 2 }, (_, index) => ID[`LABEL${index + 1}`]).join(' ')}
>
<ul className={styles['mega-menu__content']}>
{panelMenuList?.map((menu) => (
<li className={styles['mega-menu__menu']} key={menu.title}>
<Link className={styles['mega-menu__link']} to={menu.link} onClick={hideMegaMenu}>
{menu.title}
</Link>
</li>
))}
</ul>
</div>
</div>
);
}

export default function PCPanel() {
const navigate = useNavigate();

const { setPrevPath } = usePrevPathStore((state) => state);
const { logout } = useLogout();
const { userType } = useUserTypeStore();

const targetCategory = userType === 'OWNER' ? CATEGORY_OWNER : CATEGORY_COOP;

const handleLogout = () => {
logout(undefined, {
Expand All @@ -45,63 +109,15 @@ export default function PCPanel() {
>
<LogoIcon title="코인 로고" />
</Link>
<div
className={cn({
[styles['mega-menu']]: true,
[styles['header__mega-menu']]: true,
})}
onBlur={hideMegaMenu}
onMouseOut={hideMegaMenu}
>
<ul className={styles['mega-menu__trigger-list']}>
{CATEGORY_OWNER.map((category: HeaderCategory) => (
<li
key={category.title}
>
<button
className={styles['mega-menu__trigger']}
tabIndex={0}
type="button"
onClick={createOnChangeMenu(category.title)}
onFocus={createOnChangeMenu(category.title)}
onBlur={hideMegaMenu}
onMouseOver={createOnChangeMenu(category.title)}
onMouseOut={hideMegaMenu}
aria-expanded={isMegaMenuExpanded}
>
<span>
{category.title}
</span>
</button>
</li>
))}
</ul>
<div
id={ID.PANEL}
className={styles['mega-menu__panel']}
onFocus={onFocusPanel}
onMouseOver={onFocusPanel}
aria-hidden={!isMegaMenuExpanded}
aria-labelledby={Array.from({ length: 2 }, (_, index) => ID[`LABEL${index + 1}`]).join(' ')}
>
<ul className={styles['mega-menu__content']}>
{panelMenuList?.map((menu) => (
<li className={styles['mega-menu__menu']} key={menu.title}>
<Link className={styles['mega-menu__link']} to={menu.link}>
{menu.title === '가게정보' && menu.title}
</Link>
</li>
))}
</ul>
</div>
</div>
<HeaderContent categoryArray={targetCategory} />

<ul className={styles['header__auth-menu']}>
{/* Auth 완료시 수정 필요 */}
<li className={styles['header__auth-link']}>
{/* <li className={styles['header__auth-link']}>
<Link to="/owner/modify-info">
정보수정
</Link>
</li>
</li> */}
<li className={styles['header__auth-link']}>
<button type="button" onClick={handleLogout}>
로그아웃
Expand Down

0 comments on commit ffb9c1c

Please sign in to comment.