refactor(portal): extract shared partner types and data composables

Move partner domain types out of data/customers.ts into types/partner.ts so the fixture data exports can be removed later without breaking type imports. Add usePartnerTenants / usePartnerMrr composables wrapping the shared-key partner fetches.
This commit is contained in:
Ronni Baslund
2026-05-30 08:02:54 +02:00
parent 17ffd95a70
commit a51dc9a732
7 changed files with 163 additions and 20 deletions
@@ -0,0 +1,21 @@
// Shared fetch of the signed-in partner's customer tenants from
// /api/partner/tenants (platform-api /me/partner/tenants). Several pages need
// this list — dashboard, customers, and (later) billing — and they all key the
// fetch as 'partner-tenants', so Nuxt dedupes to a single round-trip and shared
// payload. Centralizing it here removes the divergent inline PartnerTenantDoc
// copies that drifted between pages.
//
// Synchronous (non-async) so `useFetch` is invoked directly in the caller's
// setup context — safe to call after another `await` in setup, unlike an async
// wrapper. Call WITHOUT await:
// const { tenants, refresh } = usePartnerTenants()
import type { PartnerTenantDoc } from '~/types/partner'
export function usePartnerTenants() {
const { data: tenants, refresh, error, pending } = useFetch<PartnerTenantDoc[]>(
'/api/partner/tenants',
{ key: 'partner-tenants', default: () => [] },
)
return { tenants, refresh, error, pending }
}