Merge branch 'dev' of https://git.hanasys.jp/qcast3/onsitesurvey into feature/suitable
This commit is contained in:
commit
2d914d3798
@ -1,12 +1,16 @@
|
||||
import type { ReactNode } from 'react'
|
||||
import type { Metadata } from 'next'
|
||||
import type { SessionData } from '@/types/Auth'
|
||||
|
||||
import ReactQueryProviders from '@/providers/ReactQueryProvider'
|
||||
import EdgeProvider from '@/providers/EdgeProvider'
|
||||
import PopupController from '@/components/ui/PopupController'
|
||||
|
||||
import '@/styles/style.scss'
|
||||
import { cookies } from 'next/headers'
|
||||
import { getIronSession } from 'iron-session'
|
||||
import { sessionOptions } from '@/libs/session'
|
||||
|
||||
import type { ReactNode } from 'react'
|
||||
import '@/styles/style.scss'
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'Create Next App',
|
||||
@ -21,9 +25,14 @@ interface RootLayoutProps {
|
||||
}
|
||||
|
||||
export default async function RootLayout({ children, header, footer, floatBtn }: RootLayoutProps): Promise<ReactNode> {
|
||||
const cookieStore = await cookies()
|
||||
const session = await getIronSession<SessionData>(cookieStore, sessionOptions)
|
||||
|
||||
const sessionData = session.isLoggedIn ? JSON.stringify(session) : ''
|
||||
|
||||
return (
|
||||
<ReactQueryProviders>
|
||||
<EdgeProvider>
|
||||
<EdgeProvider sessionData={sessionData}>
|
||||
<html lang="en">
|
||||
<body>
|
||||
<div className="wrap">
|
||||
|
||||
@ -1,25 +1,29 @@
|
||||
'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'
|
||||
import { useSessionStore } from '@/store/session'
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
alert2: (msg: string, alert2BtnYes?: () => void, alert2BtnNo?: () => void) => void
|
||||
}
|
||||
interface EdgeProviderProps {
|
||||
children: React.ReactNode
|
||||
sessionData: string
|
||||
}
|
||||
|
||||
export default function EdgeProvider({ children }: React.PropsWithChildren) {
|
||||
export default function EdgeProvider({ children, sessionData }: EdgeProviderProps) {
|
||||
const pathname = usePathname()
|
||||
const { setBackBtn } = useHeaderStore()
|
||||
const { reset } = useSideNavState()
|
||||
const { setAlertMsg, setAlertBtn, setAlert, setAlert2, setAlert2BtnYes, setAlert2BtnNo } = usePopupController()
|
||||
const { alertKind } = useAlertSwitch()
|
||||
const { session, setSession } = useSessionStore()
|
||||
|
||||
/**
|
||||
* alert 함수 - window.alert 함수 대체
|
||||
* @param msg
|
||||
* @param alertBtn
|
||||
*/
|
||||
const alertFunc = (msg: string, alertBtn: Function) => {
|
||||
console.log('🚀 ~ alertFunc ~ msg:', msg)
|
||||
setAlertMsg(msg)
|
||||
@ -27,7 +31,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 +46,30 @@ 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
|
||||
}
|
||||
if (sessionData && sessionData !== '') {
|
||||
setSession({
|
||||
...session,
|
||||
...JSON.parse(sessionData),
|
||||
})
|
||||
}
|
||||
}, [])
|
||||
|
||||
/**
|
||||
* 헤더 뒤로가기 버튼 컨트롤
|
||||
|
||||
@ -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),
|
||||
}))
|
||||
Loading…
x
Reference in New Issue
Block a user