From eb6278cda9051b28cad6949d2898a16abcf2a0c2 Mon Sep 17 00:00:00 2001 From: river <130737187+0jenn0@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:07:11 +0900 Subject: [PATCH] =?UTF-8?q?feat(getInitialTravelTitle):=20=EC=A0=9C?= =?UTF-8?q?=EB=AA=A9=20=EC=B4=88=EA=B8=B0=EA=B0=92=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=9E=90=20=EB=8B=89=EB=84=A4=EC=9E=84=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 사용자 닉네임을 삭제하면서 훅이 아니게되어 함수이름을 useInitialTravelTitle에서 getInitialTravelTitle로 수정하고 util 폴더로 이동 시켰습니다. --- .../TravelogueRegisterPage.tsx | 5 ++-- frontend/src/hooks/pages/useTravelPlanForm.ts | 5 ++-- frontend/src/hooks/useInitialTravelTitle.ts | 30 ------------------- frontend/src/utils/getInitialTravelTitle.ts | 21 +++++++++++++ 4 files changed, 27 insertions(+), 34 deletions(-) delete mode 100644 frontend/src/hooks/useInitialTravelTitle.ts create mode 100644 frontend/src/utils/getInitialTravelTitle.ts diff --git a/frontend/src/components/pages/travelogueRegister/TravelogueRegisterPage.tsx b/frontend/src/components/pages/travelogueRegister/TravelogueRegisterPage.tsx index 0bc1a289..de443878 100644 --- a/frontend/src/components/pages/travelogueRegister/TravelogueRegisterPage.tsx +++ b/frontend/src/components/pages/travelogueRegister/TravelogueRegisterPage.tsx @@ -22,7 +22,6 @@ import TravelogueDayAccordion from "@components/pages/travelogueRegister/Travelo import { useTravelogueDays } from "@hooks/pages/useTravelogueDays"; import { useDragScroll } from "@hooks/useDragScroll"; -import useInitialTravelTitle from "@hooks/useInitialTravelTitle"; import useLeadingDebounce from "@hooks/useLeadingDebounce"; import useTagSelection from "@hooks/useTagSelection"; import useUser from "@hooks/useUser"; @@ -32,6 +31,8 @@ import { ERROR_MESSAGE_MAP } from "@constants/errorMessage"; import { FORM_VALIDATIONS_MAP } from "@constants/formValidation"; import { ROUTE_PATHS_MAP } from "@constants/route"; +import getInitialTravelTitle from "@utils/getInitialTravelTitle"; + import * as S from "./TravelogueRegisterPage.styled"; const TravelogueRegisterPage = () => { @@ -66,7 +67,7 @@ const TravelogueRegisterPage = () => { onDeleteImageUrls, } = useTravelogueDays(transformDetail?.days ?? []); - const initialTitle = useInitialTravelTitle({ days: transformDetail?.days, type: "travelogue" }); + const initialTitle = getInitialTravelTitle({ days: transformDetail?.days, type: "travelogue" }); const [title, setTitle] = useState(initialTitle); diff --git a/frontend/src/hooks/pages/useTravelPlanForm.ts b/frontend/src/hooks/pages/useTravelPlanForm.ts index 0c06e79a..d744afd1 100644 --- a/frontend/src/hooks/pages/useTravelPlanForm.ts +++ b/frontend/src/hooks/pages/useTravelPlanForm.ts @@ -3,10 +3,11 @@ import { useState } from "react"; import { TravelTransformPlaces } from "@type/domain/travelTransform"; import { useTravelPlanDays } from "@hooks/pages/useTravelPlanDays"; -import useInitialTravelTitle from "@hooks/useInitialTravelTitle"; import { FORM_VALIDATIONS_MAP } from "@constants/formValidation"; +import getInitialTravelTitle from "@utils/getInitialTravelTitle"; + const useTravelPlanForm = (transformDays: TravelTransformPlaces[]) => { const [startDate, setStartDate] = useState(null); @@ -26,7 +27,7 @@ const useTravelPlanForm = (transformDays: TravelTransformPlaces[]) => { onChangeContent, } = useTravelPlanDays(transformDays); - const initialTitle = useInitialTravelTitle({ days: travelPlanDays, type: "travelPlan" }); + const initialTitle = getInitialTravelTitle({ days: travelPlanDays, type: "travelPlan" }); const [title, setTitle] = useState(initialTitle); diff --git a/frontend/src/hooks/useInitialTravelTitle.ts b/frontend/src/hooks/useInitialTravelTitle.ts deleted file mode 100644 index e261f5b7..00000000 --- a/frontend/src/hooks/useInitialTravelTitle.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { useMemo } from "react"; - -import type { TravelTransformPlaces } from "@type/domain/travelTransform"; - -import { useUserProfile } from "@queries/useUserProfile"; - -import getDaysAndNights from "@utils/getDaysAndNights"; - -type TravelRecordType = "travelogue" | "travelPlan"; - -type useInitialTravelTitleProps = { - days: TravelTransformPlaces[] | undefined; - type: TravelRecordType; -}; - -const useInitialTravelTitle = ({ days, type }: useInitialTravelTitleProps) => { - const { data, status } = useUserProfile(); - - return useMemo(() => { - const daysAndNights = getDaysAndNights(days); - - const userPrefix = status === "success" ? `${data?.nickname}의 ` : ""; - const tripType = type === "travelogue" ? "여행기" : "여행 계획"; - - if (days && days?.length >= 1) return `${userPrefix}${daysAndNights} ${tripType}`; - return ""; - }, [days, data, status, type]); -}; - -export default useInitialTravelTitle; diff --git a/frontend/src/utils/getInitialTravelTitle.ts b/frontend/src/utils/getInitialTravelTitle.ts new file mode 100644 index 00000000..e0ccd914 --- /dev/null +++ b/frontend/src/utils/getInitialTravelTitle.ts @@ -0,0 +1,21 @@ +import type { TravelTransformPlaces } from "@type/domain/travelTransform"; + +import getDaysAndNights from "@utils/getDaysAndNights"; + +type TravelRecordType = "travelogue" | "travelPlan"; + +interface getInitialTravelTitleProps { + days: TravelTransformPlaces[] | undefined; + type: TravelRecordType; +} + +const getInitialTravelTitle = ({ days, type }: getInitialTravelTitleProps) => { + const daysAndNights = getDaysAndNights(days); + + const tripType = type === "travelogue" ? "여행기" : "여행 계획"; + + if (days && days?.length >= 1) return `${daysAndNights} ${tripType}`; + return ""; +}; + +export default getInitialTravelTitle;