diff --git a/frontend/components/common/LanguageSelector.tsx b/frontend/components/common/LanguageSelector.tsx index 6af2bca6..fcabc1f5 100644 --- a/frontend/components/common/LanguageSelector.tsx +++ b/frontend/components/common/LanguageSelector.tsx @@ -18,13 +18,12 @@ export function LanguageSelector({ className }: LanguageSelectorProps) { ]; const handleLanguageChange = (newLang: string) => { + console.log("๐ŸŽฏ LanguageSelector ์–ธ์–ด ๋ณ€๊ฒฝ:", newLang); changeLang(newLang); - // ์–ธ์–ด ๋ณ€๊ฒฝ ์‹œ ๋ฉ”๋‰ด ์ปจํ…์ŠคํŠธ๊ฐ€ ์ž๋™์œผ๋กœ ์ƒˆ๋กœ๊ณ ์นจ๋จ - console.log("์–ธ์–ด ๋ณ€๊ฒฝ๋จ:", newLang); }; return ( - diff --git a/frontend/hooks/useMultiLang.ts b/frontend/hooks/useMultiLang.ts index 5a3f847f..64e56876 100644 --- a/frontend/hooks/useMultiLang.ts +++ b/frontend/hooks/useMultiLang.ts @@ -5,17 +5,51 @@ import { apiClient } from "@/lib/api/client"; let globalUserLang = "KR"; let globalChangeLangCallback: ((lang: string) => void) | null = null; +// ๐ŸŽฏ ํšจ์œจ์ ์ธ ์–ธ์–ด ๋ณ€๊ฒฝ ์•Œ๋ฆผ ์‹œ์Šคํ…œ +const languageChangeCallbacks = new Set<(newLang: string) => void>(); + +// ์ „์—ญ ์–ธ์–ด ๋ณ€๊ฒฝ ํ•จ์ˆ˜ (์™ธ๋ถ€์—์„œ ํ˜ธ์ถœ ๊ฐ€๋Šฅํ•˜๋„๋ก export) +export const notifyLanguageChange = (newLang: string) => { + globalUserLang = newLang; + (window as any).__GLOBAL_USER_LANG = newLang; + localStorage.setItem("userLocale", newLang); + localStorage.setItem("userLocaleLoaded", "true"); + (window as any).__GLOBAL_USER_LOCALE_LOADED = true; + + // ๐Ÿ—‘๏ธ ๋ฒˆ์—ญ ์บ์‹œ ์ดˆ๊ธฐํ™” + (window as any).__TRANSLATION_CACHE = {}; + + // ๋ชจ๋“  ์ปดํฌ๋„ŒํŠธ์— ์ฆ‰์‹œ ์•Œ๋ฆผ (ํด๋ง ์—†์ด!) + languageChangeCallbacks.forEach((callback) => callback(newLang)); + + console.log("๐Ÿ”„ ๋ชจ๋“  ์ปดํฌ๋„ŒํŠธ์— ์–ธ์–ด ๋ณ€๊ฒฝ ์•Œ๋ฆผ:", newLang); +}; + export const useMultiLang = (options: { companyCode?: string } = {}) => { const [userLang, setUserLang] = useState(null); // null๋กœ ์‹œ์ž‘ const companyCode = options.companyCode || "*"; - // ์ „์—ญ ์–ธ์–ด ์ƒํƒœ ๋™๊ธฐํ™” (๋ฌดํ•œ ๋ฃจํ”„ ๋ฐฉ์ง€) + // ๐ŸŽฏ ํšจ์œจ์ ์ธ ์–ธ์–ด ๋ณ€๊ฒฝ ๊ฐ์ง€ (ํด๋ง ๋Œ€์‹  ์ฝœ๋ฐฑ ๋“ฑ๋ก) useEffect(() => { - // ์ดˆ๊ธฐ ๋กœ๋”ฉ ์‹œ์—๋งŒ ๋™๊ธฐํ™” - if (globalUserLang && globalUserLang !== userLang) { - setUserLang(globalUserLang); + // ์–ธ์–ด ๋ณ€๊ฒฝ ์ฝœ๋ฐฑ ๋“ฑ๋ก + const handleLanguageChange = (newLang: string) => { + console.log("๐Ÿ”„ ์–ธ์–ด ๋ณ€๊ฒฝ ๊ฐ์ง€ (์ฆ‰์‹œ):", { from: userLang, to: newLang }); + setUserLang(newLang); + }; + + languageChangeCallbacks.add(handleLanguageChange); + + // ์ดˆ๊ธฐ ์–ธ์–ด ์„ค์ • + const currentLang = (window as any).__GLOBAL_USER_LANG || localStorage.getItem("userLocale") || globalUserLang; + if (currentLang && currentLang !== userLang) { + setUserLang(currentLang); } - }, []); // ์˜์กด์„ฑ ๋ฐฐ์—ด์„ ๋น„์›Œ์„œ ํ•œ ๋ฒˆ๋งŒ ์‹คํ–‰ + + // ํด๋ฆฐ์—…: ์ฝœ๋ฐฑ ์ œ๊ฑฐ + return () => { + languageChangeCallbacks.delete(handleLanguageChange); + }; + }, []); // ํ•œ ๋ฒˆ๋งŒ ๋“ฑ๋ก // ์–ธ์–ด ๋ณ€๊ฒฝ ์‹œ ์ „์—ญ ์ฝœ๋ฐฑ ํ˜ธ์ถœ (๋ฌดํ•œ ๋ฃจํ”„ ๋ฐฉ์ง€) useEffect(() => { @@ -126,8 +160,10 @@ export const useMultiLang = (options: { companyCode?: string } = {}) => { } }; - // ์–ธ์–ด ๋ณ€๊ฒฝ (๋ฌดํ•œ ๋ฃจํ”„ ๋ฐฉ์ง€) + // ๐ŸŽฏ ํšจ์œจ์ ์ธ ์–ธ์–ด ๋ณ€๊ฒฝ ํ•จ์ˆ˜ (์ฝœ๋ฐฑ ๋ฐฉ์‹) const changeLang = async (newLang: string) => { + console.log("๐Ÿš€ useMultiLang changeLang ํ˜ธ์ถœ:", { newLang, userLang }); + // ๊ฐ™์€ ์–ธ์–ด๋กœ ๋ณ€๊ฒฝํ•˜๋ ค๋Š” ๊ฒฝ์šฐ ๋ฌด์‹œ if (newLang === userLang) { console.log("๐Ÿ”„ ๊ฐ™์€ ์–ธ์–ด๋กœ ๋ณ€๊ฒฝ ์‹œ๋„ ๋ฌด์‹œ:", newLang); @@ -143,19 +179,17 @@ export const useMultiLang = (options: { companyCode?: string } = {}) => { }); if (response.data.success) { - // ์ „์—ญ ์ƒํƒœ ๋จผ์ € ์—…๋ฐ์ดํŠธ - globalUserLang = newLang; - // ๋กœ์ปฌ ์ƒํƒœ ์—…๋ฐ์ดํŠธ - setUserLang(newLang); - console.log("โœ… ์‚ฌ์šฉ์ž ๋กœ์ผ€์ผ ๋ณ€๊ฒฝ ์„ฑ๊ณต:", newLang); + // ๐ŸŽฏ ํ•ต์‹ฌ: ์ฆ‰์‹œ ๋ชจ๋“  ์ปดํฌ๋„ŒํŠธ์— ์•Œ๋ฆผ (ํด๋ง ์—†์ด!) + notifyLanguageChange(newLang); + + console.log("โœ… ์–ธ์–ด ๋ณ€๊ฒฝ ์™„๋ฃŒ ๋ฐ ๋ชจ๋“  ์ปดํฌ๋„ŒํŠธ์— ์ฆ‰์‹œ ์•Œ๋ฆผ:", newLang); } else { console.error("โŒ ์‚ฌ์šฉ์ž ๋กœ์ผ€์ผ ๋ณ€๊ฒฝ ์‹คํŒจ:", response.data.message); } } catch (error) { console.error("โŒ ์‚ฌ์šฉ์ž ๋กœ์ผ€์ผ ๋ณ€๊ฒฝ ์ค‘ ์˜ค๋ฅ˜:", error); - // ์˜ค๋ฅ˜ ์‹œ์—๋„ ๋กœ์ปฌ ์ƒํƒœ๋Š” ๋ณ€๊ฒฝ - globalUserLang = newLang; - setUserLang(newLang); + // ์˜ค๋ฅ˜ ์‹œ์—๋„ ํด๋ผ์ด์–ธํŠธ ์ƒํƒœ๋Š” ๋ณ€๊ฒฝ + notifyLanguageChange(newLang); } }; diff --git a/frontend/hooks/useProfile.ts b/frontend/hooks/useProfile.ts index b4aaaf00..882c0293 100644 --- a/frontend/hooks/useProfile.ts +++ b/frontend/hooks/useProfile.ts @@ -68,7 +68,7 @@ export const useProfile = (user: any, refreshUserData: () => Promise, refr try { const response = await apiCall("GET", "/admin/departments"); if (response.success && response.data) { - setDepartments(response.data); + setDepartments(response.data as Array<{ deptCode: string; deptName: string }>); } } catch (error) { console.error("๋ถ€์„œ ๋ชฉ๋ก ๋กœ๋“œ ์‹คํŒจ:", error); @@ -227,17 +227,14 @@ export const useProfile = (user: any, refreshUserData: () => Promise, refr console.log("ํ”„๋กœํ•„ ์—…๋ฐ์ดํŠธ ์‘๋‹ต:", response); - if (response.result) { + if (response.success || (response as any).result) { // locale์ด ๋ณ€๊ฒฝ๋œ ๊ฒฝ์šฐ ์ „์—ญ ๋ณ€์ˆ˜์™€ localStorage ์—…๋ฐ์ดํŠธ const localeChanged = modalState.formData.locale && modalState.formData.locale !== user.locale; if (localeChanged) { - if (typeof window !== "undefined") { - // ์ „์—ญ ๋ณ€์ˆ˜ ์—…๋ฐ์ดํŠธ - (window as any).__GLOBAL_USER_LANG = modalState.formData.locale; - // localStorage ์—…๋ฐ์ดํŠธ - localStorage.setItem("userLocale", modalState.formData.locale); - console.log("๐ŸŒ ์‚ฌ์šฉ์ž locale ์—…๋ฐ์ดํŠธ:", modalState.formData.locale); - } + // ๐ŸŽฏ useMultiLang์˜ ์ฝœ๋ฐฑ ์‹œ์Šคํ…œ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋“  ์ปดํฌ๋„ŒํŠธ์— ์ฆ‰์‹œ ์•Œ๋ฆผ + const { notifyLanguageChange } = await import("@/hooks/useMultiLang"); + notifyLanguageChange(modalState.formData.locale); + console.log("๐ŸŒ ์‚ฌ์šฉ์ž locale ์—…๋ฐ์ดํŠธ (์ฝœ๋ฐฑ ๋ฐฉ์‹):", modalState.formData.locale); } // ์„ฑ๊ณต: ์‚ฌ์šฉ์ž ์ •๋ณด ์ƒˆ๋กœ๊ณ ์นจ @@ -256,7 +253,7 @@ export const useProfile = (user: any, refreshUserData: () => Promise, refr })); showAlert("์ €์žฅ ์™„๋ฃŒ", "ํ”„๋กœํ•„์ด ์„ฑ๊ณต์ ์œผ๋กœ ์—…๋ฐ์ดํŠธ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.", "success"); } else { - throw new Error(response.message || "ํ”„๋กœํ•„ ์—…๋ฐ์ดํŠธ ์‹คํŒจ"); + throw new Error((response as any).message || "ํ”„๋กœํ•„ ์—…๋ฐ์ดํŠธ ์‹คํŒจ"); } } catch (error) { console.error("ํ”„๋กœํ•„ ์ €์žฅ ์‹คํŒจ:", error);