feat: scope articles by brand
This commit is contained in:
@@ -22,14 +22,19 @@ import { useRoute, useRouter } from 'vue-router'
|
||||
import { brandsApi } from '@/lib/api'
|
||||
import { formatDateTime } from '@/lib/display'
|
||||
import { formatError } from '@/lib/errors'
|
||||
import { useCompanyStore } from '@/stores/company'
|
||||
|
||||
const queryClient = useQueryClient()
|
||||
const { t } = useI18n()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const companyStore = useCompanyStore()
|
||||
|
||||
const activeTab = ref<'questions' | 'competitors'>('questions')
|
||||
const selectedBrandId = ref<number | null>(null)
|
||||
const selectedBrandId = computed<number | null>({
|
||||
get: () => companyStore.currentBrandId,
|
||||
set: (brandId) => companyStore.setCurrentBrand(brandId),
|
||||
})
|
||||
|
||||
const brandModalOpen = ref(false)
|
||||
const editingBrandId = ref<number | null>(null)
|
||||
@@ -148,6 +153,7 @@ const brandMutations = {
|
||||
message.success(t('brands.messages.createBrand'))
|
||||
brandModalOpen.value = false
|
||||
selectedBrandId.value = brand.id
|
||||
companyStore.setCurrentBrand(brand.id)
|
||||
await invalidateBrandQueries()
|
||||
},
|
||||
onError: (error) => message.error(formatError(error)),
|
||||
@@ -320,6 +326,14 @@ function openBrandModal(brand?: Brand): void {
|
||||
brandModalOpen.value = true
|
||||
}
|
||||
|
||||
function selectBrand(brandId: number): void {
|
||||
if (!Number.isFinite(brandId) || brandId <= 0) {
|
||||
return
|
||||
}
|
||||
selectedBrandId.value = brandId
|
||||
void queryClient.invalidateQueries({ queryKey: ['brands'] })
|
||||
}
|
||||
|
||||
function ensureQuestionCreatable(): boolean {
|
||||
if (!selectedBrandId.value) {
|
||||
message.warning(t('brands.messages.chooseBrand'))
|
||||
@@ -414,6 +428,7 @@ async function invalidateBrandQueries(): Promise<void> {
|
||||
queryClient.invalidateQueries({ queryKey: ['brands'] }),
|
||||
queryClient.invalidateQueries({ queryKey: ['workspace'] }),
|
||||
])
|
||||
await companyStore.refreshBrands()
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -440,7 +455,7 @@ async function invalidateBrandQueries(): Promise<void> {
|
||||
:key="brand.id"
|
||||
class="brand-card"
|
||||
:class="{ 'brand-card--active': brand.id === selectedBrandId }"
|
||||
@click="selectedBrandId = brand.id"
|
||||
@click="selectBrand(brand.id)"
|
||||
>
|
||||
<div class="brand-card__top">
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user