fix: project auto-complete trigger + reject reason must persist before flipping status
- Add sync_project_status trigger so projects flip active<->completed with their tasks; backfill existing rows. - handleSubmitReject now aborts (and alerts) if the rejection-reason submission fails to save, instead of silently flipping status to in_progress and logging a reason-less rejection. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+26
-16
@@ -10,6 +10,7 @@ import { logActivity } from '../lib/activityLog';
|
||||
import JSZip from 'jszip';
|
||||
import { popupOverlayStyle, popupSurfaceStyle } from '../lib/popupStyles';
|
||||
import { useLiveRefresh } from '../hooks/useLiveRefresh';
|
||||
import { useActionLock } from '../hooks/useActionLock';
|
||||
import FileAttachment from '../components/FileAttachment';
|
||||
import { sendTaskStatusUpdate } from '../lib/taskNotifications';
|
||||
import { encodeRejectedNote, parseRejectedNote, isReviewShadowSubmission, REVIEW_SHADOW_PREFIX, getVisibleTaskSubmissions, getTaskDerivedState } from '../lib/taskVersions';
|
||||
@@ -254,6 +255,7 @@ export default function TaskDetail() {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [activeTab, setActiveTab] = useState('Overview');
|
||||
const [statusSaving, setStatusSaving] = useState(false);
|
||||
const guard = useActionLock();
|
||||
const [downloading, setDownloading] = useState('');
|
||||
const [revisionModal, setRevisionModal] = useState(false);
|
||||
const [revisionForm, setRevisionForm] = useState({ description: '', deadline: '' });
|
||||
@@ -388,7 +390,7 @@ export default function TaskDetail() {
|
||||
|
||||
const log = (action) => logActivity({ actorId: currentUser.id, actorName: currentUser.name, action, taskId: id, taskTitle: task?.title, projectId: task?.project?.id, projectName: task?.project?.name });
|
||||
|
||||
const updateStatus = async (newStatus, extra = {}, action = null) => {
|
||||
const updateStatus = guard('status', async (newStatus, extra = {}, action = null) => {
|
||||
setStatusSaving(true);
|
||||
const prevTask = task;
|
||||
setTask(t => ({ ...t, status: newStatus, ...extra }));
|
||||
@@ -409,7 +411,7 @@ export default function TaskDetail() {
|
||||
} finally {
|
||||
setStatusSaving(false);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
const handleStart = () => updateStatus('in_progress', { assigned_to: currentUser.id, assigned_name: currentUser.name }, 'task_started');
|
||||
const handleOnHold = async () => {
|
||||
@@ -428,7 +430,7 @@ export default function TaskDetail() {
|
||||
const handleResume = () => updateStatus('in_progress', {}, 'task_resumed');
|
||||
const handleSendToReview = () => { setReviewFiles([]); setReviewNotes(''); setReviewModal(true); };
|
||||
const handleRemoveFromReview = () => updateStatus('in_progress', {}, 'task_resumed');
|
||||
const handleConfirmReview = async () => {
|
||||
const handleConfirmReview = guard('review', async () => {
|
||||
setReviewSaving(true);
|
||||
try {
|
||||
const targetVersion = task.current_version || 0;
|
||||
@@ -505,8 +507,8 @@ export default function TaskDetail() {
|
||||
} finally {
|
||||
setReviewSaving(false);
|
||||
}
|
||||
};
|
||||
const handleClientApprove = async () => {
|
||||
});
|
||||
const handleClientApprove = guard('approve', async () => {
|
||||
await updateStatus('client_approved', { completed_at: new Date().toISOString() }, 'task_approved');
|
||||
sendTaskStatusUpdate({
|
||||
...notificationBase,
|
||||
@@ -518,14 +520,14 @@ export default function TaskDetail() {
|
||||
includeAssigned: true,
|
||||
includeClient: true,
|
||||
}).catch(() => {});
|
||||
};
|
||||
});
|
||||
const handleClientReject = () => { setRejectNote(''); setRejectModal(true); };
|
||||
const handleSubmitReject = async () => {
|
||||
const handleSubmitReject = guard('reject', async () => {
|
||||
if (!rejectNote.trim()) return;
|
||||
setRejectSaving(true);
|
||||
try {
|
||||
const rejectedVersion = task.current_version || 0;
|
||||
const { data: rejectedNoteSubmission } = await supabase
|
||||
const { data: rejectedNoteSubmission, error: rejectNoteError } = await supabase
|
||||
.from('submissions')
|
||||
.insert({
|
||||
task_id: id,
|
||||
@@ -538,7 +540,15 @@ export default function TaskDetail() {
|
||||
})
|
||||
.select()
|
||||
.single();
|
||||
if (rejectedNoteSubmission) setSubmissions(prev => [...prev, rejectedNoteSubmission]);
|
||||
// The rejection reason lives only in this submission row. If it didn't
|
||||
// save, do NOT flip status or log the rejection — otherwise the task
|
||||
// shows as "rejected" with no reason. Surface the error and bail.
|
||||
if (rejectNoteError || !rejectedNoteSubmission) {
|
||||
console.error('Reject note save failed:', rejectNoteError);
|
||||
window.alert(rejectNoteError?.message || 'Failed to save the rejection reason. The task was not rejected — please try again.');
|
||||
return;
|
||||
}
|
||||
setSubmissions(prev => [...prev, rejectedNoteSubmission]);
|
||||
await updateStatus('in_progress', {}, 'revision_requested');
|
||||
sendTaskStatusUpdate({
|
||||
...notificationBase,
|
||||
@@ -555,10 +565,10 @@ export default function TaskDetail() {
|
||||
} finally {
|
||||
setRejectSaving(false);
|
||||
}
|
||||
};
|
||||
});
|
||||
const handleRelease = () => updateStatus('not_started', { assigned_to: null, assigned_name: null }, 'task_released');
|
||||
|
||||
const handleSubmitRevision = async () => {
|
||||
const handleSubmitRevision = guard('revision', async () => {
|
||||
setRevisionSaving(true);
|
||||
const baseline = Math.max(task.current_version || 0, ...submissions.map(s => s.version_number || 0));
|
||||
const newVersion = baseline + 1;
|
||||
@@ -602,9 +612,9 @@ export default function TaskDetail() {
|
||||
setRevisionForm({ description: '', deadline: '' });
|
||||
setRevisionFiles([]);
|
||||
setRevisionSaving(false);
|
||||
};
|
||||
});
|
||||
|
||||
const handleSubmitAmendment = async () => {
|
||||
const handleSubmitAmendment = guard('amend', async () => {
|
||||
if (!amendForm.description.trim()) return;
|
||||
setAmendSaving(true);
|
||||
setAmendModal(false);
|
||||
@@ -638,16 +648,16 @@ export default function TaskDetail() {
|
||||
setAmendForm({ description: '' });
|
||||
setAmendFiles([]);
|
||||
setAmendSaving(false);
|
||||
};
|
||||
});
|
||||
|
||||
const handlePostComment = async () => {
|
||||
const handlePostComment = guard('comment', async () => {
|
||||
if (!commentBody.trim()) return;
|
||||
setCommentSaving(true);
|
||||
const { data } = await supabase.from('task_comments').insert({ task_id: id, author_id: currentUser.id, author_name: currentUser.name, body: commentBody.trim() }).select().single();
|
||||
if (data) setComments(prev => [...prev, data]);
|
||||
setCommentBody('');
|
||||
setCommentSaving(false);
|
||||
};
|
||||
});
|
||||
|
||||
const handleDeleteComment = async (commentId) => {
|
||||
await supabase.from('task_comments').delete().eq('id', commentId);
|
||||
|
||||
Reference in New Issue
Block a user