import React, { useState, useEffect } from 'react'; import { Box, Button, TextField, Typography, Card, CardContent, CircularProgress, Alert } from '@mui/material'; import { ArrowBack as ArrowBackIcon, Save as SaveIcon, CheckCircle as CheckCircleIcon } from '@mui/icons-material'; import { businessInfoApi, BusinessInfo } from '../../api/businessInfo'; import { onboardingCache } from '../../services/onboardingCache'; interface BusinessDescriptionStepProps { onBack: () => void; onContinue: (businessData?: BusinessInfo) => void; } const BusinessDescriptionStep: React.FC = ({ onBack, onContinue }) => { const [formData, setFormData] = useState({ business_description: '', industry: '', target_audience: '', business_goals: '', }); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [success, setSuccess] = useState(null); useEffect(() => { console.log('🔄 BusinessDescriptionStep mounted. Loading cached data...'); const cachedData = onboardingCache.getStepData(2)?.businessInfo; if (cachedData) { setFormData(cachedData); console.log('✅ Loaded cached business info:', cachedData); } else { console.log('â„šī¸ No cached business info found.'); } }, []); const handleChange = (e: React.ChangeEvent) => { const { name, value } = e.target; setFormData(prev => ({ ...prev, [name]: value })); }; const handleSaveAndContinue = async () => { setError(null); setSuccess(null); setLoading(true); console.log('🚀 Attempting to save business info:', formData); try { // Simulate user_id for now, replace with actual user_id from auth context later const userId = 1; const dataToSave = { ...formData, user_id: userId }; const response = await businessInfoApi.saveBusinessInfo(dataToSave); console.log('✅ Business info saved to DB:', response); setSuccess('Business information saved successfully!'); // Also save to cache for consistency with other steps onboardingCache.saveStepData(2, { businessInfo: response, hasWebsite: false }); console.log('✅ Business info saved to cache.'); setTimeout(() => { onContinue(response); }, 1500); // Give user time to see success message } catch (err) { console.error('❌ Error saving business info:', err); setError('Failed to save business information. Please try again.'); } finally { setLoading(false); } }; return ( Tell us about your business Since you don't have a website, please provide a description of your business. This will help ALwrity understand your brand and tailor its services. {error && {error}} {success && }>{success}} ); }; export default BusinessDescriptionStep;