From 436f149635c0aec831f13cea3a65756ef0ec7212 Mon Sep 17 00:00:00 2001 From: yoosangwook Date: Fri, 9 May 2025 15:17:19 +0900 Subject: [PATCH] feat: implement alert management in EdgeProvider with dynamic alert types --- src/providers/EdgeProvider.tsx | 19 ++++++++++++------- src/store/alertSwitch.ts | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 src/store/alertSwitch.ts diff --git a/src/providers/EdgeProvider.tsx b/src/providers/EdgeProvider.tsx index 5c4e53c..3d8ea42 100644 --- a/src/providers/EdgeProvider.tsx +++ b/src/providers/EdgeProvider.tsx @@ -1,5 +1,6 @@ 'use client' +import { useAlertSwitch } from '@/store/alertSwitch' import { useHeaderStore } from '@/store/header' import { usePopupController } from '@/store/popupController' import { useSideNavState } from '@/store/sideNavState' @@ -17,6 +18,7 @@ export default function EdgeProvider({ children }: React.PropsWithChildren) { const { setBackBtn } = useHeaderStore() const { reset } = useSideNavState() const { setAlertMsg, setAlertBtn, setAlert, setAlert2, setAlert2BtnYes, setAlert2BtnNo } = usePopupController() + const { alertKind } = useAlertSwitch() const alertFunc = (msg: string, alertBtn: Function) => { console.log('๐Ÿš€ ~ alertFunc ~ msg:', msg) @@ -38,15 +40,18 @@ export default function EdgeProvider({ children }: React.PropsWithChildren) { setAlert2(true) } + //alert ํ•จ์ˆ˜ ๋ณ€๊ฒฝํ•ด์„œ ๋ฐ”์ธ๋”ฉ useEffect(() => { - window.alert = function (msg, alertBtn = () => setAlert(false)) { - alertFunc(msg, alertBtn) + if (alertKind === 'single') { + window.alert = function (msg, alertBtn = () => setAlert(false)) { + alertFunc(msg, alertBtn) + } + } else if (alertKind === 'multi') { + window.alert = function (msg, alert2BtnYes = () => setAlert2(false), alert2BtnNo = () => setAlert2(false)) { + alertFunc2(msg, alert2BtnYes, alert2BtnNo) + } } - - window.alert2 = function (msg, alert2BtnYes = () => setAlert2(false), alert2BtnNo = () => setAlert2(false)) { - alertFunc2(msg, alert2BtnYes, alert2BtnNo) - } - }, []) + }, [alertKind]) /** * ํ—ค๋” ๋’ค๋กœ๊ฐ€๊ธฐ ๋ฒ„ํŠผ ์ปจํŠธ๋กค diff --git a/src/store/alertSwitch.ts b/src/store/alertSwitch.ts new file mode 100644 index 0000000..54c9d00 --- /dev/null +++ b/src/store/alertSwitch.ts @@ -0,0 +1,21 @@ +import { create } from 'zustand' + +type AlertSwitchState = { + alertKind: string + setAlertKind: (value: string) => void + reset: () => void +} + +type InitialState = { + alertKind: string +} + +const initialState: InitialState = { + alertKind: 'single', +} + +export const useAlertSwitch = create((set) => ({ + ...initialState, + setAlertKind: (value: string) => set((state) => ({ ...state, alertKind: value })), + reset: () => set(initialState), +}))