From 53e443b4f1dbfc3fae11e5f05b86b181d76b3222 Mon Sep 17 00:00:00 2001 From: kovakmedya Date: Fri, 22 May 2026 16:03:36 +0300 Subject: [PATCH] =?UTF-8?q?feat(jobs):=20clinic-side=20'D=C3=BCzeltme=20?= =?UTF-8?q?=C4=B0ste'=20(revision=20request)=20flow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Up to now the only thing a clinic could do on a prova was approve it. If the casting didn't fit there was no way to bounce the case back to the lab short of cancelling the whole thing. Real-world flow needs a 'try again, this is what's wrong' lever, so: - requestRevisionAction (clinic only): pre-conditions in_progress + at_clinic + currentStep set; flips location → at_lab while leaving currentStep untouched so the same prova stage repeats after the lab redoes the work. Requires a note (the lab can't fix what it doesn't know is broken) — appended to job_status_history with a '[Düzeltme talebi]' prefix and surfaced to the lab via notification. - JobActionsPanel: when the clinic side sees a prova (in_progress + at_clinic) it now shows two buttons — Onayla as before, plus Düzeltme İste (variant=destructive). The dialog requires a note before submit. --- .../[jobId]/components/job-actions-panel.tsx | 69 +++++++++++++- src/lib/appwrite/job-actions.ts | 89 +++++++++++++++++++ 2 files changed, 157 insertions(+), 1 deletion(-) diff --git a/src/app/(dashboard)/jobs/[jobId]/components/job-actions-panel.tsx b/src/app/(dashboard)/jobs/[jobId]/components/job-actions-panel.tsx index b4c54ca..a5744a6 100644 --- a/src/app/(dashboard)/jobs/[jobId]/components/job-actions-panel.tsx +++ b/src/app/(dashboard)/jobs/[jobId]/components/job-actions-panel.tsx @@ -9,6 +9,7 @@ import { Loader2, PackageCheck, Play, + RotateCcw, Send, X, } from "lucide-react"; @@ -32,6 +33,7 @@ import { cancelJobAction, handToClinicAction, markDeliveredAction, + requestRevisionAction, } from "@/lib/appwrite/job-actions"; import { initialJobActionState } from "@/lib/appwrite/job-types"; import type { Job, TenantKind } from "@/lib/appwrite/schema"; @@ -67,7 +69,10 @@ export function JobActionsPanel({ {/* Clinic finished the prova — approve and send back to lab */} {isClinic && job.status === "in_progress" && isAtClinic && ( - + <> + + + )} {/* Final delivery — clinic took it from the lab */} @@ -236,6 +241,68 @@ function ApproveAtClinicButton({ job }: { job: Job }) { ); } +function RequestRevisionButton({ job }: { job: Job }) { + const router = useRouter(); + const [state, action, pending] = useActionState( + requestRevisionAction, + initialJobActionState, + ); + const [open, setOpen] = useState(false); + + useEffect(() => { + if (state.ok) { + toast.success("Düzeltme talebi gönderildi."); + setOpen(false); + router.refresh(); + } else if (state.error) { + toast.error(state.error); + } + }, [state, router]); + + return ( + + + + + Provayı reddet, lab'a geri gönder + + Bu aşamayı reddettiğinizde iş aynı adımda kalır ve laboratuvar + yeniden çalışır. Neyin düzeltilmesi gerektiğini lütfen yazın. + + +
+ +
+ +