Merge branch 'dev' of https://git.hanasys.jp/qcast3/onsitesurvey into feature/survey
This commit is contained in:
commit
c06a96bc1b
@ -14,7 +14,7 @@ export async function POST(request: Request) {
|
||||
loginId,
|
||||
pwd,
|
||||
})
|
||||
console.log('🚀 ~ result ~ result:', result)
|
||||
// console.log('🚀 ~ result ~ result:', result)
|
||||
|
||||
if (result.data.result.code === 200) {
|
||||
const cookieStore = await cookies()
|
||||
@ -54,5 +54,5 @@ export async function POST(request: Request) {
|
||||
await session.save()
|
||||
}
|
||||
|
||||
return NextResponse.json({ code: 200, message: 'Login is Succecss!!' })
|
||||
return NextResponse.json({ code: 200, message: 'Login is Succecss!!', result: result.data.data })
|
||||
}
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
'use client'
|
||||
|
||||
import { useReducer, useState } from 'react'
|
||||
import type { SessionData } from '@/types/Auth'
|
||||
import { useEffect, useReducer, useState } from 'react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { axiosInstance } from '@/libs/axios'
|
||||
import { useSessionStore } from '@/store/session'
|
||||
|
||||
interface AccountState {
|
||||
loginId: string
|
||||
@ -21,6 +23,8 @@ export default function Login() {
|
||||
//로그인 상태
|
||||
const [isLogin, setIsLogin] = useState(false)
|
||||
|
||||
const { session, setSession } = useSessionStore()
|
||||
|
||||
const reducer = (state: AccountState, newState: Partial<AccountState>) => ({ ...state, ...newState })
|
||||
const [account, setAccount] = useReducer(reducer, {
|
||||
loginId: '',
|
||||
@ -30,6 +34,7 @@ export default function Login() {
|
||||
interface LoginData {
|
||||
code: number
|
||||
message: string | null
|
||||
result: SessionData
|
||||
}
|
||||
|
||||
const {
|
||||
@ -43,7 +48,7 @@ export default function Login() {
|
||||
loginId: account.loginId,
|
||||
pwd: account.pwd,
|
||||
})
|
||||
router.push('/')
|
||||
// router.push('/')
|
||||
|
||||
return data
|
||||
},
|
||||
@ -52,6 +57,17 @@ export default function Login() {
|
||||
retry: false,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
setIsLogin(false)
|
||||
if (loginData?.code === 200) {
|
||||
setSession({
|
||||
...session,
|
||||
...loginData?.result,
|
||||
})
|
||||
router.push('/')
|
||||
}
|
||||
}, [loginData])
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="login-form-wrap">
|
||||
|
||||
@ -1,17 +1,26 @@
|
||||
'use client'
|
||||
|
||||
import { usePopupController } from '@/store/popupController'
|
||||
import React from 'react'
|
||||
|
||||
export default function DoubleBtnAlert() {
|
||||
const { alertMsg, alert2BtnYes, alert2BtnNo } = usePopupController()
|
||||
|
||||
return (
|
||||
<div className="modal-popup alert">
|
||||
<div className="modal-dialog">
|
||||
<div className="modal-content">
|
||||
<div className="alert-tit">本当に削除しますか?</div>
|
||||
<div className="alert-tit">{alertMsg}</div>
|
||||
<div className="alert-btn-wrap">
|
||||
<div className="alert-btn-bx">
|
||||
<button className="btn-frame red min">確認</button>
|
||||
<button className="btn-frame red min" onClick={() => alert2BtnYes()}>
|
||||
確認
|
||||
</button>
|
||||
</div>
|
||||
<div className="alert-btn-bx">
|
||||
<button className="btn-frame n-blue min">キャンセル</button>
|
||||
<button className="btn-frame n-blue min" onClick={() => alert2BtnNo()}>
|
||||
キャンセル
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -12,6 +12,8 @@ import type { HeaderProps } from '@/types/Header'
|
||||
|
||||
import 'swiper/css'
|
||||
import { axiosInstance } from '@/libs/axios'
|
||||
import { useSessionStore } from '@/store/session'
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
|
||||
// type HeaderProps = {
|
||||
// name: string //header 이름
|
||||
@ -24,13 +26,18 @@ export default function Header({ name }: HeaderProps) {
|
||||
const { sideNavIsOpen, setSideNavIsOpen } = useSideNavState()
|
||||
const { backBtn } = useHeaderStore()
|
||||
|
||||
const { session, reset } = useSessionStore()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
if (pathname === '/login') {
|
||||
return null
|
||||
}
|
||||
|
||||
const handleLogout = async () => {
|
||||
reset()
|
||||
const { data } = await axiosInstance(null).get('/api/auth/logout')
|
||||
if (data.code === 200) {
|
||||
queryClient.clear()
|
||||
router.push('/login')
|
||||
}
|
||||
}
|
||||
@ -60,8 +67,8 @@ export default function Header({ name }: HeaderProps) {
|
||||
<img src="/assets/images/layout/side_nav_profile.svg" alt="profile" />
|
||||
</div>
|
||||
<div className="profile-group">
|
||||
<div className="profile-name">HONG GILDONG</div>
|
||||
<div className="profile-company">Interplug corp.</div>
|
||||
<div className="profile-name">{session.userNm}</div>
|
||||
<div className="profile-company">{session.category}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="side-close-wrap">
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import { useAlertSwitch } from '@/store/alertSwitch'
|
||||
import { useHeaderStore } from '@/store/header'
|
||||
import { usePopupController } from '@/store/popupController'
|
||||
import { useSideNavState } from '@/store/sideNavState'
|
||||
@ -17,6 +18,7 @@ export default function EdgeProvider({ children }: React.PropsWithChildren) {
|
||||
const { setBackBtn } = useHeaderStore()
|
||||
const { reset } = useSideNavState()
|
||||
const { setAlertMsg, setAlertBtn, setAlert, setAlert2, setAlert2BtnYes, setAlert2BtnNo } = usePopupController()
|
||||
const { alertKind } = useAlertSwitch()
|
||||
|
||||
const alertFunc = (msg: string, alertBtn: Function) => {
|
||||
console.log('🚀 ~ alertFunc ~ msg:', msg)
|
||||
@ -38,15 +40,18 @@ export default function EdgeProvider({ children }: React.PropsWithChildren) {
|
||||
setAlert2(true)
|
||||
}
|
||||
|
||||
//alert 함수 변경해서 바인딩
|
||||
useEffect(() => {
|
||||
if (alertKind === 'single') {
|
||||
window.alert = function (msg, alertBtn = () => setAlert(false)) {
|
||||
alertFunc(msg, alertBtn)
|
||||
}
|
||||
|
||||
window.alert2 = function (msg, alert2BtnYes = () => setAlert2(false), alert2BtnNo = () => setAlert2(false)) {
|
||||
} else if (alertKind === 'multi') {
|
||||
window.alert = function (msg, alert2BtnYes = () => setAlert2(false), alert2BtnNo = () => setAlert2(false)) {
|
||||
alertFunc2(msg, alert2BtnYes, alert2BtnNo)
|
||||
}
|
||||
}, [])
|
||||
}
|
||||
}, [alertKind])
|
||||
|
||||
/**
|
||||
* 헤더 뒤로가기 버튼 컨트롤
|
||||
|
||||
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),
|
||||
}))
|
||||
51
src/store/session.ts
Normal file
51
src/store/session.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import type { SessionData } from '@/types/Auth'
|
||||
import { create } from 'zustand'
|
||||
|
||||
type SessionState = {
|
||||
session: SessionData
|
||||
setSession: (session: SessionData) => void
|
||||
reset: () => void
|
||||
}
|
||||
|
||||
type InitialState = {
|
||||
session: SessionData
|
||||
}
|
||||
|
||||
const initialState: InitialState = {
|
||||
session: {
|
||||
langCd: null,
|
||||
currPage: 0,
|
||||
rowCount: 0,
|
||||
startRow: null,
|
||||
endRow: null,
|
||||
compCd: null,
|
||||
agencyStoreId: null,
|
||||
storeId: null,
|
||||
userId: null,
|
||||
category: null,
|
||||
userNm: null,
|
||||
userNmKana: null,
|
||||
telNo: null,
|
||||
fax: null,
|
||||
email: null,
|
||||
lastEditUser: null,
|
||||
storeGubun: null,
|
||||
pwCurr: null,
|
||||
pwdInitYn: null,
|
||||
apprStatCd: null,
|
||||
loginFailCnt: 0,
|
||||
loginFailMinYn: null,
|
||||
priceViewStatCd: null,
|
||||
groupId: null,
|
||||
storeLvl: null,
|
||||
custCd: null,
|
||||
builderNo: null,
|
||||
isLoggedIn: false,
|
||||
},
|
||||
}
|
||||
|
||||
export const useSessionStore = create<SessionState>((set) => ({
|
||||
...initialState,
|
||||
setSession: (value: SessionData) => set((state) => ({ ...state, session: { ...state.session, ...value } })),
|
||||
reset: () => set(initialState),
|
||||
}))
|
||||
Loading…
x
Reference in New Issue
Block a user