Skip to content

Latest commit

 

History

History
261 lines (194 loc) · 6.65 KB

File metadata and controls

261 lines (194 loc) · 6.65 KB

Transaction Pending Overlay & Enhanced Sidebar Implementation

Overview

This implementation adds two key features to the employer dashboard:

  1. Enhanced Sidebar Active States - Refined visual feedback with glow effects, left border indicators, and smooth transitions
  2. Transaction Pending Overlay - Real-time transaction notifications with WebSocket integration

Features Implemented

1. Enhanced Dashboard Sidebar Active States

Location: frontend/src/components/EmployerLayout.tsx

Improvements:

  • Active state now includes:
    • Accent-colored left border indicator (1px rounded)
    • Subtle glow effect using box-shadow
    • Enhanced color contrast with 18% accent background
    • Smooth transitions (200ms duration)
  • Hover states:
    • Icon scale animation (110% on hover)
    • Subtle translate-x effect (0.5px shift)
    • Background overlay on hover
  • Accessibility maintained with proper ARIA labels and focus states

Visual Changes:

Active State:
- Left border: 1px rounded accent color
- Background: accent color at 18% opacity
- Text: accent color
- Shadow: 0 0 20px rgba(74,240,184,0.15)

Hover State:
- Icon scales to 110%
- Slight horizontal shift (0.5px)
- Background overlay (white/5)

2. Transaction Pending Overlay

Components Created:

TransactionPendingOverlay.tsx

  • Fixed position overlay (bottom-right corner)
  • Supports multiple simultaneous notifications (max 5)
  • Three states: pending, confirmed, failed
  • Auto-dismiss after 5 seconds for completed transactions
  • Smooth slide-in/out animations
  • Links to Stellar Explorer for transaction details

Features:

  • Real-time status updates via WebSocket
  • Progress bar animation for pending transactions
  • Status-specific icons (spinner, checkmark, error)
  • Dismissible notifications
  • Responsive design (mobile-friendly)
  • Accessibility compliant (ARIA labels, live regions)

usePendingTransactions.ts Hook

  • Manages transaction notification state
  • WebSocket integration for real-time updates
  • Auto-dismiss logic for completed transactions
  • Maximum 5 notifications displayed at once
  • Timestamp tracking for each transaction

TransactionContext.tsx Provider

  • Global state management for transaction notifications
  • Makes notifications accessible throughout the app
  • Provides useTransactionNotifications hook

File Structure

frontend/src/
├── components/
│   ├── EmployerLayout.tsx (modified)
│   └── TransactionPendingOverlay.tsx (new)
├── hooks/
│   └── usePendingTransactions.ts (new)
├── contexts/
│   └── TransactionContext.tsx (new)
└── examples/
    └── TransactionNotificationExample.tsx (new)

Usage

Using Transaction Notifications in Your Components

import { useTransactionNotifications } from '../contexts/TransactionContext';

function MyPaymentComponent() {
  const { addTransaction, updateTransaction } = useTransactionNotifications();

  const handlePayment = async () => {
    // Add pending notification
    const txId = addTransaction({
      id: `payment-${Date.now()}`,
      type: 'payment',
      status: 'pending',
      description: 'Processing payroll payment to 5 employees',
    });

    try {
      // Process payment...
      const result = await processPayment();

      // Update to confirmed
      updateTransaction(txId, {
        status: 'confirmed',
        hash: result.transactionHash,
      });
    } catch (error) {
      // Update to failed
      updateTransaction(txId, {
        status: 'failed',
        description: `Payment failed: ${error.message}`,
      });
    }
  };

  return <button onClick={handlePayment}>Send Payment</button>;
}

Transaction Object Structure

interface PendingTransaction {
  id: string; // Unique identifier
  type: string; // Transaction type (e.g., 'payment', 'bulk-upload')
  status: "pending" | "confirmed" | "failed";
  hash?: string; // Stellar transaction hash (for explorer link)
  timestamp: number; // Unix timestamp
  description?: string; // Human-readable description
}

Integration Points

WebSocket Events

The overlay listens for transaction:update events:

socket.on("transaction:update", (data) => {
  // data: { id, status, hash }
});

Existing Integration

The overlay is automatically integrated into:

  • EmployerLayout - Wraps all employer routes
  • All pages under /employer/* have access to notifications

Styling

Uses the existing design system:

  • CSS variables from index.css
  • Tailwind CSS utilities
  • Consistent with app theme (dark/light mode support)
  • Backdrop blur effects for modern glass-morphism

Key CSS Variables Used:

  • --surface - Background color
  • --accent - Primary accent color
  • --success - Success state color
  • --danger - Error state color
  • --border-hi - Border color
  • --text - Text color
  • --muted - Muted text color

Accessibility

Both features maintain WCAG compliance:

Sidebar:

  • Proper ARIA labels on navigation
  • Focus visible states with outline
  • Keyboard navigation support
  • Screen reader friendly

Overlay:

  • role="status" for notifications
  • aria-live="polite" for updates
  • aria-label on interactive elements
  • Dismissible with keyboard

Performance Considerations

  • Maximum 5 notifications displayed
  • Auto-dismiss prevents notification buildup
  • Smooth CSS transitions (GPU-accelerated)
  • Efficient WebSocket event handling
  • Debounced state updates

Browser Support

  • Modern browsers (Chrome, Firefox, Safari, Edge)
  • CSS Grid and Flexbox
  • CSS custom properties
  • Backdrop filter support
  • WebSocket API

Testing

To test the implementation:

  1. Navigate to any employer route
  2. Trigger a transaction (payment, bulk upload, etc.)
  3. Observe the notification appear in bottom-right
  4. Check active state on sidebar navigation
  5. Verify WebSocket updates work in real-time

See frontend/src/examples/TransactionNotificationExample.tsx for a test component.

Future Enhancements

Possible improvements:

  • Sound notifications (optional)
  • Notification history panel
  • Grouped notifications for bulk operations
  • Custom notification templates
  • Notification preferences/settings
  • Desktop notifications API integration
  • Undo/retry actions for failed transactions

Dependencies

No new dependencies added. Uses existing:

  • React 19.0.0
  • React Router 7.9.6
  • Tailwind CSS 4.2.0
  • Lucide React (icons)
  • @stellar/design-system

Notes

  • The overlay is positioned fixed and won't interfere with page content
  • Mobile responsive (adjusts to smaller screens)
  • Works with existing WebSocket infrastructure
  • Compatible with existing transaction history page
  • No breaking changes to existing code