fix(encounter): menu activation logic by syncing active
This commit is contained in:
No files matched your search
@@ -2,6 +2,12 @@
|
|||||||
// Components
|
// Components
|
||||||
import { Button } from '~/components/pub/ui/button'
|
import { Button } from '~/components/pub/ui/button'
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
// Track active menu item from query param
|
||||||
|
const activeMenu = computed(() => route.query.menu as string || '')
|
||||||
|
|
||||||
interface ButtonItems {
|
interface ButtonItems {
|
||||||
label: string
|
label: string
|
||||||
icon: string
|
icon: string
|
||||||
@@ -64,16 +70,20 @@ const itemsTwo: ButtonItems[] = [
|
|||||||
{
|
{
|
||||||
label: 'Tarif Tindakan',
|
label: 'Tarif Tindakan',
|
||||||
icon: 'i-lucide-banknote-arrow-down',
|
icon: 'i-lucide-banknote-arrow-down',
|
||||||
value: 'action-fee',
|
value: 'price-list',
|
||||||
type: 'icon',
|
type: 'icon',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Tarif Tindakan Paket',
|
label: 'Tarif Tindakan Paket',
|
||||||
icon: 'i-lucide-banknote-arrow-down',
|
icon: 'i-lucide-banknote-arrow-down',
|
||||||
value: 'action-fee-package',
|
value: 'price-list-package',
|
||||||
type: 'icon',
|
type: 'icon',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
function handleClick(value: string) {
|
||||||
|
router.replace({ path: route.path, query: { menu: value } })
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -83,7 +93,13 @@ const itemsTwo: ButtonItems[] = [
|
|||||||
<Button
|
<Button
|
||||||
v-for="item in itemsOne"
|
v-for="item in itemsOne"
|
||||||
:key="item.value"
|
:key="item.value"
|
||||||
class="flex items-center gap-2 rounded-lg border border-orange-300 bg-white px-3 py-1 text-sm font-medium text-orange-500 hover:bg-orange-400 hover:text-white"
|
:class="[
|
||||||
|
'flex items-center gap-2 rounded-lg border px-3 py-1 text-sm font-medium transition-colors',
|
||||||
|
activeMenu === item.value
|
||||||
|
? 'border-orange-500 bg-orange-500 text-white'
|
||||||
|
: 'border-orange-300 bg-white text-orange-500 hover:bg-orange-400 hover:text-white'
|
||||||
|
]"
|
||||||
|
@click="handleClick(item.value)"
|
||||||
>
|
>
|
||||||
<Icon
|
<Icon
|
||||||
:name="item.icon"
|
:name="item.icon"
|
||||||
@@ -97,7 +113,13 @@ const itemsTwo: ButtonItems[] = [
|
|||||||
<Button
|
<Button
|
||||||
v-for="item in itemsTwo"
|
v-for="item in itemsTwo"
|
||||||
:key="item.value"
|
:key="item.value"
|
||||||
class="flex items-center gap-2 rounded-lg border border-orange-300 bg-white px-3 py-1 text-sm font-medium text-orange-500 hover:bg-orange-400 hover:text-white"
|
:class="[
|
||||||
|
'flex items-center gap-2 rounded-lg border px-3 py-1 text-sm font-medium transition-colors',
|
||||||
|
activeMenu === item.value
|
||||||
|
? 'border-orange-500 bg-orange-500 text-white'
|
||||||
|
: 'border-orange-300 bg-white text-orange-500 hover:bg-orange-400 hover:text-white'
|
||||||
|
]"
|
||||||
|
@click="handleClick(item.value)"
|
||||||
>
|
>
|
||||||
<Icon
|
<Icon
|
||||||
:name="item.icon"
|
:name="item.icon"
|
||||||
|
|||||||
@@ -37,10 +37,10 @@ const tabs = ref([] as any)
|
|||||||
const currentDisplay = ref(props.display ?? 'tab')
|
const currentDisplay = ref(props.display ?? 'tab')
|
||||||
|
|
||||||
// activeTab selalu sinkron dengan query param
|
// activeTab selalu sinkron dengan query param
|
||||||
const activeTab = computed({
|
const activeMenu = computed({
|
||||||
get: () => (route.query?.tab && typeof route.query.tab === 'string' ? route.query.tab : 'status'),
|
get: () => (route.query?.menu && typeof route.query.menu === 'string' ? route.query.menu : 'status'),
|
||||||
set: (val: string) => {
|
set: (value: string) => {
|
||||||
router.replace({ path: route.path, query: { tab: val } })
|
router.replace({ path: route.path, query: { menu: value } })
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -413,14 +413,14 @@ onMounted(async () => {
|
|||||||
<CompTab
|
<CompTab
|
||||||
v-if="currentDisplay === 'tab'"
|
v-if="currentDisplay === 'tab'"
|
||||||
:data="tabs"
|
:data="tabs"
|
||||||
:initial-active-tab="activeTab"
|
:initial-active-tab="activeMenu"
|
||||||
@change-tab="activeTab = $event"
|
@change-tab="activeMenu = $event"
|
||||||
/>
|
/>
|
||||||
<CompMenu
|
<CompMenu
|
||||||
v-else-if="currentDisplay === 'menu'"
|
v-else-if="currentDisplay === 'menu'"
|
||||||
:data="tabs"
|
:data="tabs"
|
||||||
:initial-active-tab="activeTab"
|
:initial-active-menu="activeMenu"
|
||||||
@change-tab="activeTab = $event"
|
@change-menu="activeMenu = $event"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -2,11 +2,11 @@
|
|||||||
import { type TabItem } from '../comp-tab/type'
|
import { type TabItem } from '../comp-tab/type'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
initialActiveTab: string
|
initialActiveMenu: string
|
||||||
data: TabItem[]
|
data: TabItem[]
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const activeMenu = ref(props.initialActiveTab)
|
const activeMenu = ref(props.initialActiveMenu)
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
changeMenu: [value: string]
|
changeMenu: [value: string]
|
||||||
}>()
|
}>()
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 2.1 MiB |
Reference in New Issue
Block a user