'use client' import { useState } from 'react' import { Card, CardContent, CardDescription, CardHeader, CardTitle, Button, Badge, CameraCapture, PhotoGallery, ShareButton, SyncQueueBadge, SyncQueueStatus, useBackgroundSync, useWakeLock, useWebShare, type CapturedPhoto, type Photo, } from '@kodeme-io/next-core-ui' import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@kodeme-io/next-core-ui' import { Camera, Cloud, Share2, Moon } from 'lucide-react' export default function FieldToolsPage() { const [showCamera, setShowCamera] = useState(false) const [photos, setPhotos] = useState([]) const { add, status } = useBackgroundSync() const { isActive: wakeLockActive, toggle: toggleWakeLock } = useWakeLock() const { isSupported: shareSupported } = useWebShare() const handleCapture = (capturedPhoto: CapturedPhoto) => { const newPhoto: Photo = { id: `photo-${Date.now()}`, url: capturedPhoto.dataUrl, name: `visit-${Date.now()}.jpg`, timestamp: capturedPhoto.timestamp, size: capturedPhoto.size, } setPhotos([...photos, newPhoto]) setShowCamera(false) } const handleDeletePhoto = (photoId: string) => { setPhotos(photos.filter((p) => p.id !== photoId)) } const handleSubmitVisit = async () => { // Simulate API call - queue it for offline sync await add({ tag: 'visit-submit', request: { url: '/api/visits', method: 'POST', headers: { 'Content-Type': 'application/json' }, body: { customerId: 'demo-customer-123', photos: photos.map((p) => p.url), notes: 'Customer visit with ' + photos.length + ' photos', timestamp: Date.now(), }, }, maxRetries: 5, priority: 1, }) alert('Visit queued for sync! Try going offline and back online to see auto-sync.') } return (
{/* Header */}

PWA Field Tools Demo

Essential tools for field workers (Phase 1)

{/* Overview Cards */}
Media Capture
{photos.length}

Photos captured

Background Sync
{status.total}

Items queued

Web Share
{shareSupported ? 'Yes' : 'No'}

Supported

Wake Lock
{wakeLockActive ? 'On' : 'Off'}

Screen lock

{/* Feature Demos */}
{/* Camera Capture */} 📸 Media Capture Native camera access with photo compression and gallery {showCamera ? (
setShowCamera(false)} quality={0.8} format="image/jpeg" />
) : ( <> {photos.length > 0 && (

Captured Photos ({photos.length})

)} )}
{/* Background Sync */} 🔄 Background Sync Offline queue with automatic retry and zero data loss

Try going offline (airplane mode) and submitting - it will queue automatically!

Sync Queue Status
{/* Web Share */} 📤 Web Share Native sharing with automatic clipboard fallback

{shareSupported ? 'Native share dialog available on this device' : 'Will copy to clipboard (desktop fallback)'}

{/* Wake Lock */} ⏰ Wake Lock Prevent screen sleep during important workflows
{wakeLockActive ? '🔓 Active' : '🔒 Inactive'}

{wakeLockActive ? 'Screen will stay on. Great for delivery routes or long forms!' : 'Screen can sleep normally. Battery friendly!'}

{/* Features List */} 📋 What You Can Do Real-world use cases for PWA Field Tools

📸 Media Capture

  • • Take customer visit photos
  • • Capture delivery proof-of-delivery
  • • Document product conditions
  • • Auto-compress to 400KB
  • • Switch front/back camera

🔄 Background Sync

  • • Submit forms offline
  • • Auto-retry when online
  • • Zero data loss guaranteed
  • • Track sync progress
  • • Retry failed items

📤 Web Share

  • • Share via WhatsApp, SMS, Email
  • • Send locations to team
  • • Share reports with manager
  • • Desktop clipboard fallback
  • • Share files and images

⏰ Wake Lock

  • • Keep screen on during routes
  • • Long form data entry
  • • Inspection workflows
  • • Battery-aware (auto-release)
  • • Route-specific activation
{/* Documentation Link */} 📚 Learn More Complete documentation for PWA Field Tools

Check out the comprehensive guide with examples, API reference, best practices, and troubleshooting tips.

) }