feat(procurement): 開放具核准權限人員可在「待核准」狀態下編輯採購單
This commit is contained in:
@@ -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<PageProps>().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({
|
||||
<Eye className="h-4 w-4" />
|
||||
</Button>
|
||||
</Link>
|
||||
<Can permission="purchase_orders.edit">
|
||||
{order.status === 'draft' && (
|
||||
<Link href={`/purchase-orders/${order.id}/edit`}>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="button-outlined-primary"
|
||||
title="編輯"
|
||||
>
|
||||
<Pencil className="h-4 w-4" />
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
</Can>
|
||||
{showEditButton && (
|
||||
<Link href={`/purchase-orders/${order.id}/edit`}>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="button-outlined-primary"
|
||||
title="編輯"
|
||||
>
|
||||
<Pencil className="h-4 w-4" />
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
<Can permission="purchase_orders.delete">
|
||||
{order.status === 'draft' && (
|
||||
<Button
|
||||
|
||||
Reference in New Issue
Block a user