Improve the demo feature of the project
This commit is contained in:
@@ -5,6 +5,7 @@ import { Button } from '../../components/ui';
|
||||
import { getDemoAccounts, createDemoSession, DemoAccount } from '../../api/services/demo';
|
||||
import { apiClient } from '../../api/client';
|
||||
import { Check, Clock, Shield, Play, Zap, ArrowRight, Store, Factory } from 'lucide-react';
|
||||
import { markTourAsStartPending } from '../../features/demo-onboarding';
|
||||
|
||||
export const DemoPage: React.FC = () => {
|
||||
const navigate = useNavigate();
|
||||
@@ -38,9 +39,16 @@ export const DemoPage: React.FC = () => {
|
||||
demo_account_type: accountType as 'individual_bakery' | 'central_baker',
|
||||
});
|
||||
|
||||
console.log('✅ Demo session created:', session);
|
||||
|
||||
// Store session ID in API client
|
||||
apiClient.setDemoSessionId(session.session_id);
|
||||
|
||||
// **CRITICAL FIX: Set the virtual tenant ID in API client**
|
||||
// This ensures all API requests include the correct tenant context
|
||||
apiClient.setTenantId(session.virtual_tenant_id);
|
||||
console.log('✅ Set API client tenant ID:', session.virtual_tenant_id);
|
||||
|
||||
// Store session info in localStorage for UI
|
||||
localStorage.setItem('demo_mode', 'true');
|
||||
localStorage.setItem('demo_session_id', session.session_id);
|
||||
@@ -48,8 +56,34 @@ export const DemoPage: React.FC = () => {
|
||||
localStorage.setItem('demo_expires_at', session.expires_at);
|
||||
localStorage.setItem('demo_tenant_id', session.virtual_tenant_id);
|
||||
|
||||
// Navigate to dashboard
|
||||
navigate('/app/dashboard');
|
||||
// **CRITICAL FIX: Initialize tenant store with demo tenant**
|
||||
// This ensures useTenantId() returns the correct virtual tenant ID
|
||||
const { useTenantStore } = await import('../../stores/tenant.store');
|
||||
const demoTenant = {
|
||||
id: session.virtual_tenant_id,
|
||||
name: session.demo_config?.name || `Demo ${accountType}`,
|
||||
business_type: accountType === 'individual_bakery' ? 'bakery' : 'central_baker',
|
||||
business_model: accountType,
|
||||
address: session.demo_config?.address || 'Demo Address',
|
||||
city: session.demo_config?.city || 'Madrid',
|
||||
postal_code: '28001',
|
||||
phone: null,
|
||||
is_active: true,
|
||||
subscription_tier: 'demo',
|
||||
ml_model_trained: false,
|
||||
last_training_date: null,
|
||||
owner_id: 'demo-user',
|
||||
created_at: new Date().toISOString(),
|
||||
};
|
||||
|
||||
useTenantStore.getState().setCurrentTenant(demoTenant);
|
||||
console.log('✅ Initialized tenant store with demo tenant:', demoTenant);
|
||||
|
||||
// Mark tour to start automatically
|
||||
markTourAsStartPending();
|
||||
|
||||
// Navigate to setup page to wait for data cloning
|
||||
navigate(`/demo/setup?session=${session.session_id}`);
|
||||
} catch (err: any) {
|
||||
setError(err?.message || 'Error al crear sesión demo');
|
||||
console.error('Error creating demo session:', err);
|
||||
|
||||
Reference in New Issue
Block a user