feat(manager): shell navigation from modules + permission keys; profile menu language
Platform-v2 step 2.6a: - shell/nav.js: one nav definition (module + key per page) read by the sidebar, the page titles and a RouteGuard around the layout outlet (and /kds): a module that's off hides its items and its routes say "turned off"; a missing key hides the item and the route says "no access". Same keys as before (v1 permission names mapped), plus the module check - labels/breadcrumbs are keys in a new i18n namespace `manager` (en + el) - removed the browser-only feature toggles (usePhase2Features, Settings -> Λειτουργίες, F-033), PermissionGuard and usePermissions - profile menu: language, saved to the profile (PATCH /api/auth/me) and bootstrap reloaded - e2e manager.mjs: module off/on, no-key user, language switch live + saved Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,20 @@
|
||||
import { useState, useEffect, useRef } from 'react'
|
||||
import { ChevronDown, User, LogOut } from 'lucide-react'
|
||||
import { ChevronDown, User, LogOut, Languages, Check } from 'lucide-react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { useAccess } from '@xenia/access'
|
||||
import { LANGUAGE_NAMES, setUserLanguage, useLanguage, useTranslation } from '@xenia/i18n'
|
||||
import client from '../api/client'
|
||||
|
||||
/**
|
||||
* The profile menu (plan step 2.6a): edit profile, language, sign out.
|
||||
* The language changes the screen at once, is saved to the user's profile
|
||||
* (PATCH /api/auth/me) and then the platform bootstrap is reloaded, so it also
|
||||
* applies on the next login and in the other apps (D-12).
|
||||
*/
|
||||
export default function UserMenuButton({ displayName, onEditProfile, onSignOut }) {
|
||||
const { t, i18n } = useTranslation('manager')
|
||||
const { language, languages } = useLanguage()
|
||||
const { refresh } = useAccess()
|
||||
const [open, setOpen] = useState(false)
|
||||
const ref = useRef(null)
|
||||
|
||||
@@ -22,32 +35,68 @@ export default function UserMenuButton({ displayName, onEditProfile, onSignOut }
|
||||
}
|
||||
}, [open])
|
||||
|
||||
async function chooseLanguage(lng) {
|
||||
setOpen(false)
|
||||
if (lng === language) return
|
||||
try {
|
||||
await setUserLanguage(i18n, lng, { save: l => client.patch('/api/auth/me', { language: l }) })
|
||||
await refresh()
|
||||
} catch {
|
||||
toast.error(t('common:language.notSaved'))
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative" ref={ref}>
|
||||
<button
|
||||
onClick={() => setOpen(o => !o)}
|
||||
className="flex items-center gap-1 text-[13px] text-slate-600 font-medium hover:text-slate-900 transition-colors"
|
||||
aria-haspopup="menu"
|
||||
aria-expanded={open}
|
||||
data-testid="user-menu"
|
||||
>
|
||||
{displayName}
|
||||
<ChevronDown className={`h-3.5 w-3.5 text-slate-400 transition-transform ${open ? 'rotate-180' : ''}`} />
|
||||
</button>
|
||||
|
||||
{open && (
|
||||
<div className="absolute right-0 top-full mt-1.5 w-44 rounded-xl border border-slate-200 bg-white shadow-lg py-1 z-50">
|
||||
<div className="absolute right-0 top-full mt-1.5 w-52 rounded-xl border border-slate-200 bg-white shadow-lg py-1 z-50" role="menu">
|
||||
<button
|
||||
role="menuitem"
|
||||
onClick={() => { setOpen(false); onEditProfile() }}
|
||||
className="flex w-full items-center gap-2.5 px-3.5 py-2 text-[13px] text-slate-700 hover:bg-slate-50 transition-colors"
|
||||
>
|
||||
<User className="h-3.5 w-3.5 text-slate-400" />
|
||||
Edit Profile
|
||||
{t('profile.edit')}
|
||||
</button>
|
||||
|
||||
<div className="my-1 border-t border-slate-100" />
|
||||
<div className="flex items-center gap-2.5 px-3.5 pt-1.5 pb-1 text-[11px] font-semibold uppercase tracking-wide text-slate-400">
|
||||
<Languages className="h-3.5 w-3.5" />
|
||||
{t('profile.language')}
|
||||
</div>
|
||||
{languages.map(lng => (
|
||||
<button
|
||||
key={lng}
|
||||
role="menuitemradio"
|
||||
aria-checked={lng === language}
|
||||
lang={lng}
|
||||
onClick={() => chooseLanguage(lng)}
|
||||
className="flex w-full items-center gap-2.5 px-3.5 py-2 pl-9 text-[13px] text-slate-700 hover:bg-slate-50 transition-colors"
|
||||
>
|
||||
<span className="flex-1 text-left">{LANGUAGE_NAMES[lng]}</span>
|
||||
{lng === language && <Check className="h-3.5 w-3.5 text-primary-700" />}
|
||||
</button>
|
||||
))}
|
||||
|
||||
<div className="my-1 border-t border-slate-100" />
|
||||
<button
|
||||
role="menuitem"
|
||||
onClick={() => { setOpen(false); onSignOut() }}
|
||||
className="flex w-full items-center gap-2.5 px-3.5 py-2 text-[13px] text-rose-500 hover:bg-rose-50 transition-colors"
|
||||
>
|
||||
<LogOut className="h-3.5 w-3.5" />
|
||||
Sign Out
|
||||
{t('profile.signOut')}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user