사용자 locale 변경 시 menus와 user-menus 재호출

This commit is contained in:
hyeonsu
2025-08-28 10:09:57 +09:00
parent 49f812f444
commit 404984a652
3 changed files with 13 additions and 4 deletions

View File

@@ -194,7 +194,7 @@ export function AppLayout({ children }: AppLayoutProps) {
const router = useRouter(); const router = useRouter();
const pathname = usePathname(); const pathname = usePathname();
const { user, logout, refreshUserData } = useAuth(); const { user, logout, refreshUserData } = useAuth();
const { userMenus, adminMenus, loading } = useMenu(); const { userMenus, adminMenus, loading, refreshMenus } = useMenu();
const [sidebarOpen, setSidebarOpen] = useState(false); const [sidebarOpen, setSidebarOpen] = useState(false);
const [expandedMenus, setExpandedMenus] = useState<Set<string>>(new Set()); const [expandedMenus, setExpandedMenus] = useState<Set<string>>(new Set());
@@ -213,7 +213,7 @@ export function AppLayout({ children }: AppLayoutProps) {
selectImage, selectImage,
removeImage, removeImage,
saveProfile, saveProfile,
} = useProfile(user, refreshUserData); } = useProfile(user, refreshUserData, refreshMenus);
// 현재 경로에 따라 어드민 모드인지 판단 // 현재 경로에 따라 어드민 모드인지 판단
const isAdminMode = pathname.startsWith("/admin"); const isAdminMode = pathname.startsWith("/admin");

View File

@@ -180,5 +180,6 @@ export const useMenu = (user: any, authLoading: boolean) => {
isMenuLoading: menuState.isLoading, isMenuLoading: menuState.isLoading,
handleMenuClick, handleMenuClick,
toggleMenu, toggleMenu,
refreshMenus: loadMenuData, // 메뉴 새로고침 함수 추가
}; };
}; };

View File

@@ -16,7 +16,7 @@ interface AlertModalState {
/** /**
* 프로필 관련 비즈니스 로직을 관리하는 커스텀 훅 * 프로필 관련 비즈니스 로직을 관리하는 커스텀 훅
*/ */
export const useProfile = (user: any, refreshUserData: () => Promise<void>) => { export const useProfile = (user: any, refreshUserData: () => Promise<void>, refreshMenus?: () => Promise<void>) => {
// 상태 관리 // 상태 관리
const [modalState, setModalState] = useState<ProfileModalState>({ const [modalState, setModalState] = useState<ProfileModalState>({
isOpen: false, isOpen: false,
@@ -229,7 +229,8 @@ export const useProfile = (user: any, refreshUserData: () => Promise<void>) => {
if (response.result) { if (response.result) {
// locale이 변경된 경우 전역 변수와 localStorage 업데이트 // locale이 변경된 경우 전역 변수와 localStorage 업데이트
if (modalState.formData.locale && modalState.formData.locale !== user.locale) { const localeChanged = modalState.formData.locale && modalState.formData.locale !== user.locale;
if (localeChanged) {
if (typeof window !== "undefined") { if (typeof window !== "undefined") {
// 전역 변수 업데이트 // 전역 변수 업데이트
(window as any).__GLOBAL_USER_LANG = modalState.formData.locale; (window as any).__GLOBAL_USER_LANG = modalState.formData.locale;
@@ -241,6 +242,13 @@ export const useProfile = (user: any, refreshUserData: () => Promise<void>) => {
// 성공: 사용자 정보 새로고침 // 성공: 사용자 정보 새로고침
await refreshUserData(); await refreshUserData();
// locale이 변경된 경우 메뉴도 새로고침
if (localeChanged && refreshMenus) {
console.log("🔄 locale 변경으로 인한 메뉴 새로고침 시작");
await refreshMenus();
console.log("✅ 메뉴 새로고침 완료");
}
setModalState((prev) => ({ setModalState((prev) => ({
...prev, ...prev,
selectedFile: null, selectedFile: null,