From 99c699ea3466fe0cfdcc72e8b424ceea738929f5 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 12 Dec 2024 07:12:46 +0530 Subject: [PATCH] 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 --- .../dropdown-menu/base/DropdownItem.vue | 14 +++++++++++--- .../components-next/sidebar/SidebarProfileMenu.vue | 13 +++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app/javascript/dashboard/components-next/dropdown-menu/base/DropdownItem.vue b/app/javascript/dashboard/components-next/dropdown-menu/base/DropdownItem.vue index 821b4218b..9db3a09d4 100644 --- a/app/javascript/dashboard/components-next/dropdown-menu/base/DropdownItem.vue +++ b/app/javascript/dashboard/components-next/dropdown-menu/base/DropdownItem.vue @@ -6,7 +6,8 @@ import { useDropdownContext } from './provider.js'; const props = defineProps({ label: { type: String, 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 }, preserveOpen: { type: Boolean, default: false }, }); @@ -18,7 +19,13 @@ defineOptions({ const { closeMenu } = useDropdownContext(); 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'; return 'div'; @@ -41,7 +48,8 @@ const triggerClick = () => { :class="{ '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" > diff --git a/app/javascript/dashboard/components-next/sidebar/SidebarProfileMenu.vue b/app/javascript/dashboard/components-next/sidebar/SidebarProfileMenu.vue index b9bb9f421..7498ecd91 100644 --- a/app/javascript/dashboard/components-next/sidebar/SidebarProfileMenu.vue +++ b/app/javascript/dashboard/components-next/sidebar/SidebarProfileMenu.vue @@ -1,7 +1,6 @@