mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-25 00:31:13 -05:00
feat: Implement complete API optimization plan
This commit is contained in:
@@ -207,12 +207,14 @@ const handleUpdate = () => {
|
||||
## Component Migration Status
|
||||
|
||||
### ✅ Migrated Components
|
||||
- `SecurityTab.tsx` - Using `useSecurityMutations()`
|
||||
- `ReportsQueue.tsx` - Using `useReportActionMutation()`
|
||||
- `PrivacyTab.tsx` - Using `usePrivacyMutations()`
|
||||
- `LocationTab.tsx` - Using `useProfileLocationMutation()`
|
||||
- `AccountProfileTab.tsx` - Using `useProfileUpdateMutation()`
|
||||
- `BlockedUsers.tsx` - Using `useBlockUserMutation()`
|
||||
- `SecurityTab.tsx` - Using `useSecurityMutations()` ✅
|
||||
- `ReportsQueue.tsx` - Using `useReportActionMutation()` ✅
|
||||
- `PrivacyTab.tsx` - Using `usePrivacyMutations()` ✅
|
||||
- `LocationTab.tsx` - Using `useProfileLocationMutation()` ✅
|
||||
- `AccountProfileTab.tsx` - Using `useProfileUpdateMutation()` ✅
|
||||
- `BlockedUsers.tsx` - Using `useBlockUserMutation()` and `useBlockedUsers()` ✅
|
||||
- `PasswordUpdateDialog.tsx` - Using `usePasswordUpdateMutation()` ✅
|
||||
- `EmailChangeDialog.tsx` - Using `useEmailChangeMutation()` ✅
|
||||
|
||||
### 📊 Impact
|
||||
- **100%** of settings mutations now use mutation hooks
|
||||
@@ -220,7 +222,11 @@ const handleUpdate = () => {
|
||||
- **30%** faster perceived load times (optimistic updates)
|
||||
- **10%** fewer API calls (better cache invalidation)
|
||||
- **Zero** manual cache invalidation in components
|
||||
- **Zero** direct Supabase mutations in components
|
||||
|
||||
## Migration Checklist
|
||||
|
||||
When migrating a component:
|
||||
- [ ] Create custom mutation hook in appropriate directory
|
||||
- [ ] Use `useMutation` instead of direct Supabase calls
|
||||
- [ ] Implement `onError` callback with toast notifications
|
||||
@@ -232,27 +238,42 @@ const handleUpdate = () => {
|
||||
- [ ] Test optimistic updates if applicable
|
||||
- [ ] Add audit log creation where appropriate
|
||||
- [ ] Ensure proper type safety with TypeScript
|
||||
- [ ] Consider creating query hooks for data fetching instead of manual `useEffect`
|
||||
|
||||
## Available Mutation Hooks
|
||||
|
||||
### Profile & User Management
|
||||
- **`useProfileUpdateMutation`** - Profile updates (username, display name, bio, avatar)
|
||||
- Modifies: `profiles` table via `update_profile` RPC
|
||||
- Invalidates: profile, profile stats, profile activity, user search (if display name/username changed)
|
||||
- Features: Optimistic updates, automatic rollback
|
||||
- Features: Optimistic updates, automatic rollback, rate limiting, Novu sync
|
||||
|
||||
- **`useProfileLocationMutation`** - Location and personal info updates
|
||||
- Modifies: `profiles` table and `user_preferences` table
|
||||
- Invalidates: profile, profile stats, audit logs
|
||||
- Features: Optimistic updates, automatic rollback
|
||||
- Features: Optimistic updates, automatic rollback, audit logging
|
||||
|
||||
- **`usePrivacyMutations`** - Privacy settings updates
|
||||
- Modifies: `profiles` table and `user_preferences` table
|
||||
- Invalidates: profile, audit logs, user search (privacy affects visibility)
|
||||
- Features: Optimistic updates, automatic rollback
|
||||
- Features: Optimistic updates, automatic rollback, audit logging
|
||||
|
||||
### Security
|
||||
- **`useSecurityMutations`** - Session management
|
||||
- `revokeSession` - Revoke user sessions with automatic redirect for current session
|
||||
- Modifies: User sessions via `revoke_my_session` RPC
|
||||
- Invalidates: sessions list, audit logs
|
||||
|
||||
- **`usePasswordUpdateMutation`** - Password updates
|
||||
- Modifies: User password via Supabase Auth
|
||||
- Invalidates: audit logs
|
||||
- Features: MFA verification, audit logging, security notifications
|
||||
|
||||
- **`useEmailChangeMutation`** - Email address changes
|
||||
- Modifies: User email via Supabase Auth
|
||||
- Invalidates: audit logs
|
||||
- Features: Dual verification emails, audit logging, security notifications
|
||||
|
||||
### Moderation
|
||||
- **`useReportMutation`** - Submit user reports
|
||||
- Invalidates: moderation queue, moderation stats
|
||||
@@ -263,27 +284,27 @@ const handleUpdate = () => {
|
||||
|
||||
### Privacy & Blocking
|
||||
- **`useBlockUserMutation`** - Block/unblock users
|
||||
- Modifies: `user_blocks` table
|
||||
- Invalidates: blocked users list, audit logs
|
||||
- Features: Automatic audit logging
|
||||
|
||||
### Ride Credits
|
||||
- **`useRideCreditsMutation`** - Reorder ride credits
|
||||
- Modifies: User ride credits via `reorder_ride_credit` RPC
|
||||
- Invalidates: ride credits cache
|
||||
- Features: Optimistic drag-drop updates
|
||||
|
||||
### Admin
|
||||
- **`useAuditLogs`** - Query audit logs with pagination and filtering
|
||||
- Features: 2-minute stale time, disabled window focus refetch
|
||||
|
||||
### Profile & User Management
|
||||
- `useProfileUpdateMutation` - Profile updates (username, display name, bio)
|
||||
- `useProfileLocationMutation` - Location and personal info updates
|
||||
- `usePrivacyMutations` - Privacy settings updates
|
||||
## Query Hooks
|
||||
|
||||
### Security
|
||||
- `useSecurityMutations` - Session management (revoke sessions)
|
||||
|
||||
### Moderation
|
||||
- `useReportMutation` - Submit user reports
|
||||
- `useReportActionMutation` - Resolve/dismiss reports
|
||||
|
||||
### Admin
|
||||
- `useAuditLogs` - Query audit logs with pagination
|
||||
### Privacy
|
||||
- **`useBlockedUsers`** - Fetch blocked users for the authenticated user
|
||||
- Queries: `user_blocks` and `profiles` tables
|
||||
- Features: Automatic caching, refetch on window focus, 5-minute stale time
|
||||
- Returns: Array of blocked users with profile information
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user