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

[Fix] - 여행 전환 후 다른 페이지에서 다시 등록 페이지로 접근 시 데이터가 남아있는 문제 해결 #207

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -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<Date | null>(null);
Expand Down Expand Up @@ -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 (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const TravelogueDetailPage = () => {
)}
/>
<TransformBottomSheet
onTransform={() => onTransformTravelDetail("/travel-plans/register", data)}
onTransform={() => onTransformTravelDetail("/travel-plan/register", data)}
buttonLabel="여행 계획으로 전환"
>
이 여행기를 따라가고 싶으신가요?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,18 @@

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]);

Check warning on line 105 in frontend/src/components/pages/travelogueRegister/TravelogueRegisterPage.tsx

View workflow job for this annotation

GitHub Actions / frontend-ci

React Hook useEffect has a missing dependency: 'saveTransformDetail'. Either include it or remove the dependency array

return (
<>
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/contexts/TravelTransformDetailProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
import { ROUTE_PATHS_MAP } from "@constants/route";

const TravelogueContext = createContext<TravelTransformDetail | null>(null);
const SaveTravelogueContext = createContext<(travelogue: TravelTransformDetail) => void>(() => {});
const SaveTravelogueContext = createContext<(travelogue: TravelTransformDetail | null) => void>(
() => {},
);

export const TravelTransformDetailProvider = ({ children }: React.PropsWithChildren) => {
const [travelTransformDetail, setTravelTransformDetail] = useState<TravelTransformDetail | null>(
null,
);

const saveTravelTransformDetail = (transformDetail: TravelTransformDetail) => {
const saveTravelTransformDetail = (transformDetail: TravelTransformDetail | null) => {
setTravelTransformDetail(transformDetail);
};

Expand All @@ -31,7 +33,7 @@
);
};

export const useTravelTransformDetailContext = () => {

Check warning on line 36 in frontend/src/contexts/TravelTransformDetailProvider.tsx

View workflow job for this annotation

GitHub Actions / frontend-ci

Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components
const transformDetail = useContext(TravelogueContext);
const saveTransformDetail = useContext(SaveTravelogueContext);

Expand All @@ -51,5 +53,5 @@
}
};

return { transformDetail, onTransformTravelDetail };
return { transformDetail, saveTransformDetail, onTransformTravelDetail };
};
Loading