/** * useTenant Hook * * React hook for accessing single tenant data via TanStack Query. * Provides tenant details by ID with automatic caching and background refetch. * * Features: * - Automatic caching and deduplication * - Background refetch on window focus * - Loading and error states * - Automatic retries on failure * * @layer Presentation */ import { useQuery } from '@tanstack/react-query'; import { queryKeys } from '@/lib/query-keys'; import { tenantsApi } from '@/infrastructure/http/api/tenant'; /** * useTenant Hook * * Fetches single tenant by ID using TanStack Query. * * @param tenantId - Tenant ID to fetch (undefined to disable query) * @returns TanStack Query result with tenant data * * @example * ```tsx * function TenantProfile({ tenantId }: { tenantId?: string }) { * const { data: tenant, isLoading, error, refetch } = useTenant(tenantId); * * if (isLoading) return
Loading...
; * if (error) return
Error: {error.message}
; * if (!tenant) return
Tenant not found
; * * return ( *
*

{tenant.name}

*

{tenant.domain}

*

Status: {tenant.status}

* *
* ); * } * ``` */ export function useTenant(tenantId: string | undefined) { return useQuery({ queryKey: queryKeys.tenants.detail(tenantId!), queryFn: async () => { const tenant = await tenantsApi.getTenant(tenantId!); return tenant; }, enabled: !!tenantId, }); }