import { useState } from 'react' import { FaCodeBranch } from 'react-icons/fa' import { FaLinkSlash } from 'react-icons/fa6' import PreviewBlock from './PreviewBlock' import AnalyseRow from './AnalyseRow' 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: 'var(--green-fg)', live: 'var(--green-fg)', online: 'var(--green-fg)', provisioning: 'var(--orange-fg)', pending: 'var(--orange-fg)', building: 'var(--blue-fg)', error: 'var(--red-fg)', failed: 'var(--red-fg)', } function StatusBadge({ label, value }) { if (!value) return null const color = STATUS_COLORS[String(value).toLowerCase()] || 'var(--text-2)' 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 [showPreviewBlock, setShowPreviewBlock] = useState(false) 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 */}
{project.subdomain && } {showActions && project.subdomain && (
{showPreviewBlock && (
)}
)} {showActions && (
{needsPreviewButton(project) && !showPreviewInput && ( )} {showPreviewInput && ( <> setSubdomain(e.target.value)} /> )}
{(previewMessage || pushMessage) && (
{previewMessage &&
{previewMessage}
} {pushMessage &&
{pushMessage}
}
)}
)}
) }