Skip to content

Commit

Permalink
refactor: 경로 static으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
kimeodml committed Aug 11, 2024
1 parent 1e85d04 commit e0dc176
Show file tree
Hide file tree
Showing 25 changed files with 110 additions and 143 deletions.
37 changes: 19 additions & 18 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import ModifyEvent from 'page/ManageEvent/ModifyEvent';
import LogPage from 'component/common/PageLog';
import CommonLayout from 'page/Auth/components/Common';
import FindPassword from 'page/Auth/FindPassword';
import ROUTES from 'static/routes';

interface ProtectedRouteProps {
userTypeRequired: UserType;
Expand All @@ -30,10 +31,10 @@ function ProtectedRoute({ userTypeRequired }: ProtectedRouteProps) {

if (userType !== userTypeRequired) {
if (userType === 'OWNER') {
return <Navigate to="/owner" replace />;
return <Navigate to={ROUTES.OWNER} replace />;
}
if (userType === null) {
return <Navigate to="/login" replace />;
return <Navigate to={ROUTES.LOGIN} replace />;
}
}

Expand All @@ -44,30 +45,30 @@ function App() {
return (
<Suspense fallback={<div />}>
<Routes>
<Route path="/" element={<Navigate to="/owner" />} />
<Route path={ROUTES.MAIN} element={<Navigate to={ROUTES.OWNER} />} />
<Route element={<ProtectedRoute userTypeRequired="OWNER" />}>
<Route path="/owner" element={<OwnerLayout />}>
<Route path="/owner" element={<MyShopPage />} />
<Route path="/owner/shop-registration" element={<ShopRegistration />} />
<Route path="/owner/add-menu" element={<AddMenu />} />
<Route path="/owner/modify-menu/:menuId" element={<ModifyMenu />} />
<Route path="/owner/modify-info" element={<PageNotFound />} />
<Route path="/owner/menu-management" element={<PageNotFound />} />
<Route path="/owner/order-management" element={<PageNotFound />} />
<Route path="/owner/sales-management" element={<PageNotFound />} />
<Route path="/owner/event-add/:id" element={<AddingEvent />} />
<Route path="/owner/event-modify/:id" element={<ModifyEvent />} />
<Route path={ROUTES.OWNER} element={<OwnerLayout />}>
<Route path={ROUTES.OWNER} element={<MyShopPage />} />
<Route path={ROUTES.OWNER_SHOPREGISTRATION} element={<ShopRegistration />} />
<Route path={ROUTES.OWNER_ADDMENU} element={<AddMenu />} />
<Route path={ROUTES.OWNER_MODIFYMENU} element={<ModifyMenu />} />
<Route path={ROUTES.OWNER_MODIFYINFO} element={<PageNotFound />} />
<Route path={ROUTES.OWNER_MENUMANAGEMENT} element={<PageNotFound />} />
<Route path={ROUTES.OWNER_ORDERMANAGEMENT} element={<PageNotFound />} />
<Route path={ROUTES.OWNER_SALESMANAGEMENT} element={<PageNotFound />} />
<Route path={ROUTES.OWNER_EVENT} element={<AddingEvent />} />
<Route path={ROUTES.OWNER_EVENT_MODIFY} element={<ModifyEvent />} />
</Route>
</Route>

<Route element={<AuthLayout />}>
<Route element={<ProtectedRoute userTypeRequired={null} />}>
<Route path="/login" element={<Login />} />
<Route path={ROUTES.LOGIN} element={<Login />} />
<Route element={<CommonLayout />}>
<Route path="/signup" element={<Signup />} />
<Route path="/find-password" element={<FindPassword />} />
<Route path={ROUTES.SIGNUP} element={<Signup />} />
<Route path={ROUTES.FINDPW} element={<FindPassword />} />
</Route>
<Route path="/find-id" element={<PageNotFound />} />
<Route path={ROUTES.FINDID} element={<PageNotFound />} />
</Route>
</Route>
</Routes>
Expand Down
9 changes: 5 additions & 4 deletions src/component/common/Header/MobilePanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import useMobileSidebar from 'component/common/Header/hooks/useMobileSidebar';
import useUserTypeStore from 'store/useUserTypeStore';
import { CATEGORY_OWNER, HeaderCategory } from 'utils/constant/category';
import useSuspenseUser from 'utils/hooks/useSuspenseUser';
import ROUTES from 'static/routes';
import styles from './MobilePanel.module.scss';

interface Prop {
Expand Down Expand Up @@ -63,8 +64,8 @@ export default function MobilePanel() {
const handleLogout = () => {
logout(undefined, {
onSettled: () => {
setPrevPath('/login');
navigate('/login');
setPrevPath(ROUTES.LOGIN);
navigate(ROUTES.LOGIN);
},
});
};
Expand All @@ -75,7 +76,7 @@ export default function MobilePanel() {
className={styles['mobile-header']}
>
<span className={styles['mobile-header__title']}>
{pathname === '/owner' ? (
{pathname === ROUTES.OWNER ? (
<MobileLogoIcon title="코인 로고" />
) : (targetCategory
.flatMap((categoryValue) => categoryValue.submenu)
Expand Down Expand Up @@ -119,7 +120,7 @@ export default function MobilePanel() {
</div>
<ul className={styles['mobile-header__auth-menu']}>
<li className={styles['mobile-header__my-info']}>
<Link to="/owner/modify-info">
<Link to={ROUTES.OWNER_MODIFYINFO}>
내 정보
</Link>
</li>
Expand Down
14 changes: 4 additions & 10 deletions src/component/common/Header/PCPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useLogout } from 'query/auth';
import usePrevPathStore from 'store/path';
import useMegaMenu from 'component/common/Header/hooks/useMegaMenu';
import useUserTypeStore from 'store/useUserTypeStore';
import ROUTES from 'static/routes';
import styles from './PCPanel.module.scss';

const ID: { [key: string]: string; } = {
Expand Down Expand Up @@ -94,8 +95,8 @@ export default function PCPanel() {
const handleLogout = () => {
logout(undefined, {
onSettled: () => {
setPrevPath('/login');
navigate('/login');
setPrevPath(ROUTES.LOGIN);
navigate(ROUTES.LOGIN);
},
});
};
Expand All @@ -104,20 +105,13 @@ export default function PCPanel() {
<>
<Link
className={styles.header__logo}
to="/"
to={ROUTES.MAIN}
tabIndex={0}
>
<LogoIcon title="코인 로고" />
</Link>
<HeaderContent categoryArray={targetCategory} />

<ul className={styles['header__auth-menu']}>
{/* Auth 완료시 수정 필요 */}
{/* <li className={styles['header__auth-link']}>
<Link to="/owner/modify-info">
정보수정
</Link>
</li> */}
<li className={styles['header__auth-link']}>
<button type="button" onClick={handleLogout}>
로그아웃
Expand Down
13 changes: 7 additions & 6 deletions src/component/common/Header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ReactComponent as BackArrowIcon } from 'assets/svg/common/back-arrow.svg';
import { Suspense } from 'react';
import { useLocation } from 'react-router-dom';
import ROUTES from 'static/routes';
import useMediaQuery from 'utils/hooks/useMediaQuery';
import styles from './Header.module.scss';
import MobilePanel from './MobilePanel';
Expand All @@ -10,9 +11,9 @@ function Header() {
const { pathname } = useLocation();
const { isMobile } = useMediaQuery();

if ((pathname === '/owner/add-menu'
|| pathname.startsWith('/owner/modify-menu/')
|| pathname.startsWith('/owner/event-add/'))
if ((pathname === ROUTES.OWNER_ADDMENU
|| pathname.startsWith(ROUTES.OWNER_MODIFYMENU)
|| pathname.startsWith(ROUTES.OWNER_EVENT))
&& isMobile) {
return (
<header className={styles['add-menu-header']}>
Expand All @@ -25,9 +26,9 @@ function Header() {
<BackArrowIcon title="뒤로 가기 버튼" />
</button>
<div className={styles['add-menu-header__caption']}>
{pathname === '/owner/add-menu' && '메뉴추가'}
{pathname.startsWith('/owner/modify-menu/') && '메뉴수정'}
{pathname.startsWith('/owner/event-add/') && '이벤트/공지 작성하기'}
{pathname === ROUTES.OWNER_ADDMENU && '메뉴추가'}
{pathname.startsWith(ROUTES.OWNER_MODIFYMENU) && '메뉴수정'}
{pathname.startsWith(ROUTES.OWNER_EVENT) && '이벤트/공지 작성하기'}
</div>
</header>
);
Expand Down
7 changes: 4 additions & 3 deletions src/layout/OwnerLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import ErrorBoundary from 'component/common/ErrorBoundary';
import Header from 'component/common/Header';
import { useEffect } from 'react';
import { Outlet, useLocation, useNavigate } from 'react-router-dom';
import ROUTES from 'static/routes';
import usePrevPathStore from 'store/path';
import useUserStore from 'store/user';
import useErrorBoundary from 'utils/hooks/useErrorBoundary';
Expand All @@ -18,8 +19,8 @@ export default function OwnerLayout() {
setUser()
.catch(handleErrorBoundary)
.catch(() => {
setPrevPath('/owner/shop-registration');
navigate('/owner/shop-registration');
setPrevPath(ROUTES.OWNER_SHOPREGISTRATION);
navigate(ROUTES.OWNER_SHOPREGISTRATION);
});
}
}, [handleErrorBoundary, setUser, setPrevPath, navigate, user]);
Expand All @@ -28,7 +29,7 @@ export default function OwnerLayout() {
<div>
{user && (
<>
{location.pathname !== '/owner/shop-registration' && <Header />}
{location.pathname !== ROUTES.OWNER_SHOPREGISTRATION && <Header />}
<ErrorBoundary message="에러가 발생했습니다.">
<Outlet />
</ErrorBoundary>
Expand Down
3 changes: 2 additions & 1 deletion src/page/AddMenu/components/GoMyShop/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createPortal } from 'react-dom';
import { Link } from 'react-router-dom';
import ROUTES from 'static/routes';
import styles from './GoMyShopModal.module.scss';

interface CheckModalProps {
Expand Down Expand Up @@ -30,7 +31,7 @@ export default function GoMyShopModal({
>
<span className={styles['content__main-text']}>{mainMessage}</span>
<span className={styles['content__sub-text']}>{subMessage}</span>
<Link to="/">
<Link to={ROUTES.MAIN}>
<button
type="button"
className={styles['content__goMyShop-button']}
Expand Down
3 changes: 2 additions & 1 deletion src/page/AddMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import useAddMenuStore from 'store/addMenu';
import { useErrorMessageStore } from 'store/errorMessageStore';
import useScrollToTop from 'utils/hooks/useScrollToTop';
import useLogger from 'utils/hooks/useLogger';
import ROUTES from 'static/routes';
import MenuImage from './components/MenuImage';
import MenuName from './components/MenuName';
import MenuPrice from './components/MenuPrice';
Expand Down Expand Up @@ -69,7 +70,7 @@ export default function AddMenu() {
if (isComplete) {
toggleConfirmClick();
} else {
navigate('/owner');
navigate(ROUTES.OWNER);
logger.actionEventClick({ actionTitle: 'OWNER', title: 'add_menu_cancel', value: '메뉴 추가 취소' });
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/page/Auth/Login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { LoginParams } from 'model/auth';
import { useState } from 'react';
import sha256 from 'utils/ts/SHA-256';
import { useErrorMessageStore } from 'store/errorMessageStore';
import ROUTES from 'static/routes';
import styles from './Login.module.scss';
import OPTION from './static/option';
import ApprovalModal from './ApprovalModal';
Expand Down Expand Up @@ -128,7 +129,7 @@ export default function Login() {
로그인
</button>
{isMobile && (
<button className={styles.form__button} type="button" onClick={() => navigate('/signup')}>
<button className={styles.form__button} type="button" onClick={() => navigate(ROUTES.SIGNUP)}>
회원가입
</button>
)}
Expand Down
3 changes: 2 additions & 1 deletion src/page/Auth/SignupTmp/view/CompletePage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Link } from 'react-router-dom';
import { ReactComponent as Check } from 'assets/svg/auth/check.svg';
import useStepStore from 'store/useStepStore';
import ROUTES from 'static/routes';
import styles from './Complete.module.scss';

export default function Complete() {
Expand All @@ -22,7 +23,7 @@ export default function Complete() {
가입 허가가 승인되면 로그인이 가능합니다.
</span>
</div>
<Link to="/login" className={styles['link-button']} onClick={initialize}>로그인 화면 바로가기</Link>
<Link to={ROUTES.LOGIN} className={styles['link-button']} onClick={initialize}>로그인 화면 바로가기</Link>
</div>
);
}
7 changes: 3 additions & 4 deletions src/page/Auth/components/Common/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import { FormProvider, useForm, UseFormSetError } from 'react-hook-form';
import { Outlet, useLocation, useNavigate } from 'react-router-dom';
import cn from 'utils/ts/className';
import { Register, RegisterUser } from 'model/auth';
// eslint-disable-next-line
import { changePassword } from 'api/auth';
import { phoneRegisterUser } from 'api/register';
import { isKoinError, sendClientError } from '@bcsdlab/koin';
import { useStep } from 'page/Auth/hook/useStep';
import sha256 from 'utils/ts/SHA-256';
// eslint-disable-next-line
import Done from '../Done/index';
import ROUTES from 'static/routes';
import Done from 'page/Auth/components/Done';
import styles from './index.module.scss';

const setNewPassword = async (
Expand Down Expand Up @@ -95,7 +94,7 @@ export default function CommonLayout() {
const progressPercentage = (index + 1) / totalStep * 100;

const stepCheck = async () => {
if (isComplete) navigate('/login');
if (isComplete) navigate(ROUTES.LOGIN);
if (!errors.root) {
if (index + 1 === totalStep && isFindPassword) {
setNewPassword(getValues('phone_number'), getValues('password'), setError);
Expand Down
3 changes: 2 additions & 1 deletion src/page/Auth/components/Done/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ReactComponent as Success } from 'assets/svg/auth/done.svg';
import { useNavigate } from 'react-router-dom';
import ROUTES from 'static/routes';
import styles from './index.module.scss';

const completeFindPassword = {
Expand Down Expand Up @@ -36,7 +37,7 @@ export default function Done({ isFindPassword }: Props) {
</div>
<button
type="button"
onClick={() => navigate('/login')}
onClick={() => navigate(ROUTES.LOGIN)}
className={styles.button}
>
{isFindPassword ? '로그인하러 가기' : '로그인 화면 바로가기'}
Expand Down
3 changes: 2 additions & 1 deletion src/page/Error/PageNotFound/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ReactComponent as Error } from 'assets/svg/error/page-not-found-error.svg';
import { useNavigate } from 'react-router-dom';
import ROUTES from 'static/routes';
import styles from './PageNotFound.module.scss';

export default function PageNotFound() {
Expand All @@ -20,7 +21,7 @@ export default function PageNotFound() {
<button
type="button"
className={styles.content__button}
onClick={() => navigate('/owner')}
onClick={() => navigate(ROUTES.OWNER)}
>
메인 화면 바로가기
</button>
Expand Down
3 changes: 2 additions & 1 deletion src/page/ManageEvent/AddingEvent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ReactComponent as PictureDisalbe } from 'assets/svg/common/picture-disa
import { createPortal } from 'react-dom';
import AlertModal from 'component/common/Modal/alertModal';
import useLogger from 'utils/hooks/useLogger';
import ROUTES from 'static/routes';

/* eslint-disable no-await-in-loop */
/* eslint-disable jsx-a11y/label-has-associated-control */
Expand Down Expand Up @@ -419,7 +420,7 @@ export default function AddingEvent() {
setIsOpen={setIsAlertModalOpen}
cancelText="이어쓰기"
acceptText="취소하기"
callBack={() => navigate('/')}
callBack={() => navigate(ROUTES.MAIN)}
/>,
document.body,
)}
Expand Down
3 changes: 2 additions & 1 deletion src/page/ManageEvent/ModifyEvent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ReactComponent as Cancel } from 'assets/svg/common/cancel.svg';
import { ReactComponent as Picture } from 'assets/svg/common/picture.svg';
import { ReactComponent as PictureDisalbe } from 'assets/svg/common/picture-disable.svg';
import { createPortal } from 'react-dom';
import ROUTES from 'static/routes';

/* eslint-disable jsx-a11y/label-has-associated-control */

Expand Down Expand Up @@ -349,7 +350,7 @@ export default function ModifyEvent() {
setIsOpen={setIsAlertModalOpen}
cancelText="이어쓰기"
acceptText="취소하기"
callBack={() => navigate('/')}
callBack={() => navigate(ROUTES.MAIN)}
/>,
document.body,
)}
Expand Down
Loading

0 comments on commit e0dc176

Please sign in to comment.