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;