From 0212dba92cd16ea80dc2ae89f1f234cca272d5cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=89=E1=85=A9=E1=86=AB=E1=84=8C=E1=85=B5=E1=86=AB?= =?UTF-8?q?=E1=84=8B=E1=85=A7=E1=86=BC?= Date: Sat, 3 Aug 2024 18:47:41 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=97=AC=ED=96=89=20=EC=A0=84=ED=99=98?= =?UTF-8?q?=20=ED=9B=84=20=EB=8B=A4=EB=A5=B8=20=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EB=8B=A4=EC=8B=9C=20=EB=93=B1=EB=A1=9D=20?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=EB=A1=9C=20=EC=A0=91=EA=B7=BC=20?= =?UTF-8?q?=EC=8B=9C=20=EB=8D=B0=EC=9D=B4=ED=84=B0=EA=B0=80=20=EB=82=A8?= =?UTF-8?q?=EC=95=84=EC=9E=88=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 페이지를 벗어나면 transformDetail를 null로 변경 --- .../pages/travelPlanRegister/TravelPlanRegisterPage.tsx | 7 +++++-- .../pages/travelogueDetail/TravelogueDetailPage.tsx | 2 +- .../pages/travelogueRegister/TravelogueRegisterPage.tsx | 6 ++++++ frontend/src/contexts/TravelTransformDetailProvider.tsx | 8 +++++--- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/pages/travelPlanRegister/TravelPlanRegisterPage.tsx b/frontend/src/components/pages/travelPlanRegister/TravelPlanRegisterPage.tsx index 39e97093..a5f77b35 100644 --- a/frontend/src/components/pages/travelPlanRegister/TravelPlanRegisterPage.tsx +++ b/frontend/src/components/pages/travelPlanRegister/TravelPlanRegisterPage.tsx @@ -28,7 +28,7 @@ import * as S from "./TravelPlanRegisterPage.styled"; const MAX_TITLE_LENGTH = 20; const TravelPlanRegisterPage = () => { - const { transformDetail } = useTravelTransformDetailContext(); + const { transformDetail, saveTransformDetail } = useTravelTransformDetailContext(); const [title, setTitle] = useState(""); const [startDate, setStartDate] = useState(null); @@ -101,7 +101,10 @@ const TravelPlanRegisterPage = () => { alert(ERROR_MESSAGE_MAP.api.login); navigate(ROUTE_PATHS_MAP.login); } - }, [user?.accessToken, navigate]); + return () => { + saveTransformDetail(null); + }; + }, [user?.accessToken, navigate, saveTransformDetail]); return ( <> diff --git a/frontend/src/components/pages/travelogueDetail/TravelogueDetailPage.tsx b/frontend/src/components/pages/travelogueDetail/TravelogueDetailPage.tsx index 5b9df343..881a66ae 100644 --- a/frontend/src/components/pages/travelogueDetail/TravelogueDetailPage.tsx +++ b/frontend/src/components/pages/travelogueDetail/TravelogueDetailPage.tsx @@ -56,7 +56,7 @@ const TravelogueDetailPage = () => { )} /> onTransformTravelDetail("/travel-plans/register", data)} + onTransform={() => onTransformTravelDetail("/travel-plan/register", data)} buttonLabel="여행 계획으로 전환" > 이 여행기를 따라가고 싶으신가요? diff --git a/frontend/src/components/pages/travelogueRegister/TravelogueRegisterPage.tsx b/frontend/src/components/pages/travelogueRegister/TravelogueRegisterPage.tsx index 0e0afb13..b3508e61 100644 --- a/frontend/src/components/pages/travelogueRegister/TravelogueRegisterPage.tsx +++ b/frontend/src/components/pages/travelogueRegister/TravelogueRegisterPage.tsx @@ -91,11 +91,17 @@ const TravelogueRegisterPage = () => { const { user } = useUser(); + const { saveTransformDetail } = useTravelTransformDetailContext(); + useEffect(() => { if (!user?.accessToken) { alert(ERROR_MESSAGE_MAP.api.login); navigate(ROUTE_PATHS_MAP.login); } + + return () => { + saveTransformDetail(null); + }; }, [user?.accessToken, navigate]); return ( diff --git a/frontend/src/contexts/TravelTransformDetailProvider.tsx b/frontend/src/contexts/TravelTransformDetailProvider.tsx index 4343e9bd..e59636e8 100644 --- a/frontend/src/contexts/TravelTransformDetailProvider.tsx +++ b/frontend/src/contexts/TravelTransformDetailProvider.tsx @@ -11,14 +11,16 @@ import { ERROR_MESSAGE_MAP } from "@constants/errorMessage"; import { ROUTE_PATHS_MAP } from "@constants/route"; const TravelogueContext = createContext(null); -const SaveTravelogueContext = createContext<(travelogue: TravelTransformDetail) => void>(() => {}); +const SaveTravelogueContext = createContext<(travelogue: TravelTransformDetail | null) => void>( + () => {}, +); export const TravelTransformDetailProvider = ({ children }: React.PropsWithChildren) => { const [travelTransformDetail, setTravelTransformDetail] = useState( null, ); - const saveTravelTransformDetail = (transformDetail: TravelTransformDetail) => { + const saveTravelTransformDetail = (transformDetail: TravelTransformDetail | null) => { setTravelTransformDetail(transformDetail); }; @@ -51,5 +53,5 @@ export const useTravelTransformDetailContext = () => { } }; - return { transformDetail, onTransformTravelDetail }; + return { transformDetail, saveTransformDetail, onTransformTravelDetail }; };