-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Refactor] ApplyPage 로직 분리 - 1 (#441)
* chore: 관심사 끼리 분류 * refactor: 페이지 이탈 alert custom hook으로 분리 * refactor: isReview 전역 변수로 빼기 * refactor: apply page loading 제거 * feat: useDialog hook 생성 * refactor: useDialog 적용 * chore: dialog들 Form Provider 바깥으로 빼기 * chore: 오타 제거 * refactor: isReview 전역변수 제거 * feat: useEventListener custom hook 제작 * refactor: useEventListener 적용
- Loading branch information
1 parent
64c8410
commit c62d027
Showing
15 changed files
with
156 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useRef } from 'react'; | ||
|
||
const useDialog = () => { | ||
const ref = useRef<HTMLDialogElement>(null); | ||
|
||
const handleShowDialog = () => { | ||
ref.current?.showModal(); | ||
}; | ||
|
||
const handleCloseDialog = () => { | ||
ref.current?.close(); | ||
}; | ||
|
||
return { ref, handleShowDialog, handleCloseDialog }; | ||
}; | ||
|
||
export default useDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { useEffect } from 'react'; | ||
|
||
type EventType = keyof WindowEventMap; | ||
type EventListener = (event: Event) => void; | ||
|
||
const useEventListener = (eventName: EventType, callbackFn: EventListener) => { | ||
useEffect(() => { | ||
window.addEventListener(eventName, callbackFn); | ||
|
||
return () => window.removeEventListener(eventName, callbackFn); | ||
}, [eventName, callbackFn]); | ||
}; | ||
|
||
export default useEventListener; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import useEventListener from '@hooks/useEventListener'; | ||
|
||
/** 페이지 이탈 시 alert 띄우기 */ | ||
const useBeforeExitPageAlert = () => { | ||
const handleBeforeUnload = (e: BeforeUnloadEvent) => { | ||
e.preventDefault(); | ||
e.returnValue = ''; // Included for legacy support, e.g. Chrome/Edeg < 119; | ||
}; | ||
|
||
useEventListener('beforeunload', handleBeforeUnload); | ||
}; | ||
|
||
export default useBeforeExitPageAlert; |
Oops, something went wrong.