Improve onboarding
This commit is contained in:
@@ -44,12 +44,15 @@ ONBOARDING_STEPS = [
|
||||
"user_registered", # Auto-completed: User account created
|
||||
|
||||
# Phase 1: Discovery
|
||||
"bakery-type-selection", # Choose bakery type: production/retail/mixed
|
||||
"bakery-type-selection", # Choose bakery type: production/retail/mixed (skipped for enterprise)
|
||||
|
||||
# Phase 2: Core Setup
|
||||
"setup", # Basic bakery setup and tenant creation
|
||||
# NOTE: POI detection now happens automatically in background during tenant registration
|
||||
|
||||
# Phase 2-Enterprise: Child Tenants Setup (enterprise tier only)
|
||||
"child-tenants-setup", # Configure child tenants/branches for enterprise tier
|
||||
|
||||
# Phase 2a: AI-Assisted Inventory Setup (REFACTORED - split into 3 focused steps)
|
||||
"upload-sales-data", # File upload, validation, and AI classification
|
||||
"inventory-review", # Review and confirm AI-detected products with type selection
|
||||
@@ -63,7 +66,6 @@ ONBOARDING_STEPS = [
|
||||
|
||||
# Phase 3: Advanced Configuration (all optional)
|
||||
"recipes-setup", # Production recipes (conditional: production/mixed bakery)
|
||||
"production-processes", # Finishing processes (conditional: retail/mixed bakery)
|
||||
"quality-setup", # Quality standards and templates
|
||||
"team-setup", # Team members and permissions
|
||||
|
||||
@@ -79,10 +81,14 @@ STEP_DEPENDENCIES = {
|
||||
# Discovery phase
|
||||
"bakery-type-selection": ["user_registered"],
|
||||
|
||||
# Core setup - no longer depends on data-source-choice (removed)
|
||||
# Core setup - NOTE: bakery-type-selection dependency is conditionally required
|
||||
# Enterprise users skip bakery-type-selection, so setup only requires user_registered for them
|
||||
"setup": ["user_registered", "bakery-type-selection"],
|
||||
# NOTE: POI detection removed from steps - now happens automatically in background
|
||||
|
||||
# Enterprise child tenants setup - requires setup (parent tenant) to be completed first
|
||||
"child-tenants-setup": ["user_registered", "setup"],
|
||||
|
||||
# AI-Assisted Inventory Setup - REFACTORED into 3 sequential steps
|
||||
"upload-sales-data": ["user_registered", "setup"],
|
||||
"inventory-review": ["user_registered", "setup", "upload-sales-data"],
|
||||
@@ -96,7 +102,6 @@ STEP_DEPENDENCIES = {
|
||||
|
||||
# Advanced configuration (optional, minimal dependencies)
|
||||
"recipes-setup": ["user_registered", "setup"],
|
||||
"production-processes": ["user_registered", "setup"],
|
||||
"quality-setup": ["user_registered", "setup"],
|
||||
"team-setup": ["user_registered", "setup"],
|
||||
|
||||
@@ -270,20 +275,41 @@ class OnboardingService:
|
||||
|
||||
async def _can_complete_step(self, user_id: str, step_name: str) -> bool:
|
||||
"""Check if user can complete a specific step"""
|
||||
|
||||
|
||||
# Get required dependencies for this step
|
||||
required_steps = STEP_DEPENDENCIES.get(step_name, [])
|
||||
|
||||
required_steps = STEP_DEPENDENCIES.get(step_name, []).copy() # Copy to avoid modifying original
|
||||
|
||||
if not required_steps:
|
||||
return True # No dependencies
|
||||
|
||||
|
||||
# Check if all required steps are completed
|
||||
user_progress_data = await self._get_user_onboarding_data(user_id)
|
||||
|
||||
|
||||
# SPECIAL HANDLING FOR ENTERPRISE ONBOARDING
|
||||
# Enterprise users skip bakery-type-selection step, so don't require it for setup
|
||||
if step_name == "setup" and "bakery-type-selection" in required_steps:
|
||||
# Check if user's tenant has enterprise subscription tier
|
||||
# We do this by checking if the user has any data indicating enterprise tier
|
||||
# This could be stored in user_registered step data or we can infer from context
|
||||
user_registered_data = user_progress_data.get("user_registered", {}).get("data", {})
|
||||
subscription_tier = user_registered_data.get("subscription_tier")
|
||||
|
||||
if subscription_tier == "enterprise":
|
||||
# Enterprise users don't need bakery-type-selection
|
||||
logger.info(f"Enterprise user {user_id}: Skipping bakery-type-selection requirement for setup step")
|
||||
required_steps.remove("bakery-type-selection")
|
||||
elif not user_progress_data.get("bakery-type-selection", {}).get("completed", False):
|
||||
# Non-enterprise user hasn't completed bakery-type-selection
|
||||
# But allow setup anyway if user_registered is complete (frontend will handle it)
|
||||
# This is a fallback for when subscription_tier is not stored in user_registered data
|
||||
logger.info(f"User {user_id}: Allowing setup without bakery-type-selection (will be auto-set for enterprise)")
|
||||
required_steps.remove("bakery-type-selection")
|
||||
|
||||
for required_step in required_steps:
|
||||
if not user_progress_data.get(required_step, {}).get("completed", False):
|
||||
logger.debug(f"Step {step_name} blocked for user {user_id}: missing dependency {required_step}")
|
||||
return False
|
||||
|
||||
|
||||
# SPECIAL VALIDATION FOR ML TRAINING STEP
|
||||
if step_name == "ml-training":
|
||||
# ML training requires AI-assisted path completion
|
||||
|
||||
@@ -179,6 +179,7 @@ class EnhancedAuthService:
|
||||
onboarding_repo = OnboardingRepository(db_session)
|
||||
plan_data = {
|
||||
"subscription_plan": user_data.subscription_plan or "starter",
|
||||
"subscription_tier": user_data.subscription_plan or "starter", # Store tier for enterprise onboarding logic
|
||||
"use_trial": user_data.use_trial or False,
|
||||
"payment_method_id": user_data.payment_method_id,
|
||||
"saved_at": datetime.now(timezone.utc).isoformat()
|
||||
|
||||
Reference in New Issue
Block a user