refactor: enhance DoubleBtnAlert and Header components with improved button handling and confirm dialog integration

This commit is contained in:
yoosangwook 2025-05-12 18:24:18 +09:00
parent b4e009cb8e
commit 778d3b6be8
4 changed files with 50 additions and 18 deletions

View File

@ -1,10 +1,19 @@
'use client' 'use client'
import { usePopupController } from '@/store/popupController' import { usePopupController } from '@/store/popupController'
import React from 'react'
export default function DoubleBtnAlert() { export default function DoubleBtnAlert() {
const { alertMsg, alert2BtnYes, alert2BtnNo } = usePopupController() const { alertMsg, alert2BtnYes, alert2BtnNo, setAlert2 } = usePopupController()
const handleAlert2BtnYes = () => {
alert2BtnYes()
setAlert2(false)
}
const handleAlert2BtnNo = () => {
alert2BtnNo()
setAlert2(false)
}
return ( return (
<div className="modal-popup alert"> <div className="modal-popup alert">
@ -13,12 +22,12 @@ export default function DoubleBtnAlert() {
<div className="alert-tit">{alertMsg}</div> <div className="alert-tit">{alertMsg}</div>
<div className="alert-btn-wrap"> <div className="alert-btn-wrap">
<div className="alert-btn-bx"> <div className="alert-btn-bx">
<button className="btn-frame red min" onClick={() => alert2BtnYes()}> <button className="btn-frame red min" onClick={() => handleAlert2BtnYes()}>
</button> </button>
</div> </div>
<div className="alert-btn-bx"> <div className="alert-btn-bx">
<button className="btn-frame n-blue min" onClick={() => alert2BtnNo()}> <button className="btn-frame n-blue min" onClick={() => handleAlert2BtnNo()}>
</button> </button>
</div> </div>

View File

@ -14,6 +14,7 @@ import { useTitle } from '@/hooks/useTitle'
import { axiosInstance } from '@/libs/axios' import { axiosInstance } from '@/libs/axios'
import 'swiper/css' import 'swiper/css'
import { confirmParamsSerialize } from '@/utils/window'
export default function Header() { export default function Header() {
const router = useRouter() const router = useRouter()
@ -38,6 +39,22 @@ export default function Header() {
} }
} }
const handleYes = () => {
console.log('yes')
}
const handleNo = () => {
console.log('no')
}
const handleCofirm = () => {
window.neoConfirm(
'よろしいですか?',
() => console.log('yes'),
() => console.log('no'),
)
}
return ( return (
<> <>
<div className="header-warp"> <div className="header-warp">
@ -45,7 +62,7 @@ export default function Header() {
<div className="header-inner"> <div className="header-inner">
{backBtn && ( {backBtn && (
<div className="back-button-wrap"> <div className="back-button-wrap">
<button className="back-button" onClick={() => router.back()}></button> <button className="back-button" onClick={handleCofirm}></button>
</div> </div>
)} )}
<h2 className="logo"> <h2 className="logo">

View File

@ -7,6 +7,12 @@ import { usePathname } from 'next/navigation'
import { useEffect } from 'react' import { useEffect } from 'react'
import { useSessionStore } from '@/store/session' import { useSessionStore } from '@/store/session'
declare global {
interface Window {
neoConfirm: (msg?: string, alertBtn2Yes?: Function, alertBtn2No?: Function) => boolean
}
}
interface EdgeProviderProps { interface EdgeProviderProps {
children: React.ReactNode children: React.ReactNode
sessionData: string sessionData: string
@ -44,25 +50,18 @@ export default function EdgeProvider({ children, sessionData }: EdgeProviderProp
setAlert2(true) setAlert2(true)
} }
//alert 함수 변경해서 바인딩
useEffect(() => { useEffect(() => {
//alert 함수 변경해서 바인딩
window.alert = function (msg, alertBtn = () => setAlert(false)) { window.alert = function (msg, alertBtn = () => setAlert(false)) {
alertFunc(msg, alertBtn) alertFunc(msg, alertBtn)
} }
window.confirm = function (msg = '', alert2BtnYes = () => setAlert2(false), alert2BtnNo = () => setAlert2(false)) { // confirm 함수 변경해서 바인딩
alertFunc2( window.neoConfirm = function (msg: string | undefined, alertBtn2Yes?: Function, alertBtn2No?: Function) {
msg, if (!msg) return false
() => { alertFunc2(msg, alertBtn2Yes || (() => {}), alertBtn2No || (() => {}))
alert2BtnYes()
return true
},
() => {
alert2BtnNo()
return false
},
)
return false return false
} }
// 서버 세션이 있으면 zuatand 세션 데이터 갱신
if (sessionData && sessionData !== '') { if (sessionData && sessionData !== '') {
setSession({ setSession({
...session, ...session,

7
src/utils/window.ts Normal file
View File

@ -0,0 +1,7 @@
export const confirmParamsSerialize = ({ msg, yes, no }: { msg: string; yes: () => void; no: () => void }) => {
return JSON.stringify({ msg, yes, no })
}
export const confirmParamsDeserialize = (params: string) => {
return JSON.parse(params)
}