refactor: remove alertSwitch store and simplify alert handling in EdgeProvider

This commit is contained in:
yoosangwook 2025-05-12 10:37:58 +09:00
parent ce00cc2ba7
commit 2eacdda23e
2 changed files with 23 additions and 39 deletions

View File

@ -1,25 +1,22 @@
'use client'
import { useAlertSwitch } from '@/store/alertSwitch'
import { useHeaderStore } from '@/store/header'
import { usePopupController } from '@/store/popupController'
import { useSideNavState } from '@/store/sideNavState'
import { usePathname } from 'next/navigation'
import { useEffect } from 'react'
declare global {
interface Window {
alert2: (msg: string, alert2BtnYes?: () => void, alert2BtnNo?: () => void) => void
}
}
export default function EdgeProvider({ children }: React.PropsWithChildren) {
const pathname = usePathname()
const { setBackBtn } = useHeaderStore()
const { reset } = useSideNavState()
const { setAlertMsg, setAlertBtn, setAlert, setAlert2, setAlert2BtnYes, setAlert2BtnNo } = usePopupController()
const { alertKind } = useAlertSwitch()
/**
* alert - window.alert
* @param msg
* @param alertBtn
*/
const alertFunc = (msg: string, alertBtn: Function) => {
console.log('🚀 ~ alertFunc ~ msg:', msg)
setAlertMsg(msg)
@ -27,7 +24,7 @@ export default function EdgeProvider({ children }: React.PropsWithChildren) {
setAlert(true)
}
/**
* alert2
* alert2 - window.confirm
* @param msg alert
* @param alertBtn2Yes alert
* @param alertBtn2No alert
@ -42,16 +39,24 @@ export default function EdgeProvider({ children }: React.PropsWithChildren) {
//alert 함수 변경해서 바인딩
useEffect(() => {
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.alert = function (msg, alertBtn = () => setAlert(false)) {
alertFunc(msg, alertBtn)
}
}, [alertKind])
window.confirm = function (msg = '', alert2BtnYes = () => setAlert2(false), alert2BtnNo = () => setAlert2(false)) {
alertFunc2(
msg,
() => {
alert2BtnYes()
return true
},
() => {
alert2BtnNo()
return false
},
)
return false
}
}, [])
/**
*

View File

@ -1,21 +0,0 @@
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),
}))