From 69c68d807c66408271fbb22a9836c339132658ba Mon Sep 17 00:00:00 2001 From: Leejin-Yang Date: Thu, 19 Oct 2023 16:14:30 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=BF=80=EC=A1=B0=ED=95=A9=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=A0=91=EC=86=8D=20=EC=8B=9C=20=EC=9D=B4?= =?UTF-8?q?=EC=A0=84=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EB=A1=9C=EC=BB=AC?= =?UTF-8?q?=EC=8A=A4=ED=86=A0=EB=A6=AC=EC=A7=80=EC=97=90=20=EA=B2=BD?= =?UTF-8?q?=EB=A1=9C=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/constants/index.ts | 2 +- frontend/src/mocks/handlers/recipeHandlers.ts | 6 ++++++ frontend/src/pages/AuthPage.tsx | 8 ++++---- frontend/src/pages/ProductDetailPage.tsx | 4 ++-- frontend/src/pages/RecipePage.tsx | 12 +++++++++--- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/frontend/src/constants/index.ts b/frontend/src/constants/index.ts index 22c296123..8865b2802 100644 --- a/frontend/src/constants/index.ts +++ b/frontend/src/constants/index.ts @@ -72,4 +72,4 @@ export const ENVIRONMENT = window.location.href.includes('dev') export const IMAGE_URL = ENVIRONMENT === 'dev' ? process.env.S3_DEV_CLOUDFRONT_PATH : process.env.S3_PROD_CLOUDFRONT_PATH; -export const PRODUCT_PATH_LOCAL_STORAGE_KEY = `funeat-last-product-path-${ENVIRONMENT}`; +export const PREVIOUS_PATH_LOCAL_STORAGE_KEY = `funeat-previous-path-${ENVIRONMENT}`; diff --git a/frontend/src/mocks/handlers/recipeHandlers.ts b/frontend/src/mocks/handlers/recipeHandlers.ts index b213e5926..fff47a879 100644 --- a/frontend/src/mocks/handlers/recipeHandlers.ts +++ b/frontend/src/mocks/handlers/recipeHandlers.ts @@ -7,6 +7,12 @@ import mockRecipes from '../data/recipes.json'; export const recipeHandlers = [ rest.get('/api/recipes/:recipeId', (req, res, ctx) => { + const { mockSessionId } = req.cookies; + + if (!mockSessionId) { + return res(ctx.status(401)); + } + return res(ctx.status(200), ctx.json(recipeDetail), ctx.delay(1000)); }), diff --git a/frontend/src/pages/AuthPage.tsx b/frontend/src/pages/AuthPage.tsx index 579bca327..9f7974e45 100644 --- a/frontend/src/pages/AuthPage.tsx +++ b/frontend/src/pages/AuthPage.tsx @@ -2,7 +2,7 @@ import { useEffect, useState } from 'react'; import { Navigate, useNavigate, useParams, useSearchParams } from 'react-router-dom'; import { loginApi } from '@/apis'; -import { PRODUCT_PATH_LOCAL_STORAGE_KEY } from '@/constants'; +import { PREVIOUS_PATH_LOCAL_STORAGE_KEY } from '@/constants'; import { PATH } from '@/constants/path'; import { useMemberQuery } from '@/hooks/queries/members'; import { getLocalStorage, removeLocalStorage } from '@/utils/localStorage'; @@ -49,11 +49,11 @@ export const AuthPage = () => { return; } - const productPath = getLocalStorage(PRODUCT_PATH_LOCAL_STORAGE_KEY); - const redirectLocation = productPath ? productPath : location; + const previousPath = getLocalStorage(PREVIOUS_PATH_LOCAL_STORAGE_KEY); + const redirectLocation = previousPath ? previousPath : location; navigate(redirectLocation, { replace: true }); - removeLocalStorage(PRODUCT_PATH_LOCAL_STORAGE_KEY); + removeLocalStorage(PREVIOUS_PATH_LOCAL_STORAGE_KEY); refetchMember(); }, [location]); diff --git a/frontend/src/pages/ProductDetailPage.tsx b/frontend/src/pages/ProductDetailPage.tsx index 6471af213..5b6bbca20 100644 --- a/frontend/src/pages/ProductDetailPage.tsx +++ b/frontend/src/pages/ProductDetailPage.tsx @@ -17,7 +17,7 @@ import { } from '@/components/Common'; import { ProductDetailItem, ProductRecipeList } from '@/components/Product'; import { BestReviewItem, ReviewList, ReviewRegisterForm } from '@/components/Review'; -import { PRODUCT_PATH_LOCAL_STORAGE_KEY, RECIPE_SORT_OPTIONS, REVIEW_SORT_OPTIONS } from '@/constants'; +import { PREVIOUS_PATH_LOCAL_STORAGE_KEY, RECIPE_SORT_OPTIONS, REVIEW_SORT_OPTIONS } from '@/constants'; import { PATH } from '@/constants/path'; import ReviewFormProvider from '@/contexts/ReviewFormContext'; import { useGA, useSortOption, useTabMenu } from '@/hooks/common'; @@ -78,7 +78,7 @@ export const ProductDetailPage = () => { }; const handleLoginButtonClick = () => { - setLocalStorage(PRODUCT_PATH_LOCAL_STORAGE_KEY, pathname); + setLocalStorage(PREVIOUS_PATH_LOCAL_STORAGE_KEY, pathname); navigate(PATH.LOGIN); }; diff --git a/frontend/src/pages/RecipePage.tsx b/frontend/src/pages/RecipePage.tsx index bd8b9453e..fb7899a1b 100644 --- a/frontend/src/pages/RecipePage.tsx +++ b/frontend/src/pages/RecipePage.tsx @@ -1,7 +1,7 @@ import { BottomSheet, Heading, Link, Spacing, useBottomSheet } from '@fun-eat/design-system'; import { useQueryErrorResetBoundary } from '@tanstack/react-query'; -import { Suspense, useRef, useState } from 'react'; -import { Link as RouterLink } from 'react-router-dom'; +import { Suspense, useEffect, useRef, useState } from 'react'; +import { Link as RouterLink, useLocation } from 'react-router-dom'; import styled from 'styled-components'; import { @@ -15,10 +15,11 @@ import { SvgIcon, } from '@/components/Common'; import { RecipeList, RecipeRegisterForm } from '@/components/Recipe'; -import { RECIPE_SORT_OPTIONS } from '@/constants'; +import { PREVIOUS_PATH_LOCAL_STORAGE_KEY, RECIPE_SORT_OPTIONS } from '@/constants'; import { PATH } from '@/constants/path'; import RecipeFormProvider from '@/contexts/RecipeFormContext'; import { useGA, useSortOption } from '@/hooks/common'; +import { setLocalStorage } from '@/utils/localStorage'; const RECIPE_PAGE_TITLE = '🍯 꿀조합'; const REGISTER_RECIPE = '꿀조합 작성하기'; @@ -30,9 +31,14 @@ export const RecipePage = () => { const { isOpen, isClosing, handleOpenBottomSheet, handleCloseBottomSheet } = useBottomSheet(); const { reset } = useQueryErrorResetBoundary(); const { gaEvent } = useGA(); + const { pathname } = useLocation(); const recipeRef = useRef(null); + useEffect(() => { + setLocalStorage(PREVIOUS_PATH_LOCAL_STORAGE_KEY, pathname); + }, []); + const handleOpenRegisterRecipeSheet = () => { setActiveSheet('registerRecipe'); handleOpenBottomSheet();