diff --git a/src/pages/TaskDetailPage.tsx b/src/pages/TaskDetailPage.tsx index 2b74a00..72a4264 100644 --- a/src/pages/TaskDetailPage.tsx +++ b/src/pages/TaskDetailPage.tsx @@ -49,14 +49,13 @@ export default function TaskDetailPage() { setComments(data) } - const doAction = async (actionName: string, newStatus: string, extra?: () => Promise) => { + const doAction = async (actionName: string, newStatus: string, body?: Record) => { 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(`/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 = {} 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('') }