import React, { useState, useEffect } from "react"; import "./App.css"; import Step1 from "./components/Step1"; import Step2 from "./components/Step2"; import Step3 from "./components/Step3"; import Step4 from "./components/Step4"; import { config as appConfig, debugLog } from "./utils/config"; import { ApiService } from "./utils/apiService"; // Make ApiService available globally for debugging if (process.env.NODE_ENV === "development") { window.ApiService = ApiService; } function App() { const [apiKey, setApiKey] = useState(""); const [isApiKeyValid, setIsApiKeyValid] = useState(false); // Explicitly initialized to false const [uploadedFile, setUploadedFile] = useState(null); const [s3Link, setS3Link] = useState(""); const [fileMetadata, setFileMetadata] = useState({ fileSizeBytes: 0, sourceFileRows: 0, }); const [config, setConfig] = useState({ numRows: appConfig.defaultNumRecords, targetColumn: "", }); const [generatedDataLink, setGeneratedDataLink] = useState(""); // Check for previously stored and valid API key on app load useEffect(() => { const checkStoredApiKey = async () => { try { debugLog("Checking for stored API key on app initialization"); const storedKeyStatus = await ApiService.verifyStoredApiKey(); if (storedKeyStatus.valid) { setIsApiKeyValid(true); debugLog("Valid stored API key found", storedKeyStatus); } else { setIsApiKeyValid(false); debugLog("No valid stored API key", storedKeyStatus); } } catch (error) { debugLog("Error checking stored API key", error); setIsApiKeyValid(false); } }; checkStoredApiKey(); }, []); // Log app initialization in debug mode useEffect(() => { debugLog("Syncora app initialized", { defaultNumRecords: appConfig.defaultNumRecords, maxFileSizeMB: appConfig.maxFileSizeMB, apiBaseUrl: appConfig.apiBaseUrl, }); }, []); const steps = [ { number: 1, title: "API Key Validation", component: Step1, icon: "🔑" }, { number: 2, title: "Upload Files", component: Step2, icon: "📁" }, { number: 3, title: "Configuration", component: Step3, icon: "⚙️" }, { number: 4, title: "Generate Data", component: Step4, icon: "🚀" }, ]; // Helper function to check if a step should be enabled const isStepEnabled = (stepNumber) => { switch (stepNumber) { case 1: return true; // Step 1 is always enabled case 2: const step2Enabled = isApiKeyValid; debugLog(`Step 2 enabled check: ${step2Enabled}`, { isApiKeyValid, apiKeyLength: apiKey.length, hasApiKey: !!apiKey, }); return step2Enabled; // Step 2 enabled when API key is valid case 3: return isApiKeyValid && uploadedFile && s3Link; // Step 3 enabled when file is uploaded case 4: return isApiKeyValid && uploadedFile && s3Link && config.targetColumn; // Step 4 enabled when config is complete default: return false; } }; const renderStep = (stepNumber) => { const step = steps[stepNumber - 1]; const StepComponent = step.component; const enabled = isStepEnabled(stepNumber); return (
AI-Powered Data Generation Platform