diff --git a/fe-admin/src/components/pe/PeWorkflowPanel.tsx b/fe-admin/src/components/pe/PeWorkflowPanel.tsx index 02e3ee9..9aa63de 100644 --- a/fe-admin/src/components/pe/PeWorkflowPanel.tsx +++ b/fe-admin/src/components/pe/PeWorkflowPanel.tsx @@ -45,12 +45,20 @@ export function PeWorkflowPanel({ }) const transition = useMutation({ - mutationFn: async () => - api.post(`/purchase-evaluations/${evaluation.id}/transitions`, { + mutationFn: async () => { + // Decision = Reject (2) khi: + // - target = TuChoi (huỷ phiếu) + // - target = DangSoanThao từ phase trung gian (= Trả lại — smart reject Mig 16 + // set RejectedFromPhase + clear N-stage rows + Drafter resume jump-back) + const isReject = target === PurchaseEvaluationPhase.TuChoi + || (target === PurchaseEvaluationPhase.DangSoanThao + && evaluation.phase !== PurchaseEvaluationPhase.DangSoanThao) + return api.post(`/purchase-evaluations/${evaluation.id}/transitions`, { targetPhase: target, - decision: target === PurchaseEvaluationPhase.TuChoi ? 2 : 1, + decision: isReject ? 2 : 1, comment: comment || null, - }), + }) + }, onSuccess: () => { toast.success('Đã chuyển phase.') qc.invalidateQueries({ queryKey: ['pe-detail', evaluation.id] }) @@ -101,22 +109,37 @@ export function PeWorkflowPanel({ {next.length > 0 && !readOnly && (
- +
- {next.map(p => ( - - ))} + {next.map(p => { + // Phân loại button theo hành động: + // - Trả lại = về DangSoanThao (từ phase trung gian) — red + // - Hủy/Từ chối = TuChoi (chỉ ở phase DangSoanThao đầu) — red + // - Duyệt = forward phase tiếp theo — brand + const isSendBack = p === PurchaseEvaluationPhase.DangSoanThao + && evaluation.phase !== PurchaseEvaluationPhase.DangSoanThao + const isCancel = p === PurchaseEvaluationPhase.TuChoi + const isDanger = isSendBack || isCancel + const label = isSendBack + ? '← Trả lại (về Drafter sửa)' + : isCancel + ? '✗ Hủy / Từ chối' + : `✓ Duyệt → ${PurchaseEvaluationPhaseLabel[p]}` + return ( + + ) + })}
)} @@ -126,20 +149,40 @@ export function PeWorkflowPanel({ )} - {target !== null && ( - setTarget(null)} - title={`Chuyển → ${PurchaseEvaluationPhaseLabel[target]}`} - footer={<> - - - } - > - -