/** * Step 1: Business Details * Site type selection, hosting detection, brand inputs */ import { useState, useEffect } from 'react'; import { useBuilderWorkflowStore } from '../../../../store/builderWorkflowStore'; import { fetchSiteBlueprintById, updateSiteBlueprint, SiteBlueprint } from '../../../../services/api'; import { Card, CardDescription, CardTitle } from '../../../../components/ui/card'; import ButtonWithTooltip from '../../../../components/ui/button/ButtonWithTooltip'; import Input from '../../../../components/ui/input/Input'; import Alert from '../../../../components/ui/alert/Alert'; import { Loader2 } from 'lucide-react'; interface BusinessDetailsStepProps { blueprintId: number; } export default function BusinessDetailsStep({ blueprintId }: BusinessDetailsStepProps) { const { context, completeStep, loading } = useBuilderWorkflowStore(); const [blueprint, setBlueprint] = useState(null); const [formData, setFormData] = useState({ name: '', description: '', hosting_type: 'igny8_sites' as const, business_type: '', }); const [saving, setSaving] = useState(false); const [error, setError] = useState(null); useEffect(() => { // Load blueprint data fetchSiteBlueprintById(blueprintId) .then(setBlueprint) .catch(err => setError(err.message)); }, [blueprintId]); useEffect(() => { if (blueprint) { setFormData({ name: blueprint.name || '', description: blueprint.description || '', hosting_type: (blueprint.hosting_type as any) || 'igny8_sites', business_type: blueprint.config_json?.business_type || '', }); } }, [blueprint]); const handleSave = async () => { setSaving(true); setError(null); try { const updated = await updateSiteBlueprint(blueprintId, { name: formData.name, description: formData.description, hosting_type: formData.hosting_type, config_json: { ...blueprint?.config_json, business_type: formData.business_type, }, }); setBlueprint(updated); // Mark step as complete await completeStep('business_details', { blueprint_name: formData.name, hosting_type: formData.hosting_type, }); } catch (err: any) { setError(err.message || 'Failed to save business details'); } finally { setSaving(false); } }; const canProceed = formData.name.trim().length > 0; return ( Business Details Tell us about your business and site type to get started. {error && ( {error} )}
setFormData({ ...formData, name: e.target.value })} placeholder="My Awesome Site" required />