import React, { useState, useEffect } from 'react';
import { initializeApp } from 'firebase/app';
import { getAuth, signInAnonymously, onAuthStateChanged, signInWithCustomToken } from 'firebase/auth';
import { getFirestore, doc, setDoc, collection, onSnapshot, addDoc, serverTimestamp } from 'firebase/firestore';
import {
ChevronRight,
Upload,
CheckCircle2,
AlertCircle,
FileText,
Settings,
Truck,
CreditCard,
Play,
ArrowRight,
Save,
Mail,
Phone,
Building,
MapPin,
Loader2,
X,
FileSearch,
FolderOpen
} from 'lucide-react';
// --- Firebase Configuration & Initialization ---
const firebaseConfig = JSON.parse(__firebase_config);
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const db = getFirestore(app);
const appId = typeof __app_id !== 'undefined' ? __app_id : 'oleary-welding-ordering';
const App = () => {
const [user, setUser] = useState(null);
const [step, setStep] = useState(0); // 0: Landing, 1: Interface, 2: AI Analysis, 3: Quote
const [isLoading, setIsLoading] = useState(false);
const [saveStatus, setSaveStatus] = useState(null);
const [formErrors, setFormErrors] = useState({});
const [aiStatus, setAiStatus] = useState('idle'); // idle, uploading, processing, error, success
const [formData, setFormData] = useState({
customerType: '',
otherCustomerType: '',
supplySteel: '',
customerDeliver: '',
customerPickup: '',
recoverDrops: '',
companyName: '',
companyAddress: '',
contactName: '',
email: '',
phone: '',
projectName: '',
projectAddress: '',
files: []
});
// --- Auth Effect ---
useEffect(() => {
const initAuth = async () => {
try {
if (typeof __initial_auth_token !== 'undefined' && __initial_auth_token) {
await signInWithCustomToken(auth, __initial_auth_token);
} else {
await signInAnonymously(auth);
}
} catch (error) {
console.error("Auth error:", error);
}
};
initAuth();
const unsubscribe = onAuthStateChanged(auth, setUser);
return () => unsubscribe();
}, []);
const handleInputChange = (e) => {
const { name, value } = e.target;
setFormData(prev => ({ ...prev, [name]: value }));
if (formErrors[name]) {
setFormErrors(prev => {
const newErrors = { ...prev };
delete newErrors[name];
return newErrors;
});
}
};
const validateForm = () => {
const errors = {};
const required = ['customerType', 'contactName', 'email', 'phone', 'projectName', 'projectAddress'];
required.forEach(field => {
if (!formData[field]) errors[field] = true;
});
if (formData.customerType === 'Other' && !formData.otherCustomerType) {
errors.otherCustomerType = true;
}
setFormErrors(errors);
if (Object.keys(errors).length > 0) {
const firstErrorField = document.querySelector('.error-border');
if (firstErrorField) {
firstErrorField.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
return false;
}
return true;
};
// --- Logic: Save Information (Link Folder & Create Docs) ---
const handleSaveInformation = async () => {
if (!user) return;
setIsLoading(true);
try {
const parentFolderName = formData.companyName || formData.contactName || 'Guest_Customer';
const projectSubFolderName = `${formData.projectName} ${formData.projectAddress}`.trim();
// Document Path: /artifacts/{appId}/public/data/customer_projects/{ID}
// We simulate the hierarchy within the metadata to match the OWC requirement
const projectRef = doc(db, 'artifacts', appId, 'public', 'data', 'customer_projects', `${parentFolderName}_${formData.projectName}`.replace(/\s+/g, '_'));
await setDoc(projectRef, {
...formData,
savedAt: serverTimestamp(),
userId: user.uid,
status: 'Draft',
owc_path: `OWC / Customer Projects / ${parentFolderName} / ${projectSubFolderName}`,
lastUpdate: 'System folder metadata generated.'
});
setSaveStatus('success');
setTimeout(() => setSaveStatus(null), 3000);
} catch (error) {
console.error("Save error:", error);
setSaveStatus('error');
} finally {
setIsLoading(false);
}
};
const handleFinalSubmit = (e) => {
e.preventDefault();
if (validateForm()) {
setStep(2);
}
};
// --- Logic: AI Analysis (Link Steel Pricing Gem) ---
const simulateAiAnalysis = () => {
setAiStatus('uploading');
setTimeout(() => {
setAiStatus('processing');
// Simulate "Steel Pricing" Gem calculating pricing and time estimate
setTimeout(() => {
const success = Math.random() > 0.15; // High success rate for AI read
setAiStatus(success ? 'success' : 'error');
}, 3000);
}, 1500);
};
const handleSendToTeam = async () => {
setIsLoading(true);
try {
// Logic for "Send to O’Leary Welding team for review"
// Simulated Email to timo@olearywelding.com
const emailLogRef = collection(db, 'artifacts', appId, 'public', 'data', 'system_notifications');
await addDoc(emailLogRef, {
to: 'timo@olearywelding.com',
subject: `${formData.contactName}, ${formData.projectName} Drawings`,
body: `Gemini can not read the files submitted by customer, review here: [Link to OWC Customer Project Folder]`,
timestamp: serverTimestamp()
});
setTimeout(() => {
setIsLoading(false);
setAiStatus('team_notified');
}, 1000);
} catch (e) {
setIsLoading(false);
}
};
const LandingPage = () => (
O'LEARY WELDING
The Industry's First AI-Powered Digital Marketplace for Structural Steel Fabrication.
Interactive Tutorial
How OWC Ordering Works
setStep(1)}
className="bg-orange-500 hover:bg-orange-600 text-white text-2xl font-black py-7 px-20 rounded-full shadow-[0_15px_45px_-10px_rgba(249,115,22,0.6)] transform transition hover:-translate-y-2 active:scale-95 flex items-center mx-auto"
>
START ORDERING
);
const CustomerInterface = () => (
1. Order Configuration
Please provide project details and logistics requirements.
Digital Interface
v2.4.1 LIVE
);
const DrawingAnalysis = () => (
2. Customer Drawings
Upload part drawings for Gemini AI analysis and Steel Pricing generation.
{aiStatus === 'idle' && (
DRAG & DROP DRAWINGS
Accepting PDF, DXF, NC1, and DWG. AI instantly calculates weight, pricing, and fabrication lead times.
Select Files
)}
{(aiStatus === 'uploading' || aiStatus === 'processing') && (
{aiStatus === 'uploading' ? 'SECURE UPLOADING...' : 'QUERYING PRICING GEM...'}
"Analyzing part geometry for precise weight and labor hour estimates."
)}
{aiStatus === 'success' && (
ANALYSIS COMPLETE
File Status
Sub-folder "Drawings" created. Files stored successfully in OWC project directory.
setStep(3)}
className="flex-1 bg-slate-900 text-white font-black py-6 rounded-2xl hover:bg-slate-800 transition shadow-2xl text-2xl uppercase tracking-tight group"
>
VIEW FINAL QUOTE
)}
{aiStatus === 'error' && (
FILE PARSING ERROR
"The files can not be read by our agent, select an option for next step"
setAiStatus('idle')}
className="w-full bg-orange-500 text-white font-black py-6 rounded-2xl hover:bg-orange-600 transition flex items-center justify-center text-xl shadow-xl"
>
Resubmit in different format (PDF, DXF, NC1)
or
{isLoading ? : }
Send to O’Leary Welding team for review
)}
{aiStatus === 'team_notified' && (
TEAM NOTIFIED
Email dispatched to timo@olearywelding.com .
Subject: {formData.contactName}, {formData.projectName} Drawings
setStep(0)} className="mt-12 text-orange-400 font-black uppercase tracking-widest hover:text-orange-300 underline underline-offset-8">Return to Portal
)}
);
const QuoteSummary = () => (
Official Project Quote
{formData.projectName}
Order Reference:
OWC-{Math.floor(Math.random() * 90000) + 10000}
Estimated Delivery Window
July 22, 2024
Financial Breakdown
Structural Material {formData.supplySteel === 'yes' ? '(Owner Provided)' : ''}
{formData.supplySteel === 'yes' ? '$0.00' : '$6,120.50'}
OWC Precision Fabrication
$3,440.00
Logistics & Freight {formData.customerPickup === 'yes' ? '(Customer Pick-Up)' : ''}
{formData.customerPickup === 'yes' ? '$0.00' : '$550.00'}
Order Total
$10,110.50
Payment Link
"Confirm your order details. Upon clicking 'Pay Now', you will be redirected to our secure QuickBooks Online portal. Production scheduled immediately upon receipt."
PAY VIA QUICKBOOKS
End-to-End SSL
OWC Security Hub
Intuit Verified
setStep(0)} className="text-slate-400 hover:text-slate-900 font-black uppercase tracking-widest text-sm transition-all border-b border-transparent hover:border-slate-900 pb-1">
← Return to Dashboard
);
return (
{/* Navigation Header */}
setStep(0)}>
OWC
O'LEARY WELDING
Structural Steel Digital Marketplace
{step === 0 && }
{step === 1 && }
{step === 2 && }
{step === 3 && }
);
};
export default App;