Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] - 여행기 & 여행 계획 등록/수정 페이지 리팩터링 #520

Merged
merged 18 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
ab97029
refactor(useTravelogueDays): 여행기 등록 페이지 default export로 변경
jinyoung234 Oct 9, 2024
49a501a
refactor(useTravelogueForm): 여행기 form에 대한 책임을 useTravelogueForm으로 분리
jinyoung234 Oct 9, 2024
1e6eec1
refactor(useMultiImageUpload): 다중 이미지 업로드 로직에 대한 리팩터링
jinyoung234 Oct 9, 2024
3ddfe8d
refactor(TravelogueRegisterPage): 페이지 리팩터링
jinyoung234 Oct 9, 2024
d23a62d
refactor(ThumbnailUpload): fileRef와 click 핸들러를 내부에서 관리하는 것으로 변경
jinyoung234 Oct 10, 2024
a5a7ec8
refactor: 인증된 사용자가 아닌 경우 redirect 시키는 hook 분리
jinyoung234 Oct 10, 2024
7745cd3
refactor: useToggle 훅을 통해 open, close 하도록 변경
jinyoung234 Oct 10, 2024
5d0a22f
refactor(travelTransform): TravelTransformPlace의 타입을 유틸리티 타입으로 개선
jinyoung234 Oct 10, 2024
cf84ef5
refactor(TravelogueRegisterPage): useTravelogueForm 형태 변경
jinyoung234 Oct 10, 2024
ee784f0
refactor(TravelogueEditPage): 여행기 수정 페이지 리팩터링
jinyoung234 Oct 10, 2024
c8ebee0
refactor(TravelPlanRegisterPage): 여행 계획 등록에 대한 책임 분리
jinyoung234 Oct 10, 2024
9045bc3
refactor(TravelPlanRegisterPage): 여행 계획 수정 페이지 리팩터링
jinyoung234 Oct 10, 2024
b44f89f
refactor: useTravelPlanFormState, useTravelogueFormState 폴더구조 변경
jinyoung234 Oct 10, 2024
52dca65
fix(useTravelogueFormState): ci 문제 해결
jinyoung234 Oct 10, 2024
6b28065
refactor: on prefix를 handle prefix로 변경
jinyoung234 Oct 13, 2024
5defe1c
refactor(ThumbnailUpload): 불필요한 제네릭 제거
jinyoung234 Oct 13, 2024
02fc25f
refactor(travelTransform): import 시 type 추가
jinyoung234 Oct 13, 2024
6e85fd3
refactor(ThumbnailUpload): 불필요한 props 개행 제거
jinyoung234 Oct 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useState } from "react";
import { useNavigate } from "react-router-dom";

import { useTravelTransformDetailContext } from "@contexts/TravelTransformDetailProvider";
Expand All @@ -23,6 +22,7 @@ import TravelPlanDayAccordion from "@components/pages/travelPlanRegister/TravelP
import useTravelPlanForm from "@hooks/pages/useTravelPlanForm";
import useAuthRedirect from "@hooks/useAuthRedirect";
import useLeadingDebounce from "@hooks/useLeadingDebounce";
import useToggle from "@hooks/useToggle";

import { CYPRESS_DATA_MAP } from "@constants/cypress";
import { DEBOUNCED_TIME } from "@constants/debouncedTime";
Expand Down Expand Up @@ -54,17 +54,8 @@ const TravelPlanRegisterPage = () => {
} = useTravelPlanForm(transformDetail?.days ?? []);

/** ui */
const [isOpenBottomSheet, setIsOpenBottomSheet] = useState(false);

const handleOpenBottomSheet = () => setIsOpenBottomSheet(true);

const handleCloseBottomSheet = () => setIsOpenBottomSheet(false);

const [isShowCalendar, setIsShowCalendar] = useState(false);

const handleOpenCalendar = () => setIsShowCalendar(true);

const handleCloseCalendar = () => setIsShowCalendar(() => false);
const [isOpenBottomSheet, onBottomSheetOpen, onBottomSheetClose] = useToggle();
const [isShowCalendar, handleOpenCalendar, handleCloseCalendar] = useToggle();

/** router */
const navigate = useNavigate();
Expand All @@ -80,7 +71,7 @@ const TravelPlanRegisterPage = () => {
onSuccess: ({ headers: { location } }) => {
const id = extractLastPath(location);

handleCloseBottomSheet();
onBottomSheetClose();
navigate(ROUTE_PATHS_MAP.travelPlan(id));
},
});
Expand Down Expand Up @@ -199,7 +190,7 @@ const TravelPlanRegisterPage = () => {

<Button
variants="primary"
onClick={handleOpenBottomSheet}
onClick={onBottomSheetOpen}
data-cy={CYPRESS_DATA_MAP.travelPlanRegister.registerButton}
>
등록
Expand All @@ -211,7 +202,7 @@ const TravelPlanRegisterPage = () => {
isPending={isPostingTravelPlanPending}
mainText="여행 계획을 등록할까요?"
subText="등록한 후에도 다시 여행 계획을 수정할 수 있어요."
onClose={handleCloseBottomSheet}
onClose={onBottomSheetClose}
onConfirm={handleConfirmBottomSheet}
/>
</>
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useTravelogueForm덕분에 코드가 훨씬 간결해졌네요 👍

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { useState } from "react";

import { useTravelTransformDetailContext } from "@contexts/TravelTransformDetailProvider";

import {
Expand All @@ -21,21 +19,14 @@ import useTravelogueForm from "@components/pages/travelogueRegister/hooks/useTra

import useAuthRedirect from "@hooks/useAuthRedirect";
import { useDragScroll } from "@hooks/useDragScroll";
import useToggle from "@hooks/useToggle";

import { FORM_VALIDATIONS_MAP } from "@constants/formValidation";

import * as S from "./TravelogueRegisterPage.styled";

const TravelogueRegisterPage = () => {
const [isOpen, setIsOpen] = useState(false);

const handleOpenBottomSheet = () => {
setIsOpen(true);
};

const handleCloseBottomSheet = () => {
setIsOpen(false);
};
const [isOpen, onBottomSheetOpen, onBottomSheetClose] = useToggle();

const { transformDetail } = useTravelTransformDetailContext();

Expand Down Expand Up @@ -63,7 +54,7 @@ const TravelogueRegisterPage = () => {
onChangePlaceDescription,
onSubmitTravelogue,
},
} = useTravelogueForm(transformDetail?.days ?? [], handleCloseBottomSheet);
} = useTravelogueForm(transformDetail?.days ?? [], onBottomSheetClose);

const { scrollRef, onMouseDown, onMouseMove, onMouseUp } = useDragScroll<HTMLUListElement>();

Expand Down Expand Up @@ -169,7 +160,7 @@ const TravelogueRegisterPage = () => {
</GoogleMapLoadScript>
</div>

<Button variants="primary" onClick={handleOpenBottomSheet}>
<Button variants="primary" onClick={onBottomSheetOpen}>
등록
</Button>
</S.Layout>
Expand All @@ -179,7 +170,7 @@ const TravelogueRegisterPage = () => {
isPending={isPostingTraveloguePending}
mainText="여행기를 등록할까요?"
subText="등록한 후에도 다시 여행기를 수정할 수 있어요!"
onClose={handleCloseBottomSheet}
onClose={onBottomSheetClose}
onConfirm={onSubmitTravelogue}
/>
</>
Expand Down
17 changes: 17 additions & 0 deletions frontend/src/hooks/useToggle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useState } from "react";

const useToggle = () => {
const [isOpen, setIsOpen] = useState(false);

const onClose = () => {
setIsOpen(false);
};

const onOpen = () => {
setIsOpen(true);
};

return [isOpen, onOpen, onClose] as const;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 hook 리턴에 as const 쓴거 처음봤는데
효과가 강력하네요
배우고 갑니다 👍👍👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 튜플 형태로 고정하고 이를 구조 분해로 각각에서 사용하면서 재사용성을 높인다는게 엄청 매력적이네요 좋은 코드 잘 봤습니다 :)

};

export default useToggle;