import React, { useState, useRef, useEffect } from 'react'; import { ChevronRight, ChevronLeft, Check, Copy, Terminal, Rocket, Settings, AlertCircle, RefreshCw } from 'lucide-react'; interface OnboardingWizardProps { onComplete?: () => void; } export const OnboardingWizard: React.FC = ({ onComplete }) => { const [currentStep, setCurrentStep] = useState(1); const [webhookUrl, setWebhookUrl] = useState(''); const [copied, setCopied] = useState(false); const [isGenerating, setIsGenerating] = useState(false); const stepRef = useRef(null); // Focus management for accessibility - only when step changes, not on initial mount useEffect(() => { // Only focus if this is a step change (not initial mount) // This prevents auto-scroll to the onboarding section on page load if (stepRef.current && document.activeElement !== document.body) { stepRef.current.focus({ preventScroll: true }); } }, [currentStep]); // Environment configuration const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:3001'; const WEBHOOK_BASE_URL = import.meta.env.VITE_WEBHOOK_BASE_URL || `${API_URL}/webhook`; const INSTALL_SCRIPT_URL = import.meta.env.VITE_INSTALL_SCRIPT_URL || `${API_URL}/install.sh`; const APP_NAME = import.meta.env.VITE_APP_NAME || 'LogWhispererAI'; const generateWebhook = async () => { setIsGenerating(true); try { const response = await fetch(`${API_URL}/api/webhook`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); if (data.success && data.uuid) { // Use configured webhook base URL instead of API response setWebhookUrl(`${WEBHOOK_BASE_URL}/${data.uuid}`); } else { throw new Error(data.message || 'Errore nella generazione del webhook'); } } catch (error) { console.error('Error generating webhook:', error); // Fallback: generate locally if API fails const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { const r = Math.random() * 16 | 0; const v = c === 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); setWebhookUrl(`${WEBHOOK_BASE_URL}/${uuid}`); } finally { setIsGenerating(false); } }; const copyWebhook = () => { navigator.clipboard.writeText(webhookUrl); setCopied(true); setTimeout(() => setCopied(false), 2000); }; const copyCurlCommand = () => { const command = `curl -fsSL ${INSTALL_SCRIPT_URL} | bash -s -- --webhook ${webhookUrl}`; navigator.clipboard.writeText(command); setCopied(true); setTimeout(() => setCopied(false), 2000); }; const nextStep = () => { if (currentStep < 3) { setCurrentStep(currentStep + 1); } else { onComplete?.(); } }; const prevStep = () => { if (currentStep > 1) { setCurrentStep(currentStep - 1); } }; const getInstallCommand = () => { return webhookUrl ? `curl -fsSL ${INSTALL_SCRIPT_URL} | bash -s -- --webhook ${webhookUrl}` : `curl -fsSL ${INSTALL_SCRIPT_URL} | bash`; }; const steps = [ { number: 1, title: 'Benvenuto', icon: }, { number: 2, title: 'Webhook', icon: }, { number: 3, title: 'Setup', icon: }, ]; return (
{/* Section Header */}

Inizia in 3 semplici passi

Configura LogWhispererAI sul tuo server in meno di 5 minuti.

{/* Step Indicator */} {/* Wizard Content */}
{/* Step 1: Welcome */} {currentStep === 1 && (

Benvenuto su LogWhispererAI

Il tuo assistente DevOps personale che monitora i log del server e ti avvisa immediatamente quando qualcosa va storto, suggerendoti il comando esatto per risolvere il problema.

Cosa succederà:

  • 1. Genereremo un webhook URL univoco per il tuo account
  • 2. Installerai uno script leggero sul tuo server
  • 3. Inizierai a ricevere notifiche intelligenti su Telegram

⏱️ Tempo stimato: 5 minuti

💰 Nessuna carta di credito richiesta

)} {/* Step 2: Webhook Generation */} {currentStep === 2 && (

Genera il tuo Webhook

Clicca il pulsante qui sotto per generare il tuo webhook URL univoco. Questo URL riceverà i log dal tuo server.

{!webhookUrl ? (
) : (
Il tuo webhook URL:
{webhookUrl}

Webhook generato con successo! Procedi allo step successivo per installare lo script.

)}
)} {/* Step 3: Setup Instructions */} {currentStep === 3 && (

Installa sul tuo Server

Esegui questo comando sul tuo server per installare LogWhisperer. Lo script configurerà automaticamente il monitoraggio dei log.

Comando di installazione:
{getInstallCommand()}

Istruzioni:

  1. 1 Connettiti al tuo server via SSH
  2. 2 Esegui il comando copiato sopra
  3. 3 Segui la configurazione guidata
  4. 4 Controlla Telegram per il messaggio di conferma

Nota: Lo script richiede privilegi sudo per installare il servizio di sistema. Nessun dato sensibile viene inviato durante l'installazione.

)} {/* Navigation Buttons */}
); }; export default OnboardingWizard;