feat(P5.3+P5.4): pass completion comment in transition body, remove separate comment API call for finish/close

This commit is contained in:
zhi
2026-03-17 11:02:19 +00:00
parent faf7842cba
commit d6a45c3e17

View File

@@ -49,14 +49,13 @@ export default function TaskDetailPage() {
setComments(data) setComments(data)
} }
const doAction = async (actionName: string, newStatus: string, extra?: () => Promise<void>) => { const doAction = async (actionName: string, newStatus: string, body?: Record<string, any>) => {
setActionLoading(actionName) setActionLoading(actionName)
setActionError(null) setActionError(null)
try { try {
if (extra) await extra() await api.post(`/tasks/${id}/transition?new_status=${newStatus}`, body || {})
await api.post(`/tasks/${id}/transition?new_status=${newStatus}`)
await refreshTask() await refreshTask()
// refresh comments too (finish adds one) // refresh comments too (finish adds one via backend)
const { data } = await api.get<Comment[]>(`/tasks/${id}/comments`) const { data } = await api.get<Comment[]>(`/tasks/${id}/comments`)
setComments(data) setComments(data)
} catch (err: any) { } catch (err: any) {
@@ -70,17 +69,16 @@ export default function TaskDetailPage() {
const handleStart = () => doAction('start', 'undergoing') const handleStart = () => doAction('start', 'undergoing')
const handleFinishConfirm = async () => { const handleFinishConfirm = async () => {
if (!finishComment.trim()) return if (!finishComment.trim()) return
await doAction('finish', 'completed', async () => { await doAction('finish', 'completed', { comment: finishComment })
await api.post('/comments', { content: finishComment, task_id: task!.id, author_id: user?.id || 1 })
})
setShowFinishModal(false) setShowFinishModal(false)
setFinishComment('') setFinishComment('')
} }
const handleCloseConfirm = async () => { const handleCloseConfirm = async () => {
const body: Record<string, any> = {}
if (closeReason.trim()) { if (closeReason.trim()) {
await api.post('/comments', { content: `[Close reason] ${closeReason}`, task_id: task!.id, author_id: user?.id || 1 }).catch(() => {}) body.comment = `[Close reason] ${closeReason}`
} }
await doAction('close', 'closed') await doAction('close', 'closed', body)
setShowCloseModal(false) setShowCloseModal(false)
setCloseReason('') setCloseReason('')
} }