feat: Implement offline-first queue for merchant mutations (#84)#112
Open
johnephraim949-web wants to merge 1 commit into
Open
feat: Implement offline-first queue for merchant mutations (#84)#112johnephraim949-web wants to merge 1 commit into
johnephraim949-web wants to merge 1 commit into
Conversation
) 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
|
@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! 🚀 |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #84
📋 Summary
Implements a complete offline-first queue system for merchant mutations addressing issue #84.
🎯 Acceptance Criteria ✅
📦 Implementation
New Services
Enhanced Components
New UI Components
Documentation
🔒 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