-
- alert2BtnNo()}>
+ handleAlert2BtnNo()}>
キャンセル
diff --git a/src/components/ui/common/Header.tsx b/src/components/ui/common/Header.tsx
index 6630e1a..30e646f 100644
--- a/src/components/ui/common/Header.tsx
+++ b/src/components/ui/common/Header.tsx
@@ -14,6 +14,7 @@ import { useTitle } from '@/hooks/useTitle'
import { axiosInstance } from '@/libs/axios'
import 'swiper/css'
+import { confirmParamsSerialize } from '@/utils/window'
export default function Header() {
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 (
<>
@@ -45,7 +62,7 @@ export default function Header() {
{backBtn && (
- router.back()}>
+
)}
diff --git a/src/providers/EdgeProvider.tsx b/src/providers/EdgeProvider.tsx
index 9caa71d..424ab2d 100644
--- a/src/providers/EdgeProvider.tsx
+++ b/src/providers/EdgeProvider.tsx
@@ -7,6 +7,12 @@ import { usePathname } from 'next/navigation'
import { useEffect } from 'react'
import { useSessionStore } from '@/store/session'
+declare global {
+ interface Window {
+ neoConfirm: (msg?: string, alertBtn2Yes?: Function, alertBtn2No?: Function) => boolean
+ }
+}
+
interface EdgeProviderProps {
children: React.ReactNode
sessionData: string
@@ -44,25 +50,18 @@ export default function EdgeProvider({ children, sessionData }: EdgeProviderProp
setAlert2(true)
}
- //alert 함수 변경해서 바인딩
useEffect(() => {
+ //alert 함수 변경해서 바인딩
window.alert = function (msg, alertBtn = () => setAlert(false)) {
alertFunc(msg, alertBtn)
}
- window.confirm = function (msg = '', alert2BtnYes = () => setAlert2(false), alert2BtnNo = () => setAlert2(false)) {
- alertFunc2(
- msg,
- () => {
- alert2BtnYes()
- return true
- },
- () => {
- alert2BtnNo()
- return false
- },
- )
+ // confirm 함수 변경해서 바인딩
+ window.neoConfirm = function (msg: string | undefined, alertBtn2Yes?: Function, alertBtn2No?: Function) {
+ if (!msg) return false
+ alertFunc2(msg, alertBtn2Yes || (() => {}), alertBtn2No || (() => {}))
return false
}
+ // 서버 세션이 있으면 zuatand 세션 데이터 갱신
if (sessionData && sessionData !== '') {
setSession({
...session,
diff --git a/src/utils/window.ts b/src/utils/window.ts
new file mode 100644
index 0000000..bb20dae
--- /dev/null
+++ b/src/utils/window.ts
@@ -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)
+}