diff --git a/fe-admin/src/components/pe/PeWorkflowPanel.tsx b/fe-admin/src/components/pe/PeWorkflowPanel.tsx index 9aa63de..ab4571d 100644 --- a/fe-admin/src/components/pe/PeWorkflowPanel.tsx +++ b/fe-admin/src/components/pe/PeWorkflowPanel.tsx @@ -12,6 +12,7 @@ import { Textarea } from '@/components/ui/Textarea' import { api } from '@/lib/api' import { getErrorMessage } from '@/lib/apiError' import { cn } from '@/lib/cn' +import { useAuth } from '@/contexts/AuthContext' import { ApprovalStage, PurchaseEvaluationPhase, @@ -33,6 +34,20 @@ export function PeWorkflowPanel({ const [target, setTarget] = useState(null) const [comment, setComment] = useState('') const qc = useQueryClient() + const { user: currentUser } = useAuth() + const isAdmin = currentUser?.roles?.includes('Admin') ?? false + + // Mig 24 — V2 schema chỉ cho phép approver trong CurrentApproval.approvers + // duyệt cấp hiện tại. Nếu actor không khớp → disable nút "Duyệt forward" + // (Trả lại / Từ chối vẫn enabled vì Service không kiểm Bước/Cấp với 2 + // hành động này — Approver có thể reject bất cứ lúc nào trong phiên). + // Admin bypass. + const v2Approvers = evaluation.currentApproval?.approvers ?? [] + const actorInV2Level = isAdmin + || (currentUser?.id && v2Approvers.some(a => a.userId === currentUser.id)) + // V2 active = phiếu pin V2 + Phase=ChoDuyet + có currentApproval + const isV2Pending = !!evaluation.currentApproval + const blockedByV2Level = isV2Pending && !actorInV2Level // 2-stage dept approvals (Migration 16) — fetch riêng để FE Workflow Panel // hiển thị progress per phase × dept (Stage Review NV / Confirm TPB). @@ -107,33 +122,65 @@ export function PeWorkflowPanel({ })} + {/* Mig 24 — V2 banner: hiển thị Bước/Cấp hiện tại + danh sách NV được duyệt. + Nếu actor không có trong list → banner amber + nút Duyệt sẽ disable. */} + {isV2Pending && evaluation.currentApproval && !readOnly && ( +
+
+ Đang chờ Bước {evaluation.currentApproval.stepIndex + 1} ({evaluation.currentApproval.stepName}) + {evaluation.currentApproval.stepDepartmentName && <> · {evaluation.currentApproval.stepDepartmentName}} + {' — '}Cấp {evaluation.currentApproval.levelOrder} +
+
+ NV duyệt: {evaluation.currentApproval.approvers.map(a => a.fullName).join(' / ') || '(chưa có)'} +
+ {actorInV2Level + ?
✓ Đến lượt bạn duyệt
+ :
⚠ Không phải lượt bạn — chỉ NV trên mới duyệt được cấp này
} +
+ )} + {next.length > 0 && !readOnly && (
{next.map(p => { // Phân loại button theo hành động: - // - Trả lại = về DangSoanThao (từ phase trung gian) — red + // - Trả lại = về DangSoanThao/TraLai (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 + const isSendBack = (p === PurchaseEvaluationPhase.DangSoanThao || p === PurchaseEvaluationPhase.TraLai) && evaluation.phase !== PurchaseEvaluationPhase.DangSoanThao + && evaluation.phase !== PurchaseEvaluationPhase.TraLai const isCancel = p === PurchaseEvaluationPhase.TuChoi const isDanger = isSendBack || isCancel + const isForwardApprove = !isDanger + // Mig 24 — disable Duyệt forward nếu V2 pin + actor không trong cấp hiện tại + const isDisabled = isForwardApprove && blockedByV2Level const label = isSendBack ? '← Trả lại (về Drafter sửa)' : isCancel ? '✗ Hủy / Từ chối' : `✓ Duyệt → ${PurchaseEvaluationPhaseLabel[p]}` + const title = isDisabled && evaluation.currentApproval + ? `Cấp ${evaluation.currentApproval.levelOrder} chỉ ${evaluation.currentApproval.approvers.map(a => a.fullName).join(' / ')} mới duyệt được.` + : undefined return (