Files
sb-front/src/stores/ui.js
T

68 lines
1.9 KiB
JavaScript
Raw Normal View History

import { defineStore } from 'pinia'
import { ref } from 'vue'
import { authApi } from '@/api/authApi'
// 전역 UI 상태 (로그인/회원가입 레이어 팝업 등)
export const useUiStore = defineStore('ui', () => {
const loginOpen = ref(false)
const signupOpen = ref(false)
const redirectPath = ref('')
// 회원가입 허용 여부(관리자 설정). 비로그인도 조회 가능한 공개 API.
const signupEnabled = ref(true)
async function loadSignupEnabled() {
try {
const res = await authApi.signupEnabled()
signupEnabled.value = !!res.enabled
} catch {
signupEnabled.value = true // 조회 실패 시 기본 허용(서버가 최종 검증)
}
}
// 모바일 사이드바 드로어
const sidebarOpen = ref(false)
function toggleSidebar() {
sidebarOpen.value = !sidebarOpen.value
}
function closeSidebar() {
sidebarOpen.value = false
}
// 비밀번호 변경 모달
const passwordOpen = ref(false)
function openPassword() {
passwordOpen.value = true
}
function closePassword() {
passwordOpen.value = false
}
// 로그인 팝업 (회원가입 팝업은 닫고 전환)
function openLogin(redirect = '') {
redirectPath.value = redirect || ''
signupOpen.value = false
loginOpen.value = true
}
function closeLogin() {
loginOpen.value = false
redirectPath.value = ''
}
// 회원가입 팝업 (로그인 팝업은 닫고 전환). 열 때 최신 허용 여부 갱신.
function openSignup() {
loginOpen.value = false
signupOpen.value = true
loadSignupEnabled()
}
function closeSignup() {
signupOpen.value = false
}
return {
loginOpen, signupOpen, redirectPath, openLogin, closeLogin, openSignup, closeSignup,
signupEnabled, loadSignupEnabled,
sidebarOpen, toggleSidebar, closeSidebar,
passwordOpen, openPassword, closePassword,
}
})