From 6863e3bc65389b0e199f99a90ceadfab6778a008 Mon Sep 17 00:00:00 2001 From: Alexander Borg Date: Fri, 19 Sep 2025 13:20:04 +0200 Subject: [PATCH] Fix jwt-token --- client/src/components/Layout.jsx | 32 +++++----- client/src/components/TestTranslation.jsx | 30 +++++++++ .../components/common/LanguageSelector.jsx | 18 +++--- client/src/utils/tempTranslations.js | 61 +++++++++++++++++++ management/src/components/Layout.jsx | 12 ++-- 5 files changed, 126 insertions(+), 27 deletions(-) create mode 100644 client/src/components/TestTranslation.jsx create mode 100644 client/src/utils/tempTranslations.js diff --git a/client/src/components/Layout.jsx b/client/src/components/Layout.jsx index cf5b3e6..62ab631 100644 --- a/client/src/components/Layout.jsx +++ b/client/src/components/Layout.jsx @@ -1,10 +1,12 @@ import React, { useState } from 'react'; import { Outlet, Link, useLocation } from 'react-router-dom'; +// import { useTranslation } from 'react-i18next'; // Commented out until Docker rebuild import { useAuth } from '../contexts/AuthContext'; import { useSocket } from '../contexts/SocketContext'; import DebugToggle from './DebugToggle'; import LanguageSelector from './common/LanguageSelector'; import { canAccessSettings, hasPermission } from '../utils/rbac'; +import { t } from '../utils/tempTranslations'; // Temporary translation system import { HomeIcon, MapIcon, @@ -21,20 +23,22 @@ import { } from '@heroicons/react/24/outline'; import classNames from 'classnames'; -const baseNavigation = [ - { name: 'Dashboard', href: '/', icon: HomeIcon }, - { name: 'Map View', href: '/map', icon: MapIcon }, - { name: 'Devices', href: '/devices', icon: ServerIcon }, - { name: 'Detections', href: '/detections', icon: ExclamationTriangleIcon }, - { name: 'Alerts', href: '/alerts', icon: BellIcon }, -]; - const Layout = () => { const [sidebarOpen, setSidebarOpen] = useState(false); + // const { t } = useTranslation(); // Commented out until Docker rebuild const { user, logout } = useAuth(); const { connected, recentDetections } = useSocket(); const location = useLocation(); + // Build navigation based on user permissions with translations + const baseNavigation = [ + { name: t('navigation.dashboard'), href: '/', icon: HomeIcon }, + { name: 'Map View', href: '/map', icon: MapIcon }, // TODO: Add to translations + { name: t('navigation.devices'), href: '/devices', icon: ServerIcon }, + { name: t('navigation.detections'), href: '/detections', icon: ExclamationTriangleIcon }, + { name: t('navigation.alerts'), href: '/alerts', icon: BellIcon }, + ]; + // Build navigation based on user permissions const navigation = React.useMemo(() => { if (!user?.role) { @@ -45,16 +49,16 @@ const Layout = () => { // Add Settings if user has any settings permissions if (canAccessSettings(user.role)) { - nav.push({ name: 'Settings', href: '/settings', icon: CogIcon }); + nav.push({ name: t('navigation.settings'), href: '/settings', icon: CogIcon }); } // Add Debug if user has debug permissions if (hasPermission(user.role, 'debug.access')) { - nav.push({ name: 'Debug', href: '/debug', icon: BugAntIcon }); + nav.push({ name: 'Debug', href: '/debug', icon: BugAntIcon }); // TODO: Add to translations } return nav; - }, [user]); + }, [user]); // Removed t dependency until Docker rebuild return (
@@ -120,7 +124,7 @@ const Layout = () => { ) : ( )} - {connected ? 'Connected' : 'Disconnected'} + {connected ? t('dashboard.online') : t('dashboard.offline')}
@@ -128,7 +132,7 @@ const Layout = () => { {recentDetections.length > 0 && (
- {recentDetections.length} recent + {recentDetections.length} {t('dashboard.recentDetections').toLowerCase()}
)} @@ -146,7 +150,7 @@ const Layout = () => { onClick={logout} className="text-sm text-gray-500 hover:text-gray-700" > - Logout + {t('navigation.logout')} diff --git a/client/src/components/TestTranslation.jsx b/client/src/components/TestTranslation.jsx new file mode 100644 index 0000000..a1cb560 --- /dev/null +++ b/client/src/components/TestTranslation.jsx @@ -0,0 +1,30 @@ +import React from 'react'; +import { useTranslation } from 'react-i18next'; + +const TestTranslation = () => { + const { t, i18n } = useTranslation(); + + return ( +
+

Translation Test

+

Current language: {i18n.language}

+

Dashboard translation: {t('navigation.dashboard')}

+

Loading translation: {t('common.loading')}

+

Error translation: {t('common.error')}

+ + +
+ ); +}; + +export default TestTranslation; \ No newline at end of file diff --git a/client/src/components/common/LanguageSelector.jsx b/client/src/components/common/LanguageSelector.jsx index e40796d..80987d3 100644 --- a/client/src/components/common/LanguageSelector.jsx +++ b/client/src/components/common/LanguageSelector.jsx @@ -1,8 +1,9 @@ import React from 'react'; -import { useTranslation } from 'react-i18next'; +// import { useTranslation } from 'react-i18next'; // Commented out until Docker rebuild import { Menu, Transition } from '@headlessui/react'; import { Fragment } from 'react'; import { GlobeAltIcon, ChevronDownIcon } from '@heroicons/react/24/outline'; +import { getCurrentLanguage, changeLanguage } from '../../utils/tempTranslations'; // Temporary system const languages = [ { code: 'en', name: 'English', flag: '🇺🇸' }, @@ -10,12 +11,13 @@ const languages = [ ]; export default function LanguageSelector({ className = '' }) { - const { i18n, t } = useTranslation(); + // const { i18n, t } = useTranslation(); // Commented out until Docker rebuild + const currentLang = getCurrentLanguage(); - const currentLanguage = languages.find(lang => lang.code === i18n.language) || languages[0]; + const currentLanguage = languages.find(lang => lang.code === currentLang) || languages[0]; - const changeLanguage = (languageCode) => { - i18n.changeLanguage(languageCode); + const handleChangeLanguage = (languageCode) => { + changeLanguage(languageCode); }; return ( @@ -44,16 +46,16 @@ export default function LanguageSelector({ className = '' }) { {({ active }) => (