Add demo mode support with MSW integration and documentation
- Integrated Mock Service Worker (MSW) for frontend-only demo mode, allowing API call interception without requiring a backend. - Added `DemoModeBanner` component to indicate active demo mode and display demo credentials. - Enhanced configuration with `DEMO_MODE` flag and demo credentials for user and admin access. - Updated ESLint configuration to exclude MSW-related files from linting and coverage. - Created comprehensive `DEMO_MODE.md` documentation for setup and usage guidelines, including deployment instructions and troubleshooting. - Updated package dependencies to include MSW and related libraries.
This commit is contained in:
91
frontend/src/mocks/data/stats.ts
Normal file
91
frontend/src/mocks/data/stats.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Mock Admin Statistics Data
|
||||
*
|
||||
* Sample statistics for demo mode admin dashboard
|
||||
*/
|
||||
|
||||
import type {
|
||||
AdminStatsResponse,
|
||||
UserGrowthData,
|
||||
OrgDistributionData,
|
||||
RegistrationActivityData,
|
||||
UserStatusData,
|
||||
} from '@/lib/api/client';
|
||||
|
||||
/**
|
||||
* Generate user growth data for the last 30 days
|
||||
*/
|
||||
function generateUserGrowthData(): UserGrowthData[] {
|
||||
const data: UserGrowthData[] = [];
|
||||
const today = new Date();
|
||||
|
||||
for (let i = 29; i >= 0; i--) {
|
||||
const date = new Date(today);
|
||||
date.setDate(date.getDate() - i);
|
||||
|
||||
// Simulate growth with some randomness
|
||||
const baseTotal = 50 + Math.floor((29 - i) * 1.5);
|
||||
const baseActive = Math.floor(baseTotal * (0.7 + Math.random() * 0.2));
|
||||
|
||||
data.push({
|
||||
date: date.toISOString().split('T')[0],
|
||||
total_users: baseTotal,
|
||||
active_users: baseActive,
|
||||
});
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Organization distribution data
|
||||
*/
|
||||
const orgDistribution: OrgDistributionData[] = [
|
||||
{ name: 'Acme Corporation', value: 12 },
|
||||
{ name: 'Tech Innovators', value: 8 },
|
||||
{ name: 'Global Solutions Inc', value: 25 },
|
||||
{ name: 'Startup Ventures', value: 5 },
|
||||
{ name: 'Inactive Corp', value: 3 },
|
||||
];
|
||||
|
||||
/**
|
||||
* Registration activity data (last 7 days)
|
||||
*/
|
||||
function generateRegistrationActivity(): RegistrationActivityData[] {
|
||||
const data: RegistrationActivityData[] = [];
|
||||
const today = new Date();
|
||||
|
||||
for (let i = 6; i >= 0; i--) {
|
||||
const date = new Date(today);
|
||||
date.setDate(date.getDate() - i);
|
||||
|
||||
// Simulate registration activity with some randomness
|
||||
const count = Math.floor(Math.random() * 5) + 1; // 1-5 registrations per day
|
||||
|
||||
data.push({
|
||||
date: date.toISOString().split('T')[0],
|
||||
// @ts-ignore
|
||||
count,
|
||||
});
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* User status distribution
|
||||
*/
|
||||
const userStatus: UserStatusData[] = [
|
||||
{ name: 'Active', value: 89 },
|
||||
{ name: 'Inactive', value: 11 },
|
||||
];
|
||||
|
||||
/**
|
||||
* Complete admin stats response
|
||||
*/
|
||||
export const adminStats: AdminStatsResponse = {
|
||||
user_growth: generateUserGrowthData(),
|
||||
organization_distribution: orgDistribution,
|
||||
registration_activity: generateRegistrationActivity(),
|
||||
user_status: userStatus,
|
||||
};
|
||||
Reference in New Issue
Block a user