Skip to content

Commit 821d359

Browse files
committed
refactor : 전역 상태(AuthStore)를 통해 기존 페이지 URL을 통한 관리자 여부를 로그인한 유저의 데이터 기준으로 변경
1 parent 7bf082f commit 821d359

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

src/components/common/sidebar/Sidebar.styled.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import styled from 'styled-components';
22

3-
export const Container = styled.div<{ $isAdmin: boolean }>`
3+
export const Container = styled.div<{ $isAdmin: boolean | undefined }>`
44
display: flex;
55
flex-direction: column;
66
border: 2px solid #f0f0f0;

src/components/common/sidebar/Sidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ interface SidebarProps {
2222
const Sidebar = ({ menuItems, profileImage, nickname }: SidebarProps) => {
2323
const isLoggedIn = useAuthStore((state) => state.isLoggedIn);
2424
const location = useLocation();
25+
const isAdmin = useAuthStore().userData?.admin;
2526
const isUserPage = location.pathname.includes('/user');
2627
const isManagePage = location.pathname.includes('/manage');
27-
const isAdmin = location.pathname.includes('/admin');
2828

2929
const isMyProfile = isLoggedIn && !isUserPage && !isManagePage;
3030
const getActiveIndex = useCallback(() => {

src/components/user/mypage/ContentTab.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as S from './ContentTab.styled';
33
import { Link, Outlet, useLocation } from 'react-router-dom';
44
import ScrollWrapper from './ScrollWrapper';
55
import MovedInquiredLink from '../customerService/MoveInquiredLink';
6+
import useAuthStore from '../../../store/authStore';
67

78
interface Filter {
89
title: string;
@@ -18,8 +19,8 @@ interface ContentProps {
1819

1920
export default function ContentTab({ filter, $justifyContent }: ContentProps) {
2021
const { pathname } = useLocation();
22+
const isAdmin = useAuthStore().userData?.admin;
2123
const [filterId, setFilterId] = useState<number>();
22-
const isAdmin = pathname.includes('/admin');
2324

2425
useEffect(() => {
2526
const currentFilter = filter.find((item) =>

src/components/user/mypage/activityLog/ActivityLog.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { useLocation } from 'react-router-dom';
21
import {
32
ACTIVITY_FILTER,
43
ACTIVITY_FILTER_ADMIN,
54
} from '../../../../constants/user/myPageFilter';
65
import ContentTab from '../ContentTab';
6+
import useAuthStore from '../../../../store/authStore';
77

88
export default function ActivityLog() {
9-
const { pathname } = useLocation();
10-
const isAdmin = pathname.includes('/admin');
9+
const isAdmin = useAuthStore().userData?.admin;
1110

1211
return (
1312
<ContentTab

src/components/user/userPage/userProjectList/UserProjectList.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { Link, useLocation } from 'react-router-dom';
1+
import { Link } from 'react-router-dom';
22
import * as S from '../../mypage/joinedProject/MyJoinProjects.styled';
33
import { ROUTES } from '../../../../constants/routes';
44
import NoContent from '../../../common/noContent/NoContent';
55
import ScrollWrapper from '../../mypage/ScrollWrapper';
66
import Spinner from '../../mypage/Spinner';
77
import Project from '../../mypage/joinedProject/Project';
88
import { useGetUserProjectList } from '../../../../hooks/user/useGetUserProjectList';
9+
import useAuthStore from '../../../../store/authStore';
910

1011
export default function UserProjects() {
11-
const { pathname } = useLocation();
12-
const isAdmin = pathname.includes('/admin');
12+
const isAdmin = useAuthStore().userData?.admin;
1313
const { userProjectData, isLoading, title } = useGetUserProjectList();
1414

1515
if (isLoading) {

0 commit comments

Comments
 (0)