import React, { useState } from 'react' import { uploadCaddyfilesMulti } from '../api/import' type Props = { visible: boolean onClose: () => void onUploaded?: () => void } export default function ImportSitesModal({ visible, onClose, onUploaded }: Props) { const [sites, setSites] = useState(['']) const [loading, setLoading] = useState(false) const [error, setError] = useState(null) if (!visible) return null const setSite = (index: number, value: string) => { const s = [...sites] s[index] = value setSites(s) } const handleFileInput = async (e: React.ChangeEvent) => { const files = e.target.files if (!files || files.length === 0) return const newSites: string[] = [] for (let i = 0; i < files.length; i++) { try { const text = await files[i].text() newSites.push(text) } catch (_err) { // ignore read errors for individual files newSites.push('') } } if (newSites.length > 0) setSites(newSites) } const addSite = () => setSites(prev => [...prev, '']) const removeSite = (index: number) => setSites(prev => prev.filter((_, i) => i !== index)) const handleSubmit = async () => { setError(null) setLoading(true) try { const cleaned = sites.map(s => s || '') await uploadCaddyfilesMulti(cleaned) setLoading(false) if (onUploaded) onUploaded() onClose() } catch (err: unknown) { const msg = err instanceof Error ? err.message : String(err) setError(msg || 'Upload failed') setLoading(false) } } return (

Multi-site Import

Add each site's Caddyfile content separately, then parse them together.

{/* Hidden file input so E2E tests can programmatically upload multiple files */}
{sites.map((s, idx) => (
Site {idx + 1}
{sites.length > 1 && ( )}