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' && (