feat(procurement): 開放具核准權限人員可在「待核准」狀態下編輯採購單
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Pencil, Eye, Trash2 } from "lucide-react";
|
import { Pencil, Eye, Trash2 } from "lucide-react";
|
||||||
import { Button } from "@/Components/ui/button";
|
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 type { PurchaseOrder } from "@/types/purchase-order";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { Can } from "@/Components/Permission/Can";
|
import { Can } from "@/Components/Permission/Can";
|
||||||
|
import { PageProps } from "@/types/global";
|
||||||
import {
|
import {
|
||||||
AlertDialog,
|
AlertDialog,
|
||||||
AlertDialogAction,
|
AlertDialogAction,
|
||||||
@@ -21,6 +22,18 @@ export function PurchaseOrderActions({
|
|||||||
}: { order: PurchaseOrder }) {
|
}: { order: PurchaseOrder }) {
|
||||||
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
|
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
|
||||||
const { delete: destroy, processing } = useForm({});
|
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 = () => {
|
const handleConfirmDelete = () => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -45,8 +58,7 @@ export function PurchaseOrderActions({
|
|||||||
<Eye className="h-4 w-4" />
|
<Eye className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
<Can permission="purchase_orders.edit">
|
{showEditButton && (
|
||||||
{order.status === 'draft' && (
|
|
||||||
<Link href={`/purchase-orders/${order.id}/edit`}>
|
<Link href={`/purchase-orders/${order.id}/edit`}>
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
@@ -58,7 +70,6 @@ export function PurchaseOrderActions({
|
|||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
</Can>
|
|
||||||
<Can permission="purchase_orders.delete">
|
<Can permission="purchase_orders.delete">
|
||||||
{order.status === 'draft' && (
|
{order.status === 'draft' && (
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
Reference in New Issue
Block a user