Skip to content

fix(dashboard): analytics client, auth hook caching, mutation error handling#11

Merged
bsatrom merged 3 commits intomainfrom
fix/dashboard-analytics-auth-errors
Apr 17, 2026
Merged

fix(dashboard): analytics client, auth hook caching, mutation error handling#11
bsatrom merged 3 commits intomainfrom
fix/dashboard-analytics-auth-errors

Conversation

@bsatrom
Copy link
Copy Markdown
Member

@bsatrom bsatrom commented Apr 15, 2026

Summary

  • Refactor analytics.ts API functions to use shared apiFetch/apiPost/apiGet instead of duplicating auth token plumbing in every function (~150 lines removed)
  • Consolidate useIsAdmin, useUserGroups, useCanSendCommands onto a single shared TanStack Query cache entry — eliminates redundant fetchAuthSession() calls when multiple components mount simultaneously
  • Fix DisplayPreferences and FleetDefaults to only clear hasChanges after a successful save, not before — prevents silently disabling the save button when the API call fails; also adds error feedback UI to both
  • Fix catch (error: any) in Analytics.tsx to use proper TypeScript narrowing
  • Fix index-based key on chat messages to use stable type-timestamp identity
  • Tighten QueryResult.data from any[] to Record<string, string | number | boolean | null>[] via new QueryRow type alias
  • Fix missing Satellite lucide import in DeviceDetail.tsx

Test plan

  • Analytics chat queries execute and display results correctly
  • Auth groups are fetched once even when multiple admin-checking hooks mount simultaneously (check Network tab — only one Cognito call)
  • When saving display preferences fails (network error), the Save button remains enabled and an error message appears
  • When saving fleet defaults fails, the Save button remains enabled and an error message appears
  • TypeScript build is clean (npx tsc --noEmit)

🤖 Generated with Claude Code

bsatrom and others added 3 commits April 14, 2026 17:20
…or handling, type safety

- Refactor analytics.ts to use shared apiFetch/apiGet/apiPost helpers instead of
  duplicating fetchAuthSession + raw fetch in every function (~150 lines removed)
- Consolidate useIsAdmin, useUserGroups, useCanSendCommands onto a single shared
  TanStack Query cache entry to eliminate redundant Cognito round-trips
- Fix DisplayPreferences and FleetDefaults to only clear hasChanges on mutation
  onSuccess callback, preventing silent save button disable on API failure
- Add error feedback UI to both settings components on mutation failure
- Fix catch (error: any) in Analytics.tsx with proper TypeScript narrowing
- Replace index-based chat message keys with stable type+timestamp identity
- Tighten QueryResult.data from any[] to QueryRow[] (Record<string, string|number|boolean|null>[])
- Fix missing Satellite import in DeviceDetail.tsx

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Resolve DeviceDetail.tsx conflict (keep Satellite icon import)
- Rewrite analytics.test.ts to mock ./client helpers instead of fetch
- Add QueryClientProvider wrapper to useAuth.test.tsx renderHook calls

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…cs-auth-errors

# Conflicts:
#	songbird-dashboard/src/components/settings/FleetDefaults.tsx
#	songbird-dashboard/src/pages/DeviceDetail.tsx
@bsatrom bsatrom merged commit 1817f2c into main Apr 17, 2026
1 check passed
@bsatrom bsatrom deleted the fix/dashboard-analytics-auth-errors branch April 17, 2026 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant