From 585cb154ba71654080adeb125a87e249d224b63a Mon Sep 17 00:00:00 2001 From: Krao Hasanee Date: Fri, 27 Mar 2026 00:09:23 -0400 Subject: [PATCH] Amended request creates new submission entry with 'Amended Request' label Co-Authored-By: Claude Sonnet 4.6 --- src/components/StatusBadge.jsx | 1 + src/pages/client/RequestDetail.jsx | 31 ++++++++++++++++++++---------- supabase/schema.sql | 2 +- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/components/StatusBadge.jsx b/src/components/StatusBadge.jsx index ff131e5..4a113c1 100755 --- a/src/components/StatusBadge.jsx +++ b/src/components/StatusBadge.jsx @@ -8,6 +8,7 @@ const labels = { completed: 'Completed', initial: 'Initial', revision: 'Revision', + amendment: 'Amended', team: 'Team', client: 'Client', }; diff --git a/src/pages/client/RequestDetail.jsx b/src/pages/client/RequestDetail.jsx index 9511bad..ed5c5d1 100755 --- a/src/pages/client/RequestDetail.jsx +++ b/src/pages/client/RequestDetail.jsx @@ -93,27 +93,33 @@ export default function RequestDetail() { setSaving(true); if (action === 'edit') { - const latestSub = submissions[submissions.length - 1]; - const updatedDescription = latestSub - ? `${latestSub.description}\n\n─── Edited ${new Date().toLocaleDateString()} ───\n${revisionForm.description}` - : revisionForm.description; + const newVersion = (task.current_version || 0) + 1; + await supabase.from('tasks').update({ current_version: newVersion }).eq('id', id); - await supabase.from('submissions').update({ - description: updatedDescription, - deadline: revisionForm.deadline || latestSub?.deadline || null, - }).eq('id', latestSub.id); + const { data: newSub } = await supabase.from('submissions').insert({ + task_id: id, + version_number: newVersion + 1, + type: 'amendment', + service_type: task.title, + deadline: revisionForm.deadline || null, + description: revisionForm.description, + submitted_by: currentUser.id, + submitted_by_name: currentUser.name, + }).select().single(); - if (revisionFiles.length > 0) { + if (newSub && revisionFiles.length > 0) { for (const file of revisionFiles) { const path = `${id}/${Date.now()}_${file.name}`; const { data: uploaded } = await supabase.storage.from('submissions').upload(path, file); if (uploaded) { await supabase.from('submission_files').insert({ - submission_id: latestSub.id, name: file.name, storage_path: path, size: file.size, + submission_id: newSub.id, name: file.name, storage_path: path, size: file.size, }); } } } + + setTask(t => ({ ...t, current_version: newVersion })); } else { const newVersion = (task.current_version || 0) + 1; await supabase.from('tasks').update({ status: 'not_started', current_version: newVersion }).eq('id', id); @@ -307,6 +313,11 @@ export default function RequestDetail() { const delivery = sub.delivery; return (
+ {sub.type === 'amendment' && ( +
+ Amended Request +
+ )}
{vLabel(sub.version_number - 1)}
diff --git a/supabase/schema.sql b/supabase/schema.sql index 01ab27c..ccdaecc 100755 --- a/supabase/schema.sql +++ b/supabase/schema.sql @@ -55,7 +55,7 @@ create table public.submissions ( id uuid default gen_random_uuid() primary key, task_id uuid references public.tasks(id) on delete cascade not null, version_number integer not null, - type text not null check (type in ('initial', 'revision')) default 'initial', + type text not null check (type in ('initial', 'revision', 'amendment')) default 'initial', service_type text default '', deadline date, description text default '',