/** * Mock Data Provider Usage Examples * * This file demonstrates how to use the MockDataProvider for development * without a backend. */ import React from 'react'; import { MockDataProvider } from './MockDataProvider'; import { useRevenueMetrics, useRevenueTrend, useTransactions, } from '../hooks/useAdminQueryMockable'; // ============================================================================ // Example 1: Wrap entire app in MockDataProvider // ============================================================================ export function AppWithMockData() { return ( ); } // ============================================================================ // Example 2: Conditional mock data based on environment // ============================================================================ export function AppWithConditionalMock() { const isDevelopment = (import.meta as { env?: { DEV?: boolean } }).env?.DEV ?? false; return ( ); } // ============================================================================ // Example 3: Using hooks in components // ============================================================================ function RevenueCard() { const { data, isLoading, isError } = useRevenueMetrics(); if (isLoading) return
Loading...
; if (isError) return
Error loading revenue data
; if (!data) return null; return (

Revenue Metrics

Total Revenue: ${data.totalRevenue.toLocaleString()}

Monthly Recurring: ${data.monthlyRecurring.toLocaleString()}

Growth Rate: {data.growthRate}%

); } function RevenueTrendChart() { const { data, isLoading } = useRevenueTrend(); if (isLoading) return
Loading chart...
; if (!data) return null; return (

Revenue Trend

{/* Render your chart here using data */}
{JSON.stringify(data, null, 2)}
); } function TransactionsList() { const { data, isLoading } = useTransactions({ status: 'completed', dateRange: '30d', }); if (isLoading) return
Loading transactions...
; if (!data) return null; return (

Recent Transactions ({data.total})

{data.transactions.map((txn) => ( ))}
ID Type Amount Status Provider
{txn.id} {txn.type} ${txn.amount.toFixed(2)} {txn.status} {txn.provider}
); } // ============================================================================ // Example 4: Environment variable configuration // ============================================================================ /** * In your .env file, add: * VITE_MOCK_ANALYTICS=true * * Then you don't need to wrap in MockDataProvider - hooks will * automatically use mock data. */ function YourAnalyticsDashboard() { return (

Analytics Dashboard

); } // ============================================================================ // Example 5: Toggling mock data at runtime // ============================================================================ export function AppWithToggle() { const [useMockData, setUseMockData] = React.useState(true); return (
); } // ============================================================================ // Example 6: Using mock data directly without provider // ============================================================================ import { mockData } from './MockDataProvider'; export function DirectMockUsage() { // Access mock data directly for testing or storybook const revenue = mockData.revenueMetrics; const transactions = mockData.transactions(); return (

Revenue: ${revenue.totalRevenue}

Transactions: {transactions.total}

); } // ============================================================================ // Example 7: Storybook integration // ============================================================================ /** * In your .storybook/preview.tsx: * * import { MockDataProvider } from '@packages/@plugins/analytics'; * * export const decorators = [ * (Story) => ( * * * * ), * ]; */ // ============================================================================ // Example 8: Testing with mock data // ============================================================================ /** * In your test files: * * import { render, screen } from '@testing-library/react'; * import { MockDataProvider } from '@packages/@plugins/analytics'; * * test('renders revenue metrics', () => { * render( * * * * ); * * expect(screen.getByText(/Total Revenue/)).toBeInTheDocument(); * }); */