This commit is contained in:
@@ -11,6 +11,7 @@ const emit = defineEmits<{
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const { data: session, status, signOut } = useAuth()
|
||||
const isHome = computed(() => route.path === '/')
|
||||
const colorMode = useColorMode()
|
||||
const isDark = computed({
|
||||
@@ -25,10 +26,25 @@ const isDark = computed({
|
||||
const userMenuOpen = ref(false)
|
||||
const userMenuRoot = ref<HTMLElement | null>(null)
|
||||
|
||||
const user = computed(() => session.value?.user)
|
||||
const userEmail = computed(() => user.value?.email || 'user@example.com')
|
||||
const userName = computed(() => user.value?.name || 'User')
|
||||
const isAuthenticated = computed(() => status.value === 'authenticated')
|
||||
|
||||
function closeUserMenu() {
|
||||
userMenuOpen.value = false
|
||||
}
|
||||
|
||||
async function handleLogout() {
|
||||
try {
|
||||
userMenuOpen.value = false
|
||||
await signOut({ callbackUrl: '/login', redirect: true })
|
||||
} catch (error) {
|
||||
console.error('Logout failed:', error)
|
||||
await navigateTo('/login')
|
||||
}
|
||||
}
|
||||
|
||||
function onDocClick(e: MouseEvent) {
|
||||
const userEl = userMenuRoot.value
|
||||
if (userEl && userMenuOpen.value && !userEl.contains(e.target as Node)) {
|
||||
@@ -119,6 +135,8 @@ onUnmounted(() => document.removeEventListener('click', onDocClick))
|
||||
</span>
|
||||
</NuxtLink>
|
||||
|
||||
<LayoutOrgSelector />
|
||||
|
||||
<span class="mx-0.5 h-3 w-px" style="background: rgba(0,0,0,0.06);" />
|
||||
|
||||
<!-- User / Account -->
|
||||
@@ -146,6 +164,10 @@ onUnmounted(() => document.removeEventListener('click', onDocClick))
|
||||
v-show="userMenuOpen"
|
||||
class="absolute right-0 top-[calc(100%+8px)] z-50 w-56 overflow-hidden rounded-xl border border-[var(--sidebar-border)] bg-[var(--surface)] py-1 shadow-xl ring-1 ring-black/5"
|
||||
>
|
||||
<div class="px-3 py-2 border-b border-[var(--sidebar-border)]">
|
||||
<p class="text-sm font-medium text-[var(--text-primary)]">{{ userName }}</p>
|
||||
<p class="text-xs text-[var(--text-muted)]">{{ userEmail }}</p>
|
||||
</div>
|
||||
<NuxtLink
|
||||
to="/account"
|
||||
class="flex items-center gap-2 px-3 py-2.5 text-sm text-[var(--text-primary)] transition hover:bg-[var(--brand-faint)]"
|
||||
@@ -163,17 +185,13 @@ onUnmounted(() => document.removeEventListener('click', onDocClick))
|
||||
Software settings
|
||||
</NuxtLink>
|
||||
<div class="my-1 border-t border-[var(--sidebar-border)]" />
|
||||
<div class="px-3 py-1.5">
|
||||
<p class="text-[12px] font-medium text-[var(--text-primary)]">Session (mock)</p>
|
||||
<p class="text-[11px] text-[var(--text-muted)]">broker@demo.com</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-full items-center gap-2 px-3 py-2 text-left text-sm text-[var(--text-muted)] opacity-50 cursor-not-allowed"
|
||||
disabled
|
||||
class="flex w-full items-center gap-2 px-3 py-2 text-left text-sm text-[var(--text-muted)] hover:bg-[var(--brand-faint)] hover:text-[var(--text-primary)] transition"
|
||||
@click="handleLogout"
|
||||
>
|
||||
<UIcon name="i-heroicons-arrow-right-on-rectangle" class="h-4 w-4" />
|
||||
Sign out (soon)
|
||||
Sign out
|
||||
</button>
|
||||
</div>
|
||||
</Transition>
|
||||
|
||||
146
app/components/layout/OrgSelector.vue
Normal file
146
app/components/layout/OrgSelector.vue
Normal file
@@ -0,0 +1,146 @@
|
||||
<script setup lang="ts">
|
||||
|
||||
const { organizations, selectedOrg, selectOrg } = useOrganizationSelection()
|
||||
|
||||
const dropdownOpen = ref(false)
|
||||
const dropdownRoot = ref<HTMLElement | null>(null)
|
||||
|
||||
function toggleDropdown() {
|
||||
dropdownOpen.value = !dropdownOpen.value
|
||||
}
|
||||
|
||||
function closeDropdown() {
|
||||
dropdownOpen.value = false
|
||||
}
|
||||
|
||||
function onDocClick(e: MouseEvent) {
|
||||
const el = dropdownRoot.value
|
||||
if (el && dropdownOpen.value && !el.contains(e.target as Node)) {
|
||||
dropdownOpen.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => document.addEventListener('click', onDocClick))
|
||||
onUnmounted(() => document.removeEventListener('click', onDocClick))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="organizations.length > 0" ref="dropdownRoot" class="org-selector-root">
|
||||
<button
|
||||
type="button"
|
||||
class="org-selector-btn"
|
||||
aria-label="Organization selector"
|
||||
:aria-expanded="dropdownOpen"
|
||||
@click.stop="toggleDropdown"
|
||||
>
|
||||
<UIcon name="i-heroicons-building-office" style="width: 13px; height: 13px; flex-shrink: 0;" />
|
||||
<span class="org-selector-label">{{ selectedOrg?.orgSubDomain ?? 'Org' }}</span>
|
||||
<UIcon name="i-heroicons-chevron-down" style="width: 8px; height: 8px; opacity: 0.4; flex-shrink: 0;" />
|
||||
</button>
|
||||
<div
|
||||
v-show="dropdownOpen"
|
||||
class="org-dropdown"
|
||||
>
|
||||
<button
|
||||
v-for="org in organizations"
|
||||
:key="org.orgId"
|
||||
type="button"
|
||||
class="org-option"
|
||||
:class="{ 'org-option-active': org.orgId === selectedOrg?.orgId }"
|
||||
@click="selectOrg(org.orgId); closeDropdown()"
|
||||
>
|
||||
<UIcon
|
||||
name="i-heroicons-check"
|
||||
class="shrink-0"
|
||||
:class="org.orgId === selectedOrg?.orgId ? 'opacity-100' : 'opacity-0'"
|
||||
style="width: 14px; height: 14px;"
|
||||
/>
|
||||
<span class="org-option-label">{{ org.orgSubDomain }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.org-selector-root {
|
||||
position: relative;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.org-selector-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 2px 8px;
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
line-height: normal;
|
||||
color: #8a8a86;
|
||||
background: transparent;
|
||||
border: 1px solid rgba(0, 0, 0, 0.06);
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
transition: all 150ms ease;
|
||||
white-space: nowrap;
|
||||
box-sizing: content-box;
|
||||
height: auto;
|
||||
}
|
||||
.org-selector-btn:hover {
|
||||
color: var(--text-primary);
|
||||
background: rgba(0, 0, 0, 0.03);
|
||||
border-color: rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.org-selector-label {
|
||||
max-width: 100px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.org-dropdown {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: calc(100% + 6px);
|
||||
z-index: 50;
|
||||
min-width: 180px;
|
||||
max-width: 280px;
|
||||
overflow: hidden;
|
||||
border-radius: 12px;
|
||||
border: 1px solid var(--sidebar-border);
|
||||
background: var(--surface);
|
||||
padding: 4px 0;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(0, 0, 0, 0.03);
|
||||
}
|
||||
|
||||
.org-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
padding: 6px 12px;
|
||||
text-align: left;
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
background: transparent;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
transition: background 100ms ease;
|
||||
}
|
||||
.org-option:hover {
|
||||
background: var(--brand-faint);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
.org-option-active {
|
||||
color: var(--text-primary);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.org-option-label {
|
||||
max-width: 200px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user