import React, { useState, useEffect } from 'react'; import { classNames } from '~/utils/classNames'; import { Dialog } from '~/components/ui/Dialog'; import * as RadixDialog from '@radix-ui/react-dialog'; import { Button } from '~/components/ui/Button'; import { Input } from '~/components/ui/Input'; import { toast } from 'react-toastify'; import { MultiUserSessionManager } from './MultiUserSessionManager'; interface MultiUserToggleProps { className?: string; } export const MultiUserToggle: React.FC = ({ className }) => { const [isEnabled, setIsEnabled] = useState(false); const [showWizard, setShowWizard] = useState(false); const [currentStep, setCurrentStep] = useState(1); const [organizationName, setOrganizationName] = useState(''); const [adminEmail, setAdminEmail] = useState(''); const [adminPassword, setAdminPassword] = useState(''); const [maxUsers, setMaxUsers] = useState('10'); const [sessionTimeout, setSessionTimeout] = useState('30'); const [allowGuestAccess, setAllowGuestAccess] = useState(false); // Check if this is bolt.gives (exclusive feature) const isBoltGives = window.location.hostname === 'bolt.openweb.live' || window.location.hostname === 'localhost'; useEffect(() => { // Check if multi-user is already enabled const multiUserEnabled = localStorage.getItem('multiUserEnabled') === 'true'; setIsEnabled(multiUserEnabled); }, []); const handleToggle = () => { if (!isBoltGives) { toast.error('Multi-User Sessions is a Bolt.gives exclusive feature'); return; } if (!isEnabled) { // Show wizard to set up multi-user setShowWizard(true); setCurrentStep(1); } else { // Confirm disable if (window.confirm('Are you sure you want to disable Multi-User Sessions?')) { setIsEnabled(false); localStorage.setItem('multiUserEnabled', 'false'); toast.success('Multi-User Sessions disabled'); } } }; const handleNextStep = () => { if (currentStep === 1) { if (!organizationName.trim()) { toast.error('Please enter an organization name'); return; } } else if (currentStep === 2) { if (!adminEmail.trim() || !adminPassword.trim()) { toast.error('Please enter admin credentials'); return; } if (adminPassword.length < 8) { toast.error('Password must be at least 8 characters'); return; } } if (currentStep < 4) { setCurrentStep(currentStep + 1); } else { // Complete setup handleCompleteSetup(); } }; const handleCompleteSetup = async () => { try { // Save configuration const config = { organizationName, adminEmail, maxUsers: parseInt(maxUsers), sessionTimeout: parseInt(sessionTimeout), allowGuestAccess, enabled: true, setupDate: new Date().toISOString(), }; // Store in localStorage (in production, this would be server-side) localStorage.setItem('multiUserConfig', JSON.stringify(config)); localStorage.setItem('multiUserEnabled', 'true'); // Create admin user const response = await fetch('/api/auth/signup', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email: adminEmail, password: adminPassword, role: 'admin', organization: organizationName, }), }); if (response.ok) { setIsEnabled(true); setShowWizard(false); toast.success('Multi-User Sessions enabled successfully!'); // Auto-login the admin const loginResponse = await fetch('/api/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email: adminEmail, password: adminPassword, }), }); if (loginResponse.ok) { window.location.reload(); } } else { const error = (await response.json()) as { message?: string }; toast.error(error.message || 'Failed to setup Multi-User Sessions'); } } catch (error) { console.error('Setup error:', error); const errorMessage = error instanceof Error ? error.message : 'Failed to setup Multi-User Sessions'; toast.error(errorMessage); } }; if (!isBoltGives) { return null; // Feature not available for non-bolt.gives deployments } // If multi-user is enabled, show the session manager instead if (isEnabled) { return (
); } return ( <> {showWizard && ( setShowWizard(false)}>

Setup Multi-User Sessions

Step {currentStep} of 4
{/* Progress Bar */}
{[1, 2, 3, 4].map((step) => (
))}
{/* Step 1: Organization Setup */} {currentStep === 1 && (

Organization Setup

Configure your organization for multi-user collaboration

setOrganizationName(e.target.value)} placeholder="e.g., Acme Corp" className="w-full" />
)} {/* Step 2: Admin Account */} {currentStep === 2 && (

Admin Account

Create the administrator account for managing users

setAdminEmail(e.target.value)} placeholder="admin@example.com" className="w-full" />
setAdminPassword(e.target.value)} placeholder="Minimum 8 characters" className="w-full" />
)} {/* Step 3: Session Settings */} {currentStep === 3 && (

Session Settings

Configure session limits and security

setMaxUsers(e.target.value)} min="2" max="100" className="w-full" />
setSessionTimeout(e.target.value)} min="5" max="1440" className="w-full" />
)} {/* Step 4: Review & Confirm */} {currentStep === 4 && (

Review Configuration

Please review your settings before enabling Multi-User Sessions

Organization: {organizationName}
Admin Email: {adminEmail}
Max Users: {maxUsers}
Session Timeout: {sessionTimeout} minutes
Guest Access: {allowGuestAccess ? 'Enabled' : 'Disabled'}

Note: Multi-User Sessions is a Bolt.gives exclusive feature. You can manage users, sessions, and permissions from the admin panel after setup.

)} {/* Actions */}
)} ); };