From 6c259859cf378a04c1b382141eb43f4032a28872 Mon Sep 17 00:00:00 2001 From: sky121113 Date: Fri, 6 Feb 2026 15:38:47 +0800 Subject: [PATCH] =?UTF-8?q?feat(procurement):=20=E9=96=8B=E6=94=BE?= =?UTF-8?q?=E5=85=B7=E6=A0=B8=E5=87=86=E6=AC=8A=E9=99=90=E4=BA=BA=E5=93=A1?= =?UTF-8?q?=E5=8F=AF=E5=9C=A8=E3=80=8C=E5=BE=85=E6=A0=B8=E5=87=86=E3=80=8D?= =?UTF-8?q?=E7=8B=80=E6=85=8B=E4=B8=8B=E7=B7=A8=E8=BC=AF=E6=8E=A1=E8=B3=BC?= =?UTF-8?q?=E5=96=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PurchaseOrder/PurchaseOrderActions.tsx | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/resources/js/Components/PurchaseOrder/PurchaseOrderActions.tsx b/resources/js/Components/PurchaseOrder/PurchaseOrderActions.tsx index 368c8ec..67066a2 100644 --- a/resources/js/Components/PurchaseOrder/PurchaseOrderActions.tsx +++ b/resources/js/Components/PurchaseOrder/PurchaseOrderActions.tsx @@ -1,10 +1,11 @@ import { useState } from "react"; import { Pencil, Eye, Trash2 } from "lucide-react"; import { Button } from "@/Components/ui/button"; -import { Link, useForm } from "@inertiajs/react"; +import { Link, useForm, usePage } from "@inertiajs/react"; import type { PurchaseOrder } from "@/types/purchase-order"; import { toast } from "sonner"; import { Can } from "@/Components/Permission/Can"; +import { PageProps } from "@/types/global"; import { AlertDialog, AlertDialogAction, @@ -21,6 +22,18 @@ export function PurchaseOrderActions({ }: { order: PurchaseOrder }) { const [showDeleteDialog, setShowDeleteDialog] = useState(false); const { delete: destroy, processing } = useForm({}); + const { auth } = usePage().props; + const permissions = auth.user?.permissions || []; + const isSuperAdmin = auth.user?.roles?.some((r: any) => r.name === 'super-admin'); + + const canApprove = isSuperAdmin || permissions.includes('purchase_orders.approve'); + const canEdit = isSuperAdmin || permissions.includes('purchase_orders.edit'); + + // 編輯按鈕顯示邏輯: + // 1. 草稿狀態 + 編輯權限 + // 2. 待核准狀態 + 核准權限 (讓主管能直接改) + const showEditButton = (order.status === 'draft' && canEdit) || + (order.status === 'pending' && canApprove); const handleConfirmDelete = () => { // @ts-ignore @@ -45,20 +58,18 @@ export function PurchaseOrderActions({ - - {order.status === 'draft' && ( - - - - )} - + {showEditButton && ( + + + + )} {order.status === 'draft' && (