feat(P5.3+P5.4): pass completion comment in transition body, remove separate comment API call for finish/close
This commit is contained in:
@@ -49,14 +49,13 @@ export default function TaskDetailPage() {
|
||||
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)
|
||||
setActionError(null)
|
||||
try {
|
||||
if (extra) await extra()
|
||||
await api.post(`/tasks/${id}/transition?new_status=${newStatus}`)
|
||||
await api.post(`/tasks/${id}/transition?new_status=${newStatus}`, body || {})
|
||||
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`)
|
||||
setComments(data)
|
||||
} catch (err: any) {
|
||||
@@ -70,17 +69,16 @@ export default function TaskDetailPage() {
|
||||
const handleStart = () => doAction('start', 'undergoing')
|
||||
const handleFinishConfirm = async () => {
|
||||
if (!finishComment.trim()) return
|
||||
await doAction('finish', 'completed', async () => {
|
||||
await api.post('/comments', { content: finishComment, task_id: task!.id, author_id: user?.id || 1 })
|
||||
})
|
||||
await doAction('finish', 'completed', { comment: finishComment })
|
||||
setShowFinishModal(false)
|
||||
setFinishComment('')
|
||||
}
|
||||
const handleCloseConfirm = async () => {
|
||||
const body: Record<string, any> = {}
|
||||
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)
|
||||
setCloseReason('')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user