import { useState } from 'react' import { FaCodeBranch } from 'react-icons/fa' import { FaLinkSlash } from 'react-icons/fa6' import GiteaLinkButton from './GiteaLinkButton' import PreviewLinkButton from './PreviewLinkButton' import { suggestSubdomain } from '../lib/subdomain' import { needsPreviewButton, assignSummary } from '../lib/projectAssign' import { updateWebsiteProject, backfillProjectPushes } from '../lib/projectAdminApi' const STATUS_COLORS = { ready: '#10b981', live: '#10b981', online: '#10b981', provisioning: '#f59e0b', pending: '#f59e0b', building: '#3b82f6', error: '#ef4444', failed: '#ef4444', } function StatusBadge({ label, value }) { if (!value) return null const color = STATUS_COLORS[String(value).toLowerCase()] || '#a0aec0' return ( {label}: {value} ) } export default function AssignedProjectCard({ project, onUnassign, showActions = false, customerName = '', onChanged = () => {} }) { const [showPreviewInput, setShowPreviewInput] = useState(false) const [subdomain, setSubdomain] = useState('') const [previewBusy, setPreviewBusy] = useState(false) const [previewMessage, setPreviewMessage] = useState('') const [pushBusy, setPushBusy] = useState(false) const [pushMessage, setPushMessage] = useState('') const openPreviewInput = () => { setSubdomain(suggestSubdomain(customerName, project.projectName)) setPreviewMessage('') setShowPreviewInput(true) } const handleEnablePreview = async () => { setPreviewBusy(true) setPreviewMessage('') try { const r = await updateWebsiteProject(project.$id, { projectType: 'preview', subdomain }) setPreviewMessage(`Preview läuft: ${r.previewUrl}`) setShowPreviewInput(false) onChanged() } catch (err) { setPreviewMessage(err.message) } finally { setPreviewBusy(false) } } const handleBackfill = async () => { setPushBusy(true) setPushMessage('') try { const r = await backfillProjectPushes(project.$id) setPushMessage(assignSummary(project.projectName, r).text) onChanged() } catch (err) { setPushMessage(err.message) } finally { setPushBusy(false) } } return (
{project.projectName} {project.subdomain && ({project.subdomain})} {project.repoFullName && (
{project.repoFullName}
)}
{showActions && onUnassign && ( )}
{/* Status- und Provisioning-Zeile */}
{showActions && (
{needsPreviewButton(project) && !showPreviewInput && ( )} {showPreviewInput && ( <> setSubdomain(e.target.value)} /> )}
{(previewMessage || pushMessage) && (
{previewMessage &&
{previewMessage}
} {pushMessage &&
{pushMessage}
}
)}
)}
) }