fix: links rendering in sidebar profile (#10574)

This pull request includes several changes to the `DropdownItem.vue` and `SidebarProfileMenu.vue` components to improve the handling of links.

Earlier we passed the link `/super_admin` to RouterLink directly, which would trigger validations internally and the dropdown item would not render in case of any errors. This PR fixes this by handling the native links appropriately

Fixes #10571
This commit is contained in:
Shivam Mishra
2024-12-12 07:12:46 +05:30
committed by GitHub
parent a3290bfd42
commit 99c699ea34
2 changed files with 16 additions and 11 deletions

View File

@@ -6,7 +6,8 @@ import { useDropdownContext } from './provider.js';
const props = defineProps({ const props = defineProps({
label: { type: String, default: '' }, label: { type: String, default: '' },
icon: { type: [String, Object, Function], default: '' }, icon: { type: [String, Object, Function], default: '' },
link: { type: String, default: '' }, link: { type: [String, Object], default: '' },
nativeLink: { type: Boolean, default: false },
click: { type: Function, default: null }, click: { type: Function, default: null },
preserveOpen: { type: Boolean, default: false }, preserveOpen: { type: Boolean, default: false },
}); });
@@ -18,7 +19,13 @@ defineOptions({
const { closeMenu } = useDropdownContext(); const { closeMenu } = useDropdownContext();
const componentIs = computed(() => { const componentIs = computed(() => {
if (props.link) return 'router-link'; if (props.link) {
if (props.nativeLink && typeof props.link === 'string') {
return 'a';
}
return 'router-link';
}
if (props.click) return 'button'; if (props.click) return 'button';
return 'div'; return 'div';
@@ -41,7 +48,8 @@ const triggerClick = () => {
:class="{ :class="{
'hover:bg-n-alpha-2 rounded-lg w-full gap-3': !$slots.default, 'hover:bg-n-alpha-2 rounded-lg w-full gap-3': !$slots.default,
}" }"
:href="props.link || null" :href="componentIs === 'a' ? props.link : null"
:to="componentIs === 'router-link' ? props.link : null"
@click="triggerClick" @click="triggerClick"
> >
<slot> <slot>

View File

@@ -1,7 +1,6 @@
<script setup> <script setup>
import { computed } from 'vue'; import { computed } from 'vue';
import Auth from 'dashboard/api/auth'; import Auth from 'dashboard/api/auth';
import { useRouter } from 'vue-router';
import { useMapGetter } from 'dashboard/composables/store'; import { useMapGetter } from 'dashboard/composables/store';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import Avatar from 'next/avatar/Avatar.vue'; import Avatar from 'next/avatar/Avatar.vue';
@@ -21,7 +20,6 @@ defineOptions({
}); });
const { t } = useI18n(); const { t } = useI18n();
const router = useRouter();
const globalConfig = useMapGetter('globalConfig/get'); const globalConfig = useMapGetter('globalConfig/get');
const currentUser = useMapGetter('getCurrentUser'); const currentUser = useMapGetter('getCurrentUser');
@@ -49,9 +47,7 @@ const menuItems = computed(() => {
show: true, show: true,
label: t('SIDEBAR_ITEMS.PROFILE_SETTINGS'), label: t('SIDEBAR_ITEMS.PROFILE_SETTINGS'),
icon: 'i-lucide-user-pen', icon: 'i-lucide-user-pen',
click: () => { link: { name: 'profile_settings_index' },
router.push({ name: 'profile_settings_index' });
},
}, },
{ {
show: true, show: true,
@@ -66,15 +62,16 @@ const menuItems = computed(() => {
show: true, show: true,
label: t('SIDEBAR_ITEMS.DOCS'), label: t('SIDEBAR_ITEMS.DOCS'),
icon: 'i-lucide-book', icon: 'i-lucide-book',
click: () => { link: 'https://www.chatwoot.com/hc/user-guide/en',
window.open('https://www.chatwoot.com/hc/user-guide/en', '_blank'); nativeLink: true,
}, target: '_blank',
}, },
{ {
show: currentUser.value.type === 'SuperAdmin', show: currentUser.value.type === 'SuperAdmin',
label: t('SIDEBAR_ITEMS.SUPER_ADMIN_CONSOLE'), label: t('SIDEBAR_ITEMS.SUPER_ADMIN_CONSOLE'),
icon: 'i-lucide-castle', icon: 'i-lucide-castle',
link: '/super_admin', link: '/super_admin',
nativeLink: true,
target: '_blank', target: '_blank',
}, },
{ {