Improve the demo feature of the project
This commit is contained in:
@@ -28,29 +28,54 @@ export const useTenantInitializer = () => {
|
||||
if (isDemoMode && demoSessionId) {
|
||||
const demoTenantId = localStorage.getItem('demo_tenant_id') || 'demo-tenant-id';
|
||||
|
||||
console.log('🔍 [TenantInitializer] Demo mode detected:', {
|
||||
isDemoMode,
|
||||
demoSessionId,
|
||||
demoTenantId,
|
||||
demoAccountType,
|
||||
currentTenant: currentTenant?.id
|
||||
});
|
||||
|
||||
// Check if current tenant is the demo tenant and is properly set
|
||||
const isValidDemoTenant = currentTenant &&
|
||||
typeof currentTenant === 'object' &&
|
||||
currentTenant.id === demoTenantId;
|
||||
|
||||
if (!isValidDemoTenant) {
|
||||
console.log('🔧 [TenantInitializer] Setting up demo tenant...');
|
||||
|
||||
const accountTypeName = demoAccountType === 'individual_bakery'
|
||||
? 'Panadería San Pablo - Demo'
|
||||
: 'Panadería La Espiga - Demo';
|
||||
|
||||
// Create a mock tenant object matching TenantResponse structure
|
||||
// Create a complete tenant object matching TenantResponse structure
|
||||
const mockTenant = {
|
||||
id: demoTenantId,
|
||||
name: accountTypeName,
|
||||
subdomain: `demo-${demoSessionId.slice(0, 8)}`,
|
||||
plan_type: 'professional', // Use a valid plan type
|
||||
business_type: demoAccountType === 'individual_bakery' ? 'bakery' : 'central_baker',
|
||||
business_model: demoAccountType,
|
||||
address: 'Demo Address',
|
||||
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(),
|
||||
updated_at: new Date().toISOString(),
|
||||
};
|
||||
|
||||
// Set the demo tenant as current
|
||||
setCurrentTenant(mockTenant);
|
||||
|
||||
// **CRITICAL: Also set tenant ID in API client**
|
||||
// This ensures API requests include the tenant ID header
|
||||
import('../api/client').then(({ apiClient }) => {
|
||||
apiClient.setTenantId(demoTenantId);
|
||||
console.log('✅ [TenantInitializer] Set API client tenant ID:', demoTenantId);
|
||||
});
|
||||
}
|
||||
}
|
||||
}, [isDemoMode, demoSessionId, demoAccountType, currentTenant, setCurrentTenant]);
|
||||
|
||||
Reference in New Issue
Block a user