chore: Disable account switcher for single-account users (#10768)

This commit is contained in:
Sivin Varghese
2025-01-27 13:19:48 +05:30
committed by GitHub
parent ef7bf66476
commit d925729444
2 changed files with 19 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
<script setup> <script setup>
import { computed } from 'vue';
import { useAccount } from 'dashboard/composables/useAccount'; import { useAccount } from 'dashboard/composables/useAccount';
import { useMapGetter } from 'dashboard/composables/store'; import { useMapGetter } from 'dashboard/composables/store';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
@@ -19,6 +20,12 @@ const { accountId, currentAccount } = useAccount();
const currentUser = useMapGetter('getCurrentUser'); const currentUser = useMapGetter('getCurrentUser');
const globalConfig = useMapGetter('globalConfig/get'); const globalConfig = useMapGetter('globalConfig/get');
const userAccounts = useMapGetter('getUserAccounts');
const showAccountSwitcher = computed(
() => userAccounts.value.length > 1 && currentAccount.value.name
);
const onChangeAccount = newId => { const onChangeAccount = newId => {
const accountUrl = `/app/accounts/${newId}/dashboard`; const accountUrl = `/app/accounts/${newId}/dashboard`;
window.location.href = accountUrl; window.location.href = accountUrl;
@@ -37,9 +44,14 @@ const emitNewAccount = () => {
:data-account-id="accountId" :data-account-id="accountId"
aria-haspopup="listbox" aria-haspopup="listbox"
aria-controls="account-options" aria-controls="account-options"
class="flex items-center gap-2 justify-between w-full rounded-lg hover:bg-n-alpha-1 px-2" class="flex items-center gap-2 justify-between w-full rounded-lg px-2"
:class="{ 'bg-n-alpha-1': isOpen }" :class="[
@click="toggle" isOpen && 'bg-n-alpha-1',
showAccountSwitcher
? 'hover:bg-n-alpha-1 cursor-pointer'
: 'cursor-default',
]"
@click="() => showAccountSwitcher && toggle()"
> >
<span <span
class="text-sm font-medium leading-5 text-n-slate-12 truncate" class="text-sm font-medium leading-5 text-n-slate-12 truncate"
@@ -49,13 +61,14 @@ const emitNewAccount = () => {
</span> </span>
<span <span
v-if="showAccountSwitcher"
aria-hidden="true" aria-hidden="true"
class="i-lucide-chevron-down size-4 text-n-slate-10 flex-shrink-0" class="i-lucide-chevron-down size-4 text-n-slate-10 flex-shrink-0"
/> />
</button> </button>
</template> </template>
<DropdownBody class="min-w-80 z-50"> <DropdownBody v-if="showAccountSwitcher" class="min-w-80 z-50">
<DropdownSection :title="t('SIDEBAR_ITEMS.SWITCH_WORKSPACE')"> <DropdownSection :title="t('SIDEBAR_ITEMS.SWITCH_ACCOUNT')">
<DropdownItem <DropdownItem
v-for="account in currentUser.accounts" v-for="account in currentUser.accounts"
:id="`account-${account.id}`" :id="`account-${account.id}`"

View File

@@ -194,7 +194,7 @@
"SIDEBAR_ITEMS": { "SIDEBAR_ITEMS": {
"CHANGE_AVAILABILITY_STATUS": "Change", "CHANGE_AVAILABILITY_STATUS": "Change",
"CHANGE_ACCOUNTS": "Switch account", "CHANGE_ACCOUNTS": "Switch account",
"SWITCH_WORKSPACE": "Switch workspace", "SWITCH_ACCOUNT": "Switch account",
"CONTACT_SUPPORT": "Contact support", "CONTACT_SUPPORT": "Contact support",
"SELECTOR_SUBTITLE": "Select an account from the following list", "SELECTOR_SUBTITLE": "Select an account from the following list",
"PROFILE_SETTINGS": "Profile settings", "PROFILE_SETTINGS": "Profile settings",