Skip to content

feat: Implement offline-first queue for merchant mutations (#84)#112

Open
johnephraim949-web wants to merge 1 commit into
ericmt-98:mainfrom
johnephraim949-web:feat/offline-queue-merchant-mutations
Open

feat: Implement offline-first queue for merchant mutations (#84)#112
johnephraim949-web wants to merge 1 commit into
ericmt-98:mainfrom
johnephraim949-web:feat/offline-queue-merchant-mutations

Conversation

@johnephraim949-web
Copy link
Copy Markdown

@johnephraim949-web johnephraim949-web commented May 29, 2026

Closes #84

📋 Summary

Implements a complete offline-first queue system for merchant mutations addressing issue #84.

🎯 Acceptance Criteria ✅

  • Changing availability in airplane mode does not crash the app
  • User sees "pendiente de sincronizar" indicator
  • On reconnect the queue flushes and clears
  • Conflicts are shown with a clear action

📦 Implementation

New Services

  • offlineQueue.ts - IndexedDB persistence layer
  • offlineQueueManager.ts - Network monitoring and queue flushing
  • useOfflineQueue.ts - React hook integration

Enhanced Components

  • MerchantSettings.tsx - With pending_sync indicators
  • api.ts - Offline-aware wrappers

New UI Components

  • MerchantAvailabilityToggle.tsx - Availability with offline support
  • OfflineQueueStatus.tsx - Queue status display

Documentation

  • OFFLINE_QUEUE_IMPLEMENTATION.md - Complete implementation guide
  • 20260529_offline_mutations.sql - Optional backend schema

🔒 Scope

Implemented: ✅ IndexedDB queue, availability/settings mutations, pending_sync UI, auto-sync on reconnect, error handling, persistent storage

Not Implemented: ❌ Full offline trades, service worker caching, exponential backoff

🚀 Related

)

Resolves ericmt-98#84 by implementing a local IndexedDB queue for idempotent
merchant mutations (availability and settings changes) in areas with
intermittent connectivity.

## Changes

### New Services
- `offlineQueue.ts`: IndexedDB queue management (add, sync, retrieve mutations)
- `offlineQueueManager.ts`: Network monitoring and automatic queue flushing
- `useOfflineQueue.ts`: React hook for offline queue integration in components

### Updated Components
- `MerchantSettings.tsx`: Enhanced with pending_sync UI indicators and offline support
- `api.ts`: Added offline-aware wrappers for availability and config mutations

### New UI Components
- `MerchantAvailabilityToggle.tsx`: Availability toggle with offline support
- `OfflineQueueStatus.tsx`: Global queue status display with manual retry

### Documentation & Database
- `OFFLINE_QUEUE_IMPLEMENTATION.md`: Comprehensive implementation guide
- `20260529_offline_mutations.sql`: Optional backend audit schema (future)

## Features Implemented

✅ Local IndexedDB queue for idempotent mutations (availability and settings only)
✅ Visible 'pendiente de sincronizar' indicator in merchant settings UI
✅ Automatic queue flush on network reconnection
✅ Simple conflict resolution (server wins for trades, client retry for settings)
✅ No financial operations allowed offline without backend confirmation
✅ Error handling with manual retry mechanism
✅ Persistent queue across page reloads
✅ Network status monitoring

## Acceptance Criteria Met

✅ Changing availability in airplane mode does not crash the app
✅ User sees 'pendiente de sincronizar' indicator
✅ On reconnect the queue flushes and clears
✅ Conflicts are shown with a clear action

## Implementation Details

- Uses native IndexedDB for client-side persistence
- Automatic network detection via window online/offline events
- Atomic sync operations with per-item error handling
- Compatible with existing backend endpoints (no backend changes required)
- Idempotent mutations only (safe to retry)
- Clear separation of concerns (service/hook/component layers)

## Testing Notes

Manual testing steps documented in OFFLINE_QUEUE_IMPLEMENTATION.md:
- Offline availability changes persist and sync on reconnect
- Multiple mutations queue in order and sync atomically
- Failed syncs show error UI with retry option
- Queue persists across browser reload
- Doesn't break existing online flow
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 29, 2026

@johnephraim949-web Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Offline-first queue for merchant mutations

1 participant