Skip to content

Commit

Permalink
fix: 머지 후 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jhj2713 committed Aug 11, 2024
1 parent 0539f63 commit ac9b88f
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 7 deletions.
8 changes: 7 additions & 1 deletion client/src/features/CasperCustom/CasperCustomFinish.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ import ArrowIcon from "/public/assets/icons/arrow.svg?react";

interface CasperCustomFinishProps {
handleResetStep: () => void;
unblockNavigation: () => void;
}

export function CasperCustomFinish({ handleResetStep }: CasperCustomFinishProps) {
export function CasperCustomFinish({
handleResetStep,
unblockNavigation,
}: CasperCustomFinishProps) {
const [cookies] = useCookies([COOKIE_TOKEN_KEY]);

const {
Expand All @@ -41,6 +45,8 @@ export function CasperCustomFinish({ handleResetStep }: CasperCustomFinishProps)
if (!cookies[COOKIE_TOKEN_KEY]) {
return;
}

unblockNavigation();
getApplyCount();
}, [cookies]);

Expand Down
9 changes: 7 additions & 2 deletions client/src/features/CasperCustom/CasperCustomFinishing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ export function CasperCustomFinishing({ navigateNextStep }: CasperCustomFinishin
useEffect(() => {
showToast();

setTimeout(() => {
const flipTimer = setTimeout(() => {
setIsFlipped(true);
}, 3000);

setTimeout(() => {
const navigateTimer = setTimeout(() => {
navigateNextStep();
}, 6000);

return () => {
clearTimeout(flipTimer);
clearTimeout(navigateTimer);
};
}, []);

return (
Expand Down
37 changes: 37 additions & 0 deletions client/src/hooks/useBlockNavigation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { useEffect, useState } from "react";
import { unstable_usePrompt, useLocation } from "react-router-dom";

export function useBlockNavigation(message: string) {
const location = useLocation();
const [isBlocking, setIsBlocking] = useState(false);

unstable_usePrompt({ when: isBlocking, message });

const unblockNavigation = () => {
setIsBlocking(false);
};

const handleBeforeUnload = (e: BeforeUnloadEvent) => {
if (isBlocking) {
e.preventDefault();
e.returnValue = "";
}
};

useEffect(() => {
setIsBlocking(true);

return () => {
setIsBlocking(false);
};
}, [location]);
useEffect(() => {
window.addEventListener("beforeunload", handleBeforeUnload);

return () => {
window.removeEventListener("beforeunload", handleBeforeUnload);
};
}, [isBlocking]);

return { unblockNavigation };
}
14 changes: 12 additions & 2 deletions client/src/pages/CasperCustom/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ import {
CasperCustomForm,
CasperCustomProcess,
} from "@/features/CasperCustom";
import { useBlockNavigation } from "@/hooks/useBlockNavigation";
import useHeaderStyleObserver from "@/hooks/useHeaderStyleObserver";
import { SCROLL_MOTION } from "../../constants/animation";

const INITIAL_STEP = 0;

export default function CasperCustom() {
const { unblockNavigation } = useBlockNavigation(
"이 페이지를 떠나면 모든 변경 사항이 저장되지 않습니다. 페이지를 떠나시겠습니까?"
);

const containerRef = useHeaderStyleObserver({
darkSections: [CASPER_CUSTOM_SECTIONS.CUSTOM],
});
Expand All @@ -28,7 +33,7 @@ export default function CasperCustom() {
const selectedStep = CUSTOM_STEP_OPTION_ARRAY[selectedStepIdx];

const handleClickNextStep = () => {
setSelectedStepIdx(selectedStepIdx + 1);
setSelectedStepIdx((prevSelectedIdx) => prevSelectedIdx + 1);
};

const handleResetStep = () => {
Expand All @@ -43,7 +48,12 @@ export default function CasperCustom() {
} else if (selectedStep === CUSTOM_STEP_OPTION.FINISHING) {
return <CasperCustomFinishing navigateNextStep={handleClickNextStep} />;
} else if (selectedStep === CUSTOM_STEP_OPTION.FINISH) {
return <CasperCustomFinish handleResetStep={handleResetStep} />;
return (
<CasperCustomFinish
handleResetStep={handleResetStep}
unblockNavigation={unblockNavigation}
/>
);
}
return <></>;
};
Expand Down
3 changes: 1 addition & 2 deletions client/src/types/lotteryApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export interface GetApplyCountResponse {
}

export interface GetLotteryResponse {
lotteryEventId: number;
eventStartDate: string;
eventEndDate: string;
winnerCount: number;
activePeriod: number;
}

0 comments on commit ac9b88f

Please sign in to comment.