/** * WorkflowGuide Component * Inline welcome/guide screen for new users * Shows site creation form with industry and sector selection */ import React, { useState, useEffect, useMemo } from 'react'; import { useNavigate } from 'react-router-dom'; import { Card } from '../ui/card'; import Button from '../ui/button/Button'; import Badge from '../ui/badge/Badge'; import { CloseIcon, ArrowRightIcon, GridIcon, PlugInIcon, FileIcon, CheckCircleIcon, BoltIcon, ListIcon, GroupIcon, FileTextIcon, } from '../../icons'; import { useOnboardingStore } from '../../store/onboardingStore'; import { useSiteStore } from '../../store/siteStore'; import { fetchSites, fetchIndustries, Industry, Sector, createSite, selectSectorsForSite, setActiveSite } from '../../services/api'; import { useAuthStore } from '../../store/authStore'; import SelectDropdown from '../form/SelectDropdown'; import { useToast } from '../ui/toast/ToastContainer'; import Alert from '../ui/alert/Alert'; interface WorkflowGuideProps { onSiteAdded?: () => void; } export default function WorkflowGuide({ onSiteAdded }: WorkflowGuideProps) { const navigate = useNavigate(); const toast = useToast(); const { isGuideVisible, dismissGuide, loadFromBackend } = useOnboardingStore(); const { activeSite, loadActiveSite } = useSiteStore(); const { isAuthenticated } = useAuthStore(); // Industry and Sector selection state const [industries, setIndustries] = useState([]); const [selectedIndustry, setSelectedIndustry] = useState(null); const [selectedSectors, setSelectedSectors] = useState([]); const [loadingIndustries, setLoadingIndustries] = useState(false); const [isWordPressExpanded, setIsWordPressExpanded] = useState(false); const [isCreatingSite, setIsCreatingSite] = useState(false); const [siteName, setSiteName] = useState(''); const [websiteAddress, setWebsiteAddress] = useState(''); // Load dismissal state from backend on mount useEffect(() => { if (isAuthenticated) { loadFromBackend().catch(() => { // Silently fail - local state will be used }); } }, [isAuthenticated, loadFromBackend]); // Load industries on mount useEffect(() => { if (!isAuthenticated || !isGuideVisible) return; const loadIndustries = async () => { try { setLoadingIndustries(true); const response = await fetchIndustries(); setIndustries(response.industries || []); } catch (error) { console.error('Failed to load industries:', error); } finally { setLoadingIndustries(false); } }; loadIndustries(); }, [isAuthenticated, isGuideVisible]); // Get available sectors for selected industry const availableSectors = useMemo(() => { if (!selectedIndustry) return []; return selectedIndustry.sectors || []; }, [selectedIndustry]); // Handle industry selection const handleIndustrySelect = (industry: Industry) => { setSelectedIndustry(industry); setSelectedSectors([]); // Reset sectors when industry changes }; // Handle sector toggle const handleSectorToggle = (sectorSlug: string) => { setSelectedSectors(prev => prev.includes(sectorSlug) ? prev.filter(s => s !== sectorSlug) : [...prev, sectorSlug] ); }; // Handle WordPress card click - expand to show industry/sector selection const handleWordPressCardClick = () => { setIsWordPressExpanded(!isWordPressExpanded); if (!isWordPressExpanded && industries.length === 0) { // Load industries if not already loaded const loadIndustries = async () => { try { setLoadingIndustries(true); const response = await fetchIndustries(); setIndustries(response.industries || []); } catch (error) { console.error('Failed to load industries:', error); } finally { setLoadingIndustries(false); } }; loadIndustries(); } }; // Handle Add Site button click const handleAddSite = async () => { if (!siteName || !siteName.trim()) { toast.error('Please enter a site name'); return; } if (!selectedIndustry) { toast.error('Please select an industry first'); return; } if (selectedSectors.length === 0) { toast.error('Please select at least one sector'); return; } if (selectedSectors.length > 5) { toast.error('Maximum 5 sectors allowed per site'); return; } try { setIsCreatingSite(true); // Create site with user-provided name and domain const newSite = await createSite({ name: siteName.trim(), domain: websiteAddress.trim() || undefined, is_active: true, hosting_type: 'wordpress', }); // Set industry for the site (if API supports it during creation, otherwise update) // For now, we'll set it via selectSectorsForSite which also sets industry // Select sectors for the site (this also sets the industry) await selectSectorsForSite( newSite.id, selectedIndustry.slug, selectedSectors ); // Set as active site if it's the first site const sitesRes = await fetchSites(); if (sitesRes.results.length === 1) { await setActiveSite(newSite.id); } const siteNameTrimmed = siteName.trim(); toast.success(`Site "${siteNameTrimmed}" created successfully with ${selectedSectors.length} sector${selectedSectors.length !== 1 ? 's' : ''}!`); // Reload sites in store await loadActiveSite(); // Call callback if provided (before navigation) if (onSiteAdded) { onSiteAdded(); } // Dismiss guide and redirect to site settings with integrations tab await dismissGuide(); navigate(`/sites/${newSite.id}/settings?tab=integrations`); } catch (error: any) { toast.error(`Failed to create site: ${error.message}`); } finally { setIsCreatingSite(false); } }; if (!isGuideVisible) return null; return (
{/* Header */}

Welcome to IGNY8

Your complete AI-powered content creation workflow

{/* Site Integration Option */}

Integrate New Site or Existing Site

Connect your WordPress site to IGNY8

{/* Site Type Selection - 2 columns for future IGNY8 option */}
{/* WordPress Site Card - Clickable to expand */} {/* Placeholder for future IGNY8 option */}
IGNY8 Hosted
Coming Soon
{/* Expanded Site Form - 3 columns: Name, Website Address, Industry */} {isWordPressExpanded && (
{/* Site Name, Website Address, and Industry - 3 columns */}
{/* Site Name */}
setSiteName(e.target.value)} placeholder="Enter site name" className="w-full px-4 py-2.5 border-2 border-gray-200 dark:border-gray-700 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white text-base focus:border-blue-500 focus:ring-2 focus:ring-blue-200 dark:focus:ring-blue-800" />
{/* Website Address */}
setWebsiteAddress(e.target.value)} placeholder="https://example.com" className="w-full px-4 py-2.5 border-2 border-gray-200 dark:border-gray-700 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white text-base focus:border-blue-500 focus:ring-2 focus:ring-blue-200 dark:focus:ring-blue-800" />
{/* Industry Selection - Using SelectDropdown */}
{loadingIndustries ? (
Loading industries...
) : ( ({ value: industry.slug, label: industry.name, }))} placeholder="-- Select Industry --" value={selectedIndustry?.slug || ''} onChange={(value) => { const industry = industries.find(i => i.slug === value); if (industry) { handleIndustrySelect(industry); } }} className="text-base [&_.igny8-select-styled]:text-base [&_.igny8-select-styled]:py-2.5 [&_button]:text-base" /> )}
{/* Sector Selection - Cards like IndustriesSectorsKeywords page */} {selectedIndustry && availableSectors.length > 0 && (
{availableSectors.map((sector) => ( handleSectorToggle(sector.slug)} >

{sector.name}

{selectedSectors.includes(sector.slug) && ( )}
{sector.description && (

{sector.description}

)}
))}
{selectedSectors.length > 0 && (

{selectedSectors.length} sector{selectedSectors.length !== 1 ? 's' : ''} selected

)}
)} {/* Validation Notification Card */} {(!siteName || !siteName.trim() || !selectedIndustry || selectedSectors.length === 0) && (
)} {/* Add Site Button */}
)}
); }