feat: implement alert management in EdgeProvider with dynamic alert types
This commit is contained in:
parent
a6702f52fc
commit
436f149635
@ -1,5 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
|
import { useAlertSwitch } from '@/store/alertSwitch'
|
||||||
import { useHeaderStore } from '@/store/header'
|
import { useHeaderStore } from '@/store/header'
|
||||||
import { usePopupController } from '@/store/popupController'
|
import { usePopupController } from '@/store/popupController'
|
||||||
import { useSideNavState } from '@/store/sideNavState'
|
import { useSideNavState } from '@/store/sideNavState'
|
||||||
@ -17,6 +18,7 @@ export default function EdgeProvider({ children }: React.PropsWithChildren) {
|
|||||||
const { setBackBtn } = useHeaderStore()
|
const { setBackBtn } = useHeaderStore()
|
||||||
const { reset } = useSideNavState()
|
const { reset } = useSideNavState()
|
||||||
const { setAlertMsg, setAlertBtn, setAlert, setAlert2, setAlert2BtnYes, setAlert2BtnNo } = usePopupController()
|
const { setAlertMsg, setAlertBtn, setAlert, setAlert2, setAlert2BtnYes, setAlert2BtnNo } = usePopupController()
|
||||||
|
const { alertKind } = useAlertSwitch()
|
||||||
|
|
||||||
const alertFunc = (msg: string, alertBtn: Function) => {
|
const alertFunc = (msg: string, alertBtn: Function) => {
|
||||||
console.log('🚀 ~ alertFunc ~ msg:', msg)
|
console.log('🚀 ~ alertFunc ~ msg:', msg)
|
||||||
@ -38,15 +40,18 @@ export default function EdgeProvider({ children }: React.PropsWithChildren) {
|
|||||||
setAlert2(true)
|
setAlert2(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//alert 함수 변경해서 바인딩
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
window.alert = function (msg, alertBtn = () => setAlert(false)) {
|
if (alertKind === 'single') {
|
||||||
alertFunc(msg, alertBtn)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}, [alertKind])
|
||||||
window.alert2 = function (msg, alert2BtnYes = () => setAlert2(false), alert2BtnNo = () => setAlert2(false)) {
|
|
||||||
alertFunc2(msg, alert2BtnYes, alert2BtnNo)
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 헤더 뒤로가기 버튼 컨트롤
|
* 헤더 뒤로가기 버튼 컨트롤
|
||||||
|
|||||||
21
src/store/alertSwitch.ts
Normal file
21
src/store/alertSwitch.ts
Normal file
@ -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<AlertSwitchState>((set) => ({
|
||||||
|
...initialState,
|
||||||
|
setAlertKind: (value: string) => set((state) => ({ ...state, alertKind: value })),
|
||||||
|
reset: () => set(initialState),
|
||||||
|
}))
|
||||||
Loading…
x
Reference in New Issue
Block a user