Files
textbee/web/lib/api/query-keys.ts
isra el 497a14074a refactor: centralize data fetching into typed react-query hooks
Introduce a typed data layer under lib/api (query-key factory, response
types, feature hooks) plus shared lib/format and lib/status helpers, and
migrate the canonical dashboard consumers (subscription-info, overview,
device-list, api-keys) onto it, deleting their duplicated inline queries,
mutations and formatters.

List hooks keep the raw { data: [] } envelope in the cache and unwrap
per-observer with react-query `select`, so shared keys like ['devices']
stay compatible with the not-yet-migrated components that still read the
raw shape (avoids a cache-shape collision surfaced by the dashboard e2e).

Adds unit tests for the formatters and the hooks (against MSW). Build,
19 unit tests, and 2 e2e all green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-11 01:36:16 +03:00

21 lines
881 B
TypeScript

import type { ApiKeyStatusFilter } from './types'
// Single source of truth for react-query cache keys. Values intentionally match
// the ad-hoc string keys used across the app before this refactor (e.g.
// ['devices'], ['currentSubscription'], ['apiKeys', 'active']) so migrated and
// not-yet-migrated components still share the same cache entries.
export const queryKeys = {
currentUser: ['currentUser'] as const,
subscription: ['currentSubscription'] as const,
stats: ['stats'] as const,
devices: ['devices'] as const,
webhooks: ['webhooks'] as const,
billingPlans: ['billingPlans'] as const,
apiKeys: (status: ApiKeyStatusFilter = 'active') =>
['apiKeys', status] as const,
deviceMessages: (deviceId: string, filters?: Record<string, unknown>) =>
filters
? (['messages', deviceId, filters] as const)
: (['messages', deviceId] as const),
}