feat(P8.3): freeze/start buttons disabled with hints when pre-conditions unmet

This commit is contained in:
zhi
2026-03-17 10:04:17 +00:00
parent a4b4ffcb88
commit faf7842cba

View File

@@ -45,6 +45,7 @@ export default function MilestoneDetailPage() {
const [actionError, setActionError] = useState<string | null>(null)
const [showCloseConfirm, setShowCloseConfirm] = useState(false)
const [closeReason, setCloseReason] = useState('')
const [preflight, setPreflight] = useState<{ freeze?: { allowed: boolean; reason: string | null }; start?: { allowed: boolean; reason: string | null } } | null>(null)
const fetchMilestone = () => {
api.get<Milestone>(`/milestones/${id}`).then(({ data }) => {
@@ -55,11 +56,18 @@ export default function MilestoneDetailPage() {
setProjectCode(proj.project_code || '')
})
api.get<ProjectMember[]>(`/projects/${data.project_id}/members`).then(({ data }) => setMembers(data)).catch(() => {})
fetchPreflight(data.project_id)
}
})
api.get<MilestoneProgress>(`/milestones/${id}/progress`).then(({ data }) => setProgress(data)).catch(() => {})
}
const fetchPreflight = (projectId: number) => {
api.get(`/projects/${projectId}/milestones/${id}/actions/preflight`)
.then(({ data }) => setPreflight(data))
.catch(() => setPreflight(null))
}
useEffect(() => {
fetchMilestone()
}, [id])
@@ -113,6 +121,7 @@ export default function MilestoneDetailPage() {
await api.post(`/projects/${project.id}/milestones/${milestone.id}/actions/${action}`, body ?? {})
fetchMilestone()
refreshMilestoneItems()
fetchPreflight(project.id)
} catch (err: any) {
const detail = err?.response?.data?.detail
setActionError(typeof detail === 'string' ? detail : `${action} failed`)
@@ -164,22 +173,38 @@ export default function MilestoneDetailPage() {
{!isTerminal && (
<div style={{ display: 'flex', gap: 8, marginTop: 8, flexWrap: 'wrap', alignItems: 'center' }}>
{msStatus === 'open' && (
<button
className="btn-primary"
disabled={actionLoading === 'freeze'}
onClick={handleFreeze}
>
{actionLoading === 'freeze' ? '⏳ Freezing...' : '🧊 Freeze'}
</button>
<span title={preflight?.freeze?.allowed === false ? preflight.freeze.reason ?? '' : ''}>
<button
className="btn-primary"
disabled={actionLoading === 'freeze' || preflight?.freeze?.allowed === false}
onClick={handleFreeze}
style={preflight?.freeze?.allowed === false ? { opacity: 0.5, cursor: 'not-allowed' } : {}}
>
{actionLoading === 'freeze' ? '⏳ Freezing...' : '🧊 Freeze'}
</button>
{preflight?.freeze?.allowed === false && (
<span className="text-dim" style={{ marginLeft: 8, fontSize: '0.85em' }}>
{preflight.freeze.reason}
</span>
)}
</span>
)}
{msStatus === 'freeze' && (
<button
className="btn-primary"
disabled={actionLoading === 'start'}
onClick={handleStart}
>
{actionLoading === 'start' ? '⏳ Starting...' : '▶️ Start'}
</button>
<span title={preflight?.start?.allowed === false ? preflight.start.reason ?? '' : ''}>
<button
className="btn-primary"
disabled={actionLoading === 'start' || preflight?.start?.allowed === false}
onClick={handleStart}
style={preflight?.start?.allowed === false ? { opacity: 0.5, cursor: 'not-allowed' } : {}}
>
{actionLoading === 'start' ? '⏳ Starting...' : '▶️ Start'}
</button>
{preflight?.start?.allowed === false && (
<span className="text-dim" style={{ marginLeft: 8, fontSize: '0.85em' }}>
{preflight.start.reason}
</span>
)}
</span>
)}
{(msStatus === 'open' || msStatus === 'freeze' || msStatus === 'undergoing') && (
<>