munch-ease-frontend/src/components/HouseholdSwitcher.vue
2025-11-01 13:44:58 +11:00

42 lines
1.1 KiB
Vue

<template>
<div v-if="enabled && households.length > 0" class="household-switcher">
<label>Household:</label>
<ul>
<li v-for="h in households" :key="h.slug">
<router-link :to="toHousehold(h.slug)" :class="{ active: h.slug === activeSlug }">
{{ h.name }}
</router-link>
</li>
</ul>
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue'
import { useRoute } from 'vue-router'
import { useAuth } from '@/composables/useAuth'
const enabled = (typeof process !== 'undefined' && (process.env?.VUE_APP_MULTITENANT_ENABLED === 'true'))
const route = useRoute()
const { households } = useAuth()
const activeSlug = computed(() => (typeof route.params.householdSlug === 'string' ? route.params.householdSlug : null))
function toHousehold(slug: string) {
if (enabled) return { name: 'mealplan', params: { householdSlug: slug } }
return { name: 'mealplan' }
}
</script>
<style scoped>
.household-switcher {
display: inline-block;
}
.household-switcher ul {
list-style: none;
display: inline-flex;
gap: 8px;
margin: 0 0 0 8px;
padding: 0;
}
</style>