/** * Step 1: Business Details * Site type selection, hosting detection, brand inputs * * Supports both: * - Stage 1 Wizard: data, onChange, metadata, selectedSectors * - Stage 2 Workflow: blueprintId */ 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 Button from '../../../../components/ui/button/Button'; import Input from '../../../../components/form/input/InputField'; import Alert from '../../../../components/ui/alert/Alert'; import { BoltIcon, GridIcon } from '../../../../icons'; import type { BuilderFormData, SiteBuilderMetadata } from '../../../../types/siteBuilder'; // Stage 1 Wizard props interface Stage1Props { data: BuilderFormData; onChange: (key: K, value: BuilderFormData[K]) => void; metadata?: SiteBuilderMetadata; selectedSectors?: Array<{ id: number; name: string }>; blueprintId?: never; } // Stage 2 Workflow props interface Stage2Props { blueprintId: number; data?: never; onChange?: never; metadata?: never; selectedSectors?: never; } type BusinessDetailsStepProps = Stage1Props | Stage2Props; export function BusinessDetailsStep(props: BusinessDetailsStepProps) { // Check if this is Stage 2 (has blueprintId) const isStage2 = 'blueprintId' in props && props.blueprintId !== undefined; // Stage 2 implementation if (isStage2) { return ; } // Stage 1 implementation return ; } // Stage 2 Workflow Component function BusinessDetailsStepStage2({ blueprintId }: { blueprintId: number }) { 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 hosting preference to keep blueprints organized.
{error && ( {error} )}
setFormData({ ...formData, name: e.target.value })} placeholder="Acme Robotics" required />