diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 8806636c0..a307c65f3 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,16 +1,24 @@ import { Global, ThemeProvider } from '@emotion/react'; +import { useEffect, useMemo } from 'react'; + import { QueryClientProvider } from '@tanstack/react-query'; import { RouterProvider } from 'react-router-dom'; import createQueryClient from './queryClient'; import fonts from '@_common/font.style'; +import { removeInviteCode } from '@_common/inviteCodeManager'; import reset from './common/reset.style'; -import { useMemo } from 'react'; -import { theme } from '@_common/theme/theme.style'; import router from '@_routes/router'; +import { theme } from '@_common/theme/theme.style'; export default function App() { const queryClient = useMemo(createQueryClient, []); + useEffect(() => { + window.addEventListener('beforeunload', removeInviteCode); + + return window.removeEventListener('beforeunload', removeInviteCode); + }); + return ( diff --git a/frontend/src/apis/posts.ts b/frontend/src/apis/posts.ts index 119e9805c..98db1ebf3 100644 --- a/frontend/src/apis/posts.ts +++ b/frontend/src/apis/posts.ts @@ -104,10 +104,14 @@ export const postDarakbang = async ({ name: string; nickname: string; }) => { - await ApiClient.postWithAuth('darakbang', { + const response = await ApiClient.postWithAuth('darakbang', { name, nickname, }); + + const json = await response.json(); + + return json?.data; }; export const postDarakbangEntrance = async ({ diff --git a/frontend/src/common/getRoutes.ts b/frontend/src/common/getRoutes.ts new file mode 100644 index 000000000..52a20cf6f --- /dev/null +++ b/frontend/src/common/getRoutes.ts @@ -0,0 +1,29 @@ +import { getLastDarakbangId } from './lastDarakbangManager'; + +const getDarakbangIdRoute = (darakbangId: number) => + '/darakbang/' + darakbangId; + +const getNowDarakbangRoute = () => + getDarakbangIdRoute(getLastDarakbangId() || 0); + +const GET_ROUTES = { + nowDarakbang: { + main: () => getNowDarakbangRoute(), + addMoim: () => getNowDarakbangRoute() + '/add-moim', + moimDetail: (moimId: number) => getNowDarakbangRoute() + '/moim/' + moimId, + moimParticipateComplete: () => + getNowDarakbangRoute() + '/moim/participation-complete', + modify: (moimId: number) => getNowDarakbangRoute() + '/modify/' + moimId, + chat: () => getNowDarakbangRoute() + '/chat', + chattingRoom: (moimId: number) => + getNowDarakbangRoute() + '/chatting-room/' + moimId, + please: () => getNowDarakbangRoute() + '/please', + addPlease: () => getNowDarakbangRoute() + '/please/creation', + myPage: () => getNowDarakbangRoute() + '/my-page', + notification: () => getNowDarakbangRoute() + '/notification', + darakbangManagement: () => getNowDarakbangRoute() + '/darakbang-management', + darakbangMembers: () => getNowDarakbangRoute() + '/darakbang-members', + darakbangInvitation: () => getNowDarakbangRoute() + '/darakbang-invitation', + }, +}; +export default GET_ROUTES; diff --git a/frontend/src/common/inviteCodeManager.tsx b/frontend/src/common/inviteCodeManager.tsx new file mode 100644 index 000000000..dfba13861 --- /dev/null +++ b/frontend/src/common/inviteCodeManager.tsx @@ -0,0 +1,15 @@ +const INVITE_CODE_KEY = 'invite-code'; + +export const setInviteCode = (inviteCode: string): void => { + localStorage.setItem(INVITE_CODE_KEY, inviteCode); +}; + +export const getInviteCode = () => { + const inviteCode = localStorage.getItem(INVITE_CODE_KEY); + if (!inviteCode) return null; + return inviteCode; +}; + +export const removeInviteCode = () => { + localStorage.removeItem(INVITE_CODE_KEY); +}; diff --git a/frontend/src/components/MoimCardList/MoimCardList.tsx b/frontend/src/components/MoimCardList/MoimCardList.tsx index fcc04a5a3..822ea1a0d 100644 --- a/frontend/src/components/MoimCardList/MoimCardList.tsx +++ b/frontend/src/components/MoimCardList/MoimCardList.tsx @@ -1,8 +1,9 @@ import * as S from './MoimCardList.style'; +import GET_ROUTES from '@_common/getRoutes'; +import MoimCard from '../MoimCard/MoimCard'; import { MoimInfo } from '@_types/index'; import { useNavigate } from 'react-router-dom'; -import MoimCard from '../MoimCard/MoimCard'; interface MoimCardListProps { moimInfos: MoimInfo[]; @@ -14,7 +15,7 @@ export default function MoimCardList(props: MoimCardListProps) { const navigate = useNavigate(); const handleMoimCard = (moimId: number) => { - navigate(`/moim/${moimId}`); + navigate(GET_ROUTES.nowDarakbang.moimDetail(moimId)); }; return ( diff --git a/frontend/src/components/NavigationBar/NavigationBar.tsx b/frontend/src/components/NavigationBar/NavigationBar.tsx index 87788ff51..1489a0224 100644 --- a/frontend/src/components/NavigationBar/NavigationBar.tsx +++ b/frontend/src/components/NavigationBar/NavigationBar.tsx @@ -1,17 +1,19 @@ import * as S from './NavigationBar.style'; -import { useState } from 'react'; + +import { useLocation, useNavigate } from 'react-router-dom'; + +import GET_ROUTES from '@_common/getRoutes'; import NavigationBarItem from '@_components/NavigationBarItem/NavigationBarItem'; +import { useState } from 'react'; import { useTheme } from '@emotion/react'; -import { useLocation, useNavigate } from 'react-router-dom'; -import ROUTES from '@_constants/routes'; export type Tab = '홈' | '채팅' | '해주세요' | '마이페이지'; const tabRoutes: Record = { - 홈: ROUTES.main, - 채팅: ROUTES.chat, - 해주세요: ROUTES.please, - 마이페이지: ROUTES.myPage, + 홈: GET_ROUTES.nowDarakbang.main(), + 채팅: GET_ROUTES.nowDarakbang.chat(), + 해주세요: GET_ROUTES.nowDarakbang.addPlease(), + 마이페이지: GET_ROUTES.nowDarakbang.myPage(), }; export default function NavigationBar() { diff --git a/frontend/src/constants/routes.ts b/frontend/src/constants/routes.ts index 2385d2bad..3bab69c33 100644 --- a/frontend/src/constants/routes.ts +++ b/frontend/src/constants/routes.ts @@ -1,10 +1,12 @@ -const ROUTES = { - main: '/', +const addDarakbangPrefix = (route: string) => { + return '/darakbang/:darakbangId' + route; +}; + +const beforeUsingDarakbangPrefixRoutes = { + darakbangMain: '/', addMoim: '/add-moim', - detail: '/moim/:moimId', + moimDetail: '/moim/:moimId', participationComplete: '/moim/participation-complete', - home: '/home', - kakaoOAuth: '/kakao-o-auth', modify: '/modify/:moimId', chat: '/chat', chattingRoom: '/chatting-room/:moimId', @@ -12,16 +14,37 @@ const ROUTES = { addPlease: '/please/creation', myPage: '/my-page', notification: '/notification', + darakbangManagement: '/darakbang-management', + darakbangMembers: '/darakbang-members', + darakbangInvitation: '/darakbang-invitation', +}; + +const usingDarakbangPrefixRoutes = Object.entries( + beforeUsingDarakbangPrefixRoutes, +).reduce( + (object, [key, routes]) => { + object[key as keyof typeof beforeUsingDarakbangPrefixRoutes] = + addDarakbangPrefix(routes); + return object; + }, + {} as Record, +); + +const ROUTES = { + main: '/', + home: '/home', + kakaoOAuth: '/kakao-o-auth', + darakbangInvitationRoute: '/darakbang-invitation-route', + darakbangSelectOption: '/darakbang-select-option', darakbangSelect: '/darakbang-select', darakbangCreation: '/darakbang-creation', darakbangEntrance: '/darakbang-entrance', darakbangNickname: '/darakbang-nickname', darakbangLanding: '/darakbang-landing', - darakbangManagement: '/darakbang-management', - darakbangMembers: '/darakbang-members', - darakbangInvitation: '/darakbang-invitation', - darakbangInvitationRoute: '/darakbang-invitation-route', + + // /darakbang/:darakbangId/[루트] 형식 + ...usingDarakbangPrefixRoutes, }; export default ROUTES; diff --git a/frontend/src/hooks/mutaions/useCreateDarakbang.ts b/frontend/src/hooks/mutaions/useCreateDarakbang.ts index 2199ddaa5..2cf0cef8c 100644 --- a/frontend/src/hooks/mutaions/useCreateDarakbang.ts +++ b/frontend/src/hooks/mutaions/useCreateDarakbang.ts @@ -3,15 +3,15 @@ import { useMutation, useQueryClient } from '@tanstack/react-query'; import QUERY_KEYS from '@_constants/queryKeys'; import { postDarakbang } from '@_apis/posts'; -export default function useCreateDarakbang(onSuccess?: () => void) { +export default function useCreateDarakbang(onSuccess?: (id: number) => void) { const queryClient = useQueryClient(); return useMutation({ mutationFn: postDarakbang, - onSuccess: () => { + onSuccess: (id: number) => { queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.myDarakbangs] }); - if (onSuccess) onSuccess(); + if (onSuccess) onSuccess(id); }, }); } diff --git a/frontend/src/pages/ChatPage/ChatPage.tsx b/frontend/src/pages/ChatPage/ChatPage.tsx index 99eb77b8f..d9a021f1e 100644 --- a/frontend/src/pages/ChatPage/ChatPage.tsx +++ b/frontend/src/pages/ChatPage/ChatPage.tsx @@ -1,5 +1,6 @@ import ChattingPreview from '@_components/ChattingPreview/ChattingPreview'; import ChattingPreviewLayout from '@_layouts/ChattingPreviewLayout/ChattingPreviewLayout'; +import GET_ROUTES from '@_common/getRoutes'; import MissingFallback from '@_components/MissingFallback/MissingFallback'; import NavigationBar from '@_components/NavigationBar/NavigationBar'; import NavigationBarWrapper from '@_layouts/components/NavigationBarWrapper/NavigationBarWrapper'; @@ -24,7 +25,11 @@ export default function ChatPage() { chatPreviews?.map((chatPreview) => ( navigate('/chatting-room/' + chatPreview.moimId)} + onClick={() => + navigate( + GET_ROUTES.nowDarakbang.chattingRoom(chatPreview.moimId), + ) + } key={chatPreview.moimId} /> )) diff --git a/frontend/src/pages/DarakbangCreationPage/DarakbangCreationPage.tsx b/frontend/src/pages/DarakbangCreationPage/DarakbangCreationPage.tsx index 2be1d1393..6f243db90 100644 --- a/frontend/src/pages/DarakbangCreationPage/DarakbangCreationPage.tsx +++ b/frontend/src/pages/DarakbangCreationPage/DarakbangCreationPage.tsx @@ -5,12 +5,13 @@ import { ChangeEvent, useState } from 'react'; import Button from '@_components/Button/Button'; import DarakbangCreationModalContent from './DarakbangCreationModalContent/DarakbangCreationModalContent'; import ErrorControlledInput from '@_components/ErrorControlledInput/ErrorControlledInput'; +import GET_ROUTES from '@_common/getRoutes'; import HighlightSpan from '@_components/HighlightSpan/HighlightSpan'; import Modal from '@_components/Modal/Modal'; import POLICES from '@_constants/poclies'; -import ROUTES from '@_constants/routes'; import SelectLayout from '@_layouts/SelectLayout/SelectLayout'; import SolidArrow from '@_components/Icons/SolidArrow'; +import { setLastDarakbangId } from '@_common/lastDarakbangManager'; import useCreateDarakbang from '@_hooks/mutaions/useCreateDarakbang'; import { useNavigate } from 'react-router-dom'; import { useTheme } from '@emotion/react'; @@ -18,8 +19,11 @@ import { useTheme } from '@emotion/react'; export default function DarakbangCreationPage() { const theme = useTheme(); const navigate = useNavigate(); - const { mutate: createDarakbang } = useCreateDarakbang(() => - navigate(ROUTES.main), + const { mutate: createDarakbang } = useCreateDarakbang( + (darakbangId: number) => { + setLastDarakbangId(darakbangId); + navigate(GET_ROUTES.nowDarakbang.main()); + }, ); const [darakbangName, setDarakbangName] = useState(''); diff --git a/frontend/src/pages/DarakbangEntrancePage/DarakbangEntrancePage.tsx b/frontend/src/pages/DarakbangEntrancePage/DarakbangEntrancePage.tsx index 1d5503c44..7da481172 100644 --- a/frontend/src/pages/DarakbangEntrancePage/DarakbangEntrancePage.tsx +++ b/frontend/src/pages/DarakbangEntrancePage/DarakbangEntrancePage.tsx @@ -3,6 +3,7 @@ import { ChangeEvent, useState } from 'react'; import Button from '@_components/Button/Button'; import ErrorControlledInput from '@_components/ErrorControlledInput/ErrorControlledInput'; import POLICES from '@_constants/poclies'; +import ROUTES from '@_constants/routes'; import SelectLayout from '@_layouts/SelectLayout/SelectLayout'; import SolidArrow from '@_components/Icons/SolidArrow'; import { useNavigate } from 'react-router-dom'; @@ -11,7 +12,7 @@ import { useTheme } from '@emotion/react'; export default function DarakbangEntrancePage() { const theme = useTheme(); const navigate = useNavigate(); - const [entranceCode, setEntranceCode] = useState(''); + const [inviteCode, setInviteCode] = useState(''); return ( @@ -33,7 +34,7 @@ export default function DarakbangEntrancePage() { placeholder="참여코드를 입력하세요" maxLength={POLICES.entranceCodeLength} onChange={(e: ChangeEvent) => { - setEntranceCode(e.target.value.toUpperCase()); + setInviteCode(e.target.value.toUpperCase()); }} style={{ textTransform: 'uppercase' }} /> @@ -42,7 +43,10 @@ export default function DarakbangEntrancePage() { diff --git a/frontend/src/pages/DarakbangManagementPage/DarakbangManagementPage.tsx b/frontend/src/pages/DarakbangManagementPage/DarakbangManagementPage.tsx index eb2726c64..d20287ebe 100644 --- a/frontend/src/pages/DarakbangManagementPage/DarakbangManagementPage.tsx +++ b/frontend/src/pages/DarakbangManagementPage/DarakbangManagementPage.tsx @@ -1,5 +1,5 @@ +import GET_ROUTES from '@_common/getRoutes'; import MenuItem from '@_components/MenuItem/MenuItem'; -import ROUTES from '@_constants/routes'; import SolidArrow from '@_components/Icons/SolidArrow'; import TriSectionHeader from '@_layouts/components/TriSectionHeader/TriSectionHeader'; import { useNavigate } from 'react-router-dom'; @@ -16,11 +16,11 @@ export default function DarakbangManagementPage() { navigate(ROUTES.darakbangMembers)} + onClick={() => navigate(GET_ROUTES.nowDarakbang.darakbangMembers())} /> navigate(ROUTES.darakbangInvitation)} + onClick={() => navigate(GET_ROUTES.nowDarakbang.darakbangInvitation())} isLastItem /> diff --git a/frontend/src/pages/DarakbangNicknamePage/DarakbangNicknamePage.tsx b/frontend/src/pages/DarakbangNicknamePage/DarakbangNicknamePage.tsx index 5e8befdf2..79ec47e81 100644 --- a/frontend/src/pages/DarakbangNicknamePage/DarakbangNicknamePage.tsx +++ b/frontend/src/pages/DarakbangNicknamePage/DarakbangNicknamePage.tsx @@ -1,24 +1,24 @@ import { ChangeEvent, useState } from 'react'; -import { useLocation, useNavigate } from 'react-router-dom'; +import { getInviteCode, removeInviteCode } from '@_common/inviteCodeManager'; import Button from '@_components/Button/Button'; import DarakbangNicknameModalContent from './DarakbangNicknameModalContent/DarakbangNicknameModalContent'; import ErrorControlledInput from '@_components/ErrorControlledInput/ErrorControlledInput'; +import GET_ROUTES from '@_common/getRoutes'; import HighlightSpan from '@_components/HighlightSpan/HighlightSpan'; import Modal from '@_components/Modal/Modal'; import POLICES from '@_constants/poclies'; -import ROUTES from '@_constants/routes'; import SolidArrow from '@_components/Icons/SolidArrow'; import StickyTriSectionHeader from '@_layouts/components/StickyTriSectionHeader/StickyTriSectionHeader'; import StretchContentLayout from '@_layouts/StretchContentLayout/StretchContentLayout'; import useDarakbangNameByCode from '@_hooks/queries/useDarakbangNameByCode'; import useEnterDarakbang from '@_hooks/mutaions/useEnterDarakbang'; +import { useNavigate } from 'react-router-dom'; export default function DarakbangNicknamePage() { const navigate = useNavigate(); - const { state } = useLocation(); - const { code = 'NULL' } = state; + const code = getInviteCode() || ''; const { darakbangName = '' } = useDarakbangNameByCode(code); const [nickname, setNickName] = useState(''); @@ -27,7 +27,8 @@ export default function DarakbangNicknamePage() { const { mutate: enterDarakbang } = useEnterDarakbang({ onSuccess: () => { - navigate(ROUTES.main); + removeInviteCode(); + navigate(GET_ROUTES.nowDarakbang.main()); }, onError: (string: string) => { setIsModalOpen(false); diff --git a/frontend/src/pages/DarakbangSelectPage/DarakbangSelectPage.tsx b/frontend/src/pages/DarakbangSelectPage/DarakbangSelectPage.tsx index 409764cf2..7490ec525 100644 --- a/frontend/src/pages/DarakbangSelectPage/DarakbangSelectPage.tsx +++ b/frontend/src/pages/DarakbangSelectPage/DarakbangSelectPage.tsx @@ -1,5 +1,6 @@ import * as S from './DarakbangSelectPage.style'; +import GET_ROUTES from '@_common/getRoutes'; import HighlightSpan from '@_components/HighlightSpan/HighlightSpan'; import MissingFallback from '@_components/MissingFallback/MissingFallback'; import ROUTES from '@_constants/routes'; @@ -46,7 +47,7 @@ export default function DarakbangSelectPage() { key={darakbangId} onClick={() => { setLastDarakbangId(darakbangId); - navigate(ROUTES.main); + navigate(GET_ROUTES.nowDarakbang.main()); }} > {name} diff --git a/frontend/src/pages/HomePage/HomePage.tsx b/frontend/src/pages/HomePage/HomePage.tsx index f4491df53..dbd3b3048 100644 --- a/frontend/src/pages/HomePage/HomePage.tsx +++ b/frontend/src/pages/HomePage/HomePage.tsx @@ -1,10 +1,30 @@ +import { css, useTheme } from '@emotion/react'; + +import GET_ROUTES from '@_common/getRoutes'; import KakaoOAuthLoginIcon from '@_components/Icons/KakaoOAuthIcon'; -import MainLogoIcon from '@_components/Icons/MainLogoIcon'; import LoginLayout from '@_layouts/LoginLayout/LoginLayout'; -import { css, useTheme } from '@emotion/react'; +import MainLogoIcon from '@_components/Icons/MainLogoIcon'; +import ROUTES from '@_constants/routes'; +import { getLastDarakbangId } from '@_common/lastDarakbangManager'; +import { getToken } from '@_utils/tokenManager'; +import { useNavigate } from 'react-router-dom'; export default function HomePage() { const theme = useTheme(); + const navigate = useNavigate(); + const nowToken = getToken(); + + if (nowToken) { + const lastDarakbangId = getLastDarakbangId(); + if (lastDarakbangId) { + navigate(GET_ROUTES.nowDarakbang.main()); + return null; + } + if (!lastDarakbangId) { + navigate(ROUTES.darakbangSelectOption); + return null; + } + } const kakaoAuthLogin = () => { if ( diff --git a/frontend/src/pages/KakaoOAuthLoginPage/KakaoOAuthLoginPage.tsx b/frontend/src/pages/KakaoOAuthLoginPage/KakaoOAuthLoginPage.tsx index c17948df5..cb8c5c7ed 100644 --- a/frontend/src/pages/KakaoOAuthLoginPage/KakaoOAuthLoginPage.tsx +++ b/frontend/src/pages/KakaoOAuthLoginPage/KakaoOAuthLoginPage.tsx @@ -1,4 +1,5 @@ import ROUTES from '@_constants/routes'; +import { getInviteCode } from '@_common/inviteCodeManager'; import { kakaoOAuth } from '@_apis/auth'; import { requestPermission } from '@_service/notification'; import { setToken } from '@_utils/tokenManager'; @@ -8,23 +9,32 @@ import useServeToken from '@_hooks/mutaions/useServeToken'; export default function KakaoOAuthLoginPage() { const navigate = useNavigate(); - const { mutate } = useServeToken(); + const { mutate: serveToken } = useServeToken(); useEffect(() => { const loginKakaoOAuth = async () => { const code = new URL(window.location.href).searchParams.get('code'); + if (code === null) { + alert('잘못된 접근입니다'); + navigate(ROUTES.home); return; } const response = await kakaoOAuth(code); setToken(response.data.accessToken); - requestPermission(mutate); - navigate(ROUTES.darakbangSelectOption); + requestPermission(serveToken); + const inviteCode = getInviteCode(); + if (inviteCode) { + navigate(`${ROUTES.darakbangInvitationRoute}?code=${inviteCode}`); + } + if (!inviteCode) { + navigate(ROUTES.darakbangSelectOption); + } }; loginKakaoOAuth(); - }, [navigate, mutate]); + }, [navigate, serveToken]); return null; } diff --git a/frontend/src/pages/MainPage/MainPage.tsx b/frontend/src/pages/MainPage/MainPage.tsx index fb591b0c6..7703101b2 100644 --- a/frontend/src/pages/MainPage/MainPage.tsx +++ b/frontend/src/pages/MainPage/MainPage.tsx @@ -10,6 +10,7 @@ import { setLastDarakbangId, } from '@_common/lastDarakbangManager'; +import GET_ROUTES from '@_common/getRoutes'; import HomeLayout from '@_layouts/HomeLayout.tsx/HomeLayout'; import HomeMainContent from '@_components/HomeMainContent/HomeMainContent'; import NavigationBar from '@_components/NavigationBar/NavigationBar'; @@ -40,7 +41,7 @@ export default function MainPage() { }; const handleNotification = () => { - navigate(ROUTES.notification); + navigate(GET_ROUTES.nowDarakbang.notification()); requestPermission(mutate); }; @@ -51,7 +52,7 @@ export default function MainPage() { return { onClick: () => { setLastDarakbangId(darakbangId); - navigate(ROUTES.main); + navigate(GET_ROUTES.nowDarakbang.main()); }, description: name + (darakbangId === nowDarakbangId ? '(현재 다락방)' : ''), @@ -61,7 +62,7 @@ export default function MainPage() { options.push( { onClick: () => navigate(ROUTES.darakbangEntrance), - description: '다른 다락방 들어가기', + description: '코드로 다른 다락방 들어가기', hasTopBorder: true, }, { @@ -73,7 +74,7 @@ export default function MainPage() { if (myRoleInNowDarakbang === 'MANAGER') { options.push({ - onClick: () => navigate(ROUTES.darakbangManagement), + onClick: () => navigate(GET_ROUTES.nowDarakbang.darakbangManagement()), description: '다락방 관리하기', hasTopBorder: true, }); @@ -134,7 +135,9 @@ export default function MainPage() { - navigate(ROUTES.addMoim)} /> + navigate(GET_ROUTES.nowDarakbang.addMoim())} + /> diff --git a/frontend/src/pages/MoimCreationPage/MoimCreationPage.tsx b/frontend/src/pages/MoimCreationPage/MoimCreationPage.tsx index 388f09ffc..bb74b1310 100644 --- a/frontend/src/pages/MoimCreationPage/MoimCreationPage.tsx +++ b/frontend/src/pages/MoimCreationPage/MoimCreationPage.tsx @@ -1,3 +1,4 @@ + import BackArrowButton from '@_components/BackArrowButton/BackArrowButton'; import FunnelStepIndicator from '@_components/Funnel/FunnelStepIndicator/FunnelStepIndicator'; import FunnelLayout from '@_layouts/FunnelLayout/FunnelLayout'; @@ -52,6 +53,7 @@ export default function MoimCreationPage() { 모임 만들기 + { - navigate(ROUTES.participationComplete); + navigate(GET_ROUTES.nowDarakbang.moimParticipateComplete()); }); const { mutate: cancelMoim } = useCancelMoim(); @@ -44,7 +44,7 @@ export default function MoimDetailPage() { const { mutate: completeMoim } = useCompleteMoin(); const { mutate: cancelChamyo } = useCancelChamyo(); const { mutate: openChat } = useOpenChat(() => - navigate(`/chatting-room/${moimId}`), + navigate(GET_ROUTES.nowDarakbang.chattingRoom(moimId)), ); if ( @@ -62,7 +62,7 @@ export default function MoimDetailPage() { -
navigate(ROUTES.main)}> +
navigate(GET_ROUTES.nowDarakbang.main())}>
@@ -74,7 +74,7 @@ export default function MoimDetailPage() { { name: '모임 수정하기', onClick: () => - navigate(`/modify/${moimId}`, { + navigate(GET_ROUTES.nowDarakbang.modify(moimId), { state: { ...moim, moimId, @@ -148,13 +148,15 @@ export default function MoimDetailPage() { ) ) : moim.status === 'MOIMING' ? ( ) : ( diff --git a/frontend/src/pages/MoimModifyPage/MoimModifyPage.tsx b/frontend/src/pages/MoimModifyPage/MoimModifyPage.tsx index bec045d17..808d10eb9 100644 --- a/frontend/src/pages/MoimModifyPage/MoimModifyPage.tsx +++ b/frontend/src/pages/MoimModifyPage/MoimModifyPage.tsx @@ -1,19 +1,21 @@ +import { MoimInfo, MoimInputInfo } from '@_types/index'; +import { useLocation, useNavigate } from 'react-router-dom'; + import Button from '@_components/Button/Button'; import FormLayout from '@_layouts/FormLayout/FormLayout'; +import GET_ROUTES from '@_common/getRoutes'; import LabeledInput from '@_components/Input/MoimInput'; import MOIM_INPUT_INFOS from './MoimModifyPage.constant'; +import useModifyMoim from '@_hooks/mutaions/useModifyMoim'; import useMoimInfoInput from './MoimModifyPage.hook'; -import { useLocation, useNavigate } from 'react-router-dom'; import { useState } from 'react'; -import useModifyMoim from '@_hooks/mutaions/useModifyMoim'; -import { MoimInfo, MoimInputInfo } from '@_types/index'; export default function MoimModifyPage() { const navigate = useNavigate(); const location = useLocation(); const state = location.state as MoimInfo; const { mutate: modifyMoim } = useModifyMoim((moimId: number) => { - navigate(`/moim/${moimId}`); + navigate(GET_ROUTES.nowDarakbang.moimDetail(moimId)); }); const [isSubmitted, setIsSubmitted] = useState(false); diff --git a/frontend/src/pages/NotificationPage/NotificationPage.tsx b/frontend/src/pages/NotificationPage/NotificationPage.tsx index 39d05fee8..925e0cfe5 100644 --- a/frontend/src/pages/NotificationPage/NotificationPage.tsx +++ b/frontend/src/pages/NotificationPage/NotificationPage.tsx @@ -1,9 +1,10 @@ -import ROUTES from '@_constants/routes'; -import InformationLayout from '@_layouts/InformationLayout/InformationLayout'; import BackLogo from '@_common/assets/back.svg'; -import { useNavigate } from 'react-router-dom'; +import GET_ROUTES from '@_common/getRoutes'; +import InformationLayout from '@_layouts/InformationLayout/InformationLayout'; import NotificationList from '@_components/NotificationList/NotificationList'; +import { useNavigate } from 'react-router-dom'; import useNotification from '@_hooks/queries/useNotification'; + export default function NotificationPage() { const navigate = useNavigate(); const { notifications, isLoading } = useNotification(); @@ -17,7 +18,7 @@ export default function NotificationPage() { -
navigate(ROUTES.main)}> +
navigate(GET_ROUTES.nowDarakbang.main())}>
diff --git a/frontend/src/pages/PleaseCreationPage/PleaseCreationPage.tsx b/frontend/src/pages/PleaseCreationPage/PleaseCreationPage.tsx index de3cb8ef6..2e1e9a2cd 100644 --- a/frontend/src/pages/PleaseCreationPage/PleaseCreationPage.tsx +++ b/frontend/src/pages/PleaseCreationPage/PleaseCreationPage.tsx @@ -1,20 +1,21 @@ +import * as S from './PleaseCreationPage.style'; + import Button from '@_components/Button/Button'; import FormLayout from '@_layouts/FormLayout/FormLayout'; +import GET_ROUTES from '@_common/getRoutes'; import LabeledInput from '@_components/Input/MoimInput'; -import usePleaseInfoInput from './PleaseCreationPage.hook'; -import { useNavigate } from 'react-router-dom'; -import { useState } from 'react'; -import ROUTES from '@_constants/routes'; +import LabeledTextArea from '@_components/TextArea/LabeledTextArea'; import PLEASE_INPUT_INFOS from './PleaseCreationPage.constant'; import useAddPlease from '@_hooks/mutaions/useAddPlease'; -import LabeledTextArea from '@_components/TextArea/LabeledTextArea'; -import * as S from './PleaseCreationPage.style'; +import { useNavigate } from 'react-router-dom'; +import usePleaseInfoInput from './PleaseCreationPage.hook'; +import { useState } from 'react'; export default function PleaseCreationPage() { const navigate = useNavigate(); const [isSubmitted, setIsSubmitted] = useState(false); const { mutate } = useAddPlease(() => { - navigate(ROUTES.please); + navigate(GET_ROUTES.nowDarakbang.please()); }); const { @@ -35,7 +36,7 @@ export default function PleaseCreationPage() { return ( - navigate(ROUTES.main)}> + navigate(-1)}> 해주세요 만들기 diff --git a/frontend/src/pages/PleasePage/PleasePage.tsx b/frontend/src/pages/PleasePage/PleasePage.tsx index 05a6dbc39..41fd0814e 100644 --- a/frontend/src/pages/PleasePage/PleasePage.tsx +++ b/frontend/src/pages/PleasePage/PleasePage.tsx @@ -1,10 +1,10 @@ import { Fragment } from 'react'; +import GET_ROUTES from '@_common/getRoutes'; import NavigationBar from '@_components/NavigationBar/NavigationBar'; import NavigationBarWrapper from '@_layouts/components/NavigationBarWrapper/NavigationBarWrapper'; import PleaseLayout from '@_layouts/PleaseLayout/PleaseLayout'; import PleaseList from '@_components/PleaseList/PleaseList'; import PlusButton from '@_components/PlusButton/PlusButton'; -import ROUTES from '@_constants/routes'; import { common } from '@_common/common.style'; import { useNavigate } from 'react-router-dom'; import { useTheme } from '@emotion/react'; @@ -25,7 +25,9 @@ export default function PleasePage() { - navigate(ROUTES.addPlease)} /> + navigate(GET_ROUTES.nowDarakbang.addPlease())} + /> diff --git a/frontend/src/routes/DarakbangInvitationRoute.tsx b/frontend/src/routes/DarakbangInvitationRoute.tsx index 55e87b7e7..c04a063be 100644 --- a/frontend/src/routes/DarakbangInvitationRoute.tsx +++ b/frontend/src/routes/DarakbangInvitationRoute.tsx @@ -1,3 +1,4 @@ +import { removeInviteCode, setInviteCode } from '@_common/inviteCodeManager'; import { useNavigate, useSearchParams } from 'react-router-dom'; import Button from '@_components/Button/Button'; @@ -15,22 +16,26 @@ export default function DarakbangInvitationRoute() { const isRightCode = darakbangName !== ''; if (isLoading) return null; if (isRightCode) { - navigate(ROUTES.darakbangNickname, { state: { code } }); + if (code) setInviteCode(code); + navigate(ROUTES.darakbangNickname); + return null; + } + if (!isRightCode) { + removeInviteCode(); + return ( + + + + + + + + + ); } - - return ( - - - - - - - - - ); } diff --git a/frontend/src/routes/SlashRoute.tsx b/frontend/src/routes/SlashRoute.tsx new file mode 100644 index 000000000..d48044003 --- /dev/null +++ b/frontend/src/routes/SlashRoute.tsx @@ -0,0 +1,25 @@ +import GET_ROUTES from '@_common/getRoutes'; +import { Navigate } from 'react-router-dom'; +import ROUTES from '@_constants/routes'; +import { getLastDarakbangId } from '@_common/lastDarakbangManager'; +import { getToken } from '@_utils/tokenManager'; + +export default function SlashRoute() { + const token = getToken(); + const lastDarakbangId = getLastDarakbangId(); + + if (token) { + if (lastDarakbangId) { + return ; + } + if (!lastDarakbangId) { + return ; + } + } + + if (!token) { + return ; + } + + return ; +} diff --git a/frontend/src/routes/router.tsx b/frontend/src/routes/router.tsx index 97e52c21e..0ebcdc3b4 100644 --- a/frontend/src/routes/router.tsx +++ b/frontend/src/routes/router.tsx @@ -23,11 +23,17 @@ import PleaseCreationPage from '@_pages/PleaseCreationPage/PleaseCreationPage'; import PleasePage from '@_pages/PleasePage/PleasePage'; import ProtectedRoute from './ProtectedRoute'; import ROUTES from '@_constants/routes'; +import SlashRoute from './SlashRoute'; import { createBrowserRouter } from 'react-router-dom'; const routesConfig = [ { path: ROUTES.main, + element: , + requiresAuth: false, + }, + { + path: ROUTES.darakbangMain, element: , requiresAuth: true, }, @@ -37,7 +43,7 @@ const routesConfig = [ requiresAuth: true, }, { - path: ROUTES.detail, + path: ROUTES.moimDetail, element: , requiresAuth: true, },