feat: 統一全系統頁面標題樣式、優化側邊欄與實作角色成員查看功能
This commit is contained in:
@@ -20,8 +20,8 @@ import {
|
||||
AlertDialogTitle,
|
||||
AlertDialogTrigger,
|
||||
} from "@/Components/ui/alert-dialog";
|
||||
import { Can } from "@/Components/Permission/Can";
|
||||
import type { Product } from "@/Pages/Product/Index";
|
||||
// import BarcodeViewDialog from "@/Components/Product/BarcodeViewDialog";
|
||||
|
||||
interface ProductTableProps {
|
||||
products: Product[];
|
||||
@@ -147,38 +147,42 @@ export default function ProductTable({
|
||||
<Eye className="h-4 w-4" />
|
||||
</Button>
|
||||
*/}
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onEdit(product)}
|
||||
className="button-outlined-primary"
|
||||
>
|
||||
<Pencil className="h-4 w-4" />
|
||||
</Button>
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger asChild>
|
||||
<Button variant="outline" size="sm" className="button-outlined-error">
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>確認刪除</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
確定要刪除「{product.name}」嗎?此操作無法復原。
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={() => onDelete(product.id)}
|
||||
className="bg-red-600 hover:bg-red-700"
|
||||
>
|
||||
刪除
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
<Can permission="products.edit">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onEdit(product)}
|
||||
className="button-outlined-primary"
|
||||
>
|
||||
<Pencil className="h-4 w-4" />
|
||||
</Button>
|
||||
</Can>
|
||||
<Can permission="products.delete">
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger asChild>
|
||||
<Button variant="outline" size="sm" className="button-outlined-error">
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>確認刪除</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
確定要刪除「{product.name}」嗎?此操作無法復原。
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={() => onDelete(product.id)}
|
||||
className="bg-red-600 hover:bg-red-700"
|
||||
>
|
||||
刪除
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</Can>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Button } from "@/Components/ui/button";
|
||||
import { Link, useForm } from "@inertiajs/react";
|
||||
import type { PurchaseOrder } from "@/types/purchase-order";
|
||||
import { toast } from "sonner";
|
||||
import { Can } from "@/Components/Permission/Can";
|
||||
|
||||
export function PurchaseOrderActions({
|
||||
order,
|
||||
@@ -31,26 +32,30 @@ export function PurchaseOrderActions({
|
||||
<Eye className="h-4 w-4" />
|
||||
</Button>
|
||||
</Link>
|
||||
<Link href={`/purchase-orders/${order.id}/edit`}>
|
||||
<Can permission="purchase_orders.edit">
|
||||
<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>
|
||||
<Can permission="purchase_orders.delete">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="button-outlined-primary"
|
||||
title="編輯"
|
||||
className="button-outlined-error"
|
||||
title="刪除"
|
||||
onClick={handleDelete}
|
||||
disabled={processing}
|
||||
>
|
||||
<Pencil className="h-4 w-4" />
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</Link>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="button-outlined-error"
|
||||
title="刪除"
|
||||
onClick={() => onDelete?.(order.id)}
|
||||
disabled={processing}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</Can>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
69
resources/js/Components/Vendor/VendorTable.tsx
vendored
69
resources/js/Components/Vendor/VendorTable.tsx
vendored
@@ -19,6 +19,7 @@ import {
|
||||
AlertDialogTitle,
|
||||
AlertDialogTrigger,
|
||||
} from "@/Components/ui/alert-dialog";
|
||||
import { Can } from "@/Components/Permission/Can";
|
||||
import type { Vendor } from "@/Pages/Vendor/Index";
|
||||
|
||||
interface VendorTableProps {
|
||||
@@ -122,38 +123,42 @@ export default function VendorTable({
|
||||
>
|
||||
<Eye className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onEdit(vendor)}
|
||||
className="button-outlined-primary"
|
||||
>
|
||||
<Pencil className="h-4 w-4" />
|
||||
</Button>
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger asChild>
|
||||
<Button variant="outline" size="sm" className="button-outlined-error">
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>確認刪除</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
確定要刪除廠商「{vendor.name}」嗎?此操作無法復原。
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={() => onDelete(vendor.id)}
|
||||
className="bg-red-600 hover:bg-red-700"
|
||||
>
|
||||
刪除
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
<Can permission="vendors.edit">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onEdit(vendor)}
|
||||
className="button-outlined-primary"
|
||||
>
|
||||
<Pencil className="h-4 w-4" />
|
||||
</Button>
|
||||
</Can>
|
||||
<Can permission="vendors.delete">
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger asChild>
|
||||
<Button variant="outline" size="sm" className="button-outlined-error">
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>確認刪除</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
確定要刪除廠商「{vendor.name}」嗎?此操作無法復原。
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={() => onDelete(vendor.id)}
|
||||
className="bg-red-600 hover:bg-red-700"
|
||||
>
|
||||
刪除
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</Can>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
|
||||
@@ -27,6 +27,7 @@ import { Badge } from "@/Components/ui/badge";
|
||||
import { WarehouseInventory } from "@/types/warehouse";
|
||||
import { getSafetyStockStatus } from "@/utils/inventory";
|
||||
import { formatDate } from "@/utils/format";
|
||||
import { Can } from "@/Components/Permission/Can";
|
||||
|
||||
interface InventoryTableProps {
|
||||
inventories: WarehouseInventory[];
|
||||
@@ -280,15 +281,17 @@ export default function InventoryTable({
|
||||
>
|
||||
<Eye className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onDelete(item.id)}
|
||||
title="刪除"
|
||||
className="button-outlined-error"
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
<Can permission="inventory.delete">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onDelete(item.id)}
|
||||
title="刪除"
|
||||
className="button-outlined-error"
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</Can>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
|
||||
@@ -15,6 +15,7 @@ import { Button } from "@/Components/ui/button";
|
||||
import { Badge } from "@/Components/ui/badge";
|
||||
import { SafetyStockSetting, WarehouseInventory } from "@/types/warehouse";
|
||||
import { calculateProductTotalStock, getSafetyStockStatus } from "@/utils/inventory";
|
||||
import { Can } from "@/Components/Permission/Can";
|
||||
|
||||
interface SafetyStockListProps {
|
||||
settings: SafetyStockSetting[];
|
||||
@@ -125,22 +126,24 @@ export default function SafetyStockList({
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onEdit(setting)}
|
||||
className="button-outlined-primary"
|
||||
>
|
||||
<Pencil className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onDelete(setting.id)}
|
||||
className="button-outlined-error"
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
<Can permission="inventory.safety_stock">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onEdit(setting)}
|
||||
className="button-outlined-primary"
|
||||
>
|
||||
<Pencil className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onDelete(setting.id)}
|
||||
className="button-outlined-error"
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</Can>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
Warehouse,
|
||||
Truck,
|
||||
Contact2,
|
||||
FileText,
|
||||
LogOut,
|
||||
User,
|
||||
ChevronDown,
|
||||
@@ -20,7 +19,7 @@ import {
|
||||
Users
|
||||
} from "lucide-react";
|
||||
import { toast, Toaster } from "sonner";
|
||||
import { useState, useEffect } from "react";
|
||||
import { useState, useEffect, useMemo } from "react";
|
||||
import { Link, usePage } from "@inertiajs/react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import BreadcrumbNav, { BreadcrumbItemType } from "@/Components/shared/BreadcrumbNav";
|
||||
@@ -32,6 +31,8 @@ import {
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/Components/ui/dropdown-menu";
|
||||
import { usePermission } from "@/hooks/usePermission";
|
||||
import ApplicationLogo from "@/Components/ApplicationLogo";
|
||||
|
||||
interface MenuItem {
|
||||
id: string;
|
||||
@@ -39,6 +40,7 @@ interface MenuItem {
|
||||
icon?: React.ReactNode;
|
||||
route?: string;
|
||||
children?: MenuItem[];
|
||||
permission?: string | string[]; // 所需權限(單一或多個,滿足任一即可)
|
||||
}
|
||||
|
||||
export default function AuthenticatedLayout({
|
||||
@@ -51,6 +53,7 @@ export default function AuthenticatedLayout({
|
||||
const { url, props } = usePage();
|
||||
// @ts-ignore
|
||||
const user = props.auth?.user || { name: 'Guest', username: 'guest' };
|
||||
const { can, canAny } = usePermission();
|
||||
const [isCollapsed, setIsCollapsed] = useState(() => {
|
||||
if (typeof window !== "undefined") {
|
||||
return localStorage.getItem("sidebar-collapsed") === "true";
|
||||
@@ -59,29 +62,34 @@ export default function AuthenticatedLayout({
|
||||
});
|
||||
const [isMobileOpen, setIsMobileOpen] = useState(false);
|
||||
|
||||
const menuItems: MenuItem[] = [
|
||||
// 完整的菜單定義(含權限配置)
|
||||
const allMenuItems: MenuItem[] = [
|
||||
{
|
||||
id: "dashboard",
|
||||
label: "儀表板",
|
||||
icon: <LayoutDashboard className="h-5 w-5" />,
|
||||
route: "/",
|
||||
// 儀表板無需特定權限,所有登入使用者皆可存取
|
||||
},
|
||||
{
|
||||
id: "inventory-management",
|
||||
label: "商品與庫存管理",
|
||||
icon: <Boxes className="h-5 w-5" />,
|
||||
permission: ["products.view", "warehouses.view"], // 滿足任一即可看到此群組
|
||||
children: [
|
||||
{
|
||||
id: "product-management",
|
||||
label: "商品資料管理",
|
||||
icon: <Package className="h-4 w-4" />,
|
||||
route: "/products",
|
||||
permission: "products.view",
|
||||
},
|
||||
{
|
||||
id: "warehouse-management",
|
||||
label: "倉庫管理",
|
||||
icon: <Warehouse className="h-4 w-4" />,
|
||||
route: "/warehouses",
|
||||
permission: "warehouses.view",
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -89,12 +97,14 @@ export default function AuthenticatedLayout({
|
||||
id: "vendor-management",
|
||||
label: "廠商管理",
|
||||
icon: <Truck className="h-5 w-5" />,
|
||||
permission: "vendors.view",
|
||||
children: [
|
||||
{
|
||||
id: "vendor-list",
|
||||
label: "廠商資料管理",
|
||||
icon: <Contact2 className="h-4 w-4" />,
|
||||
route: "/vendors",
|
||||
permission: "vendors.view",
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -102,12 +112,14 @@ export default function AuthenticatedLayout({
|
||||
id: "purchase-management",
|
||||
label: "採購管理",
|
||||
icon: <ShoppingCart className="h-5 w-5" />,
|
||||
permission: "purchase_orders.view",
|
||||
children: [
|
||||
{
|
||||
id: "purchase-order-list",
|
||||
label: "管理採購單",
|
||||
icon: <FileText className="h-4 w-4" />,
|
||||
label: "採購單管理",
|
||||
icon: <ShoppingCart className="h-4 w-4" />,
|
||||
route: "/purchase-orders",
|
||||
permission: "purchase_orders.view",
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -115,23 +127,53 @@ export default function AuthenticatedLayout({
|
||||
id: "system-management",
|
||||
label: "系統管理",
|
||||
icon: <Settings className="h-5 w-5" />,
|
||||
permission: ["users.view", "roles.view"],
|
||||
children: [
|
||||
{
|
||||
id: "user-management",
|
||||
label: "使用者管理",
|
||||
icon: <Users className="h-4 w-4" />,
|
||||
route: "/admin/users",
|
||||
permission: "users.view",
|
||||
},
|
||||
{
|
||||
id: "role-management",
|
||||
label: "角色與權限",
|
||||
icon: <Shield className="h-4 w-4" />,
|
||||
route: "/admin/roles",
|
||||
permission: "roles.view",
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
// 檢查單一項目是否有權限
|
||||
const hasPermissionForItem = (item: MenuItem): boolean => {
|
||||
if (!item.permission) return true; // 無指定權限則預設有權限
|
||||
if (Array.isArray(item.permission)) {
|
||||
return canAny(item.permission);
|
||||
}
|
||||
return can(item.permission);
|
||||
};
|
||||
|
||||
// 過濾菜單:移除無權限的項目,若父層所有子項目都無權限則隱藏父層
|
||||
const menuItems = useMemo(() => {
|
||||
return allMenuItems
|
||||
.map((item) => {
|
||||
// 如果有子項目,先過濾子項目
|
||||
if (item.children && item.children.length > 0) {
|
||||
const filteredChildren = item.children.filter(hasPermissionForItem);
|
||||
// 若所有子項目都無權限,則隱藏整個群組
|
||||
if (filteredChildren.length === 0) return null;
|
||||
return { ...item, children: filteredChildren };
|
||||
}
|
||||
// 無子項目的單一選單,直接檢查權限
|
||||
if (!hasPermissionForItem(item)) return null;
|
||||
return item;
|
||||
})
|
||||
.filter((item): item is MenuItem => item !== null);
|
||||
}, [can, canAny]);
|
||||
|
||||
// 初始化狀態:優先讀取 localStorage
|
||||
const [expandedItems, setExpandedItems] = useState<string[]>(() => {
|
||||
try {
|
||||
@@ -296,7 +338,7 @@ export default function AuthenticatedLayout({
|
||||
{isMobileOpen ? <X className="h-6 w-6" /> : <Menu className="h-6 w-6" />}
|
||||
</button>
|
||||
<Link href="/" className="flex items-center gap-2">
|
||||
<div className="w-8 h-8 rounded-lg bg-primary-main flex items-center justify-center text-white font-bold text-lg">K</div>
|
||||
<ApplicationLogo className="w-8 h-8 rounded-lg object-contain" />
|
||||
<span className="font-bold text-slate-900">小小冰室 ERP</span>
|
||||
</Link>
|
||||
</div>
|
||||
@@ -342,12 +384,14 @@ export default function AuthenticatedLayout({
|
||||
<div className="hidden h-16 items-center justify-between px-6 border-b border-slate-100">
|
||||
{!isCollapsed && (
|
||||
<Link href="/" className="flex items-center gap-2 group">
|
||||
<div className="w-8 h-8 rounded-lg bg-primary-main flex items-center justify-center text-white font-bold text-lg group-hover:scale-110 transition-transform">K</div>
|
||||
<ApplicationLogo className="w-8 h-8 rounded-lg object-contain group-hover:scale-110 transition-transform" />
|
||||
<span className="font-extrabold text-[#01ab83] text-lg tracking-tight">小小冰室 ERP</span>
|
||||
</Link>
|
||||
)}
|
||||
{isCollapsed && (
|
||||
<Link href="/" className="w-8 h-8 rounded-lg bg-primary-main flex items-center justify-center text-white font-bold text-lg mx-auto">K</Link>
|
||||
<Link href="/" className="w-8 h-8 mx-auto">
|
||||
<ApplicationLogo className="w-8 h-8 rounded-lg object-contain" />
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -389,7 +433,7 @@ export default function AuthenticatedLayout({
|
||||
)}>
|
||||
<div className="h-16 flex items-center justify-between px-6 border-b border-slate-100">
|
||||
<Link href="/" className="flex items-center gap-2">
|
||||
<div className="w-8 h-8 rounded-lg bg-primary-main flex items-center justify-center text-white font-bold text-lg">K</div>
|
||||
<ApplicationLogo className="w-8 h-8 rounded-lg object-contain" />
|
||||
<span className="font-extrabold text-[#01ab83] text-lg">小小冰室 ERP</span>
|
||||
</Link>
|
||||
<button onClick={() => setIsMobileOpen(false)} className="p-2 text-slate-400">
|
||||
|
||||
@@ -25,6 +25,7 @@ interface Props {
|
||||
export default function RoleCreate({ groupedPermissions }: Props) {
|
||||
const { data, setData, post, processing, errors } = useForm({
|
||||
name: '',
|
||||
display_name: '',
|
||||
permissions: [] as string[],
|
||||
});
|
||||
|
||||
@@ -70,8 +71,9 @@ export default function RoleCreate({ groupedPermissions }: Props) {
|
||||
'edit': '編輯',
|
||||
'delete': '刪除',
|
||||
'publish': '發布',
|
||||
'adjust': '調整',
|
||||
'adjust': '新增 / 調整',
|
||||
'transfer': '調撥',
|
||||
'safety_stock': '安全庫存設定',
|
||||
};
|
||||
|
||||
return map[action] || action;
|
||||
@@ -87,29 +89,34 @@ export default function RoleCreate({ groupedPermissions }: Props) {
|
||||
>
|
||||
<Head title="建立角色" />
|
||||
|
||||
<div className="p-8 max-w-7xl mx-auto">
|
||||
<form onSubmit={handleSubmit} className="space-y-8">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<Shield className="h-6 w-6 text-[#01ab83]" />
|
||||
建立新角色
|
||||
</h1>
|
||||
<p className="text-gray-500 mt-1">
|
||||
設定角色名稱並分配對應的操作權限
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<Link href={route('roles.index')}>
|
||||
<Button variant="outline" type="button">
|
||||
<ArrowLeft className="h-4 w-4 mr-2" />
|
||||
取消
|
||||
</Button>
|
||||
</Link>
|
||||
<div className="container mx-auto p-6 max-w-7xl">
|
||||
<form onSubmit={handleSubmit} className="space-y-6">
|
||||
{/* Header Area */}
|
||||
<div>
|
||||
<Link href={route('roles.index')}>
|
||||
<Button
|
||||
variant="outline"
|
||||
type="button"
|
||||
className="gap-2 button-outlined-primary mb-2"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
返回角色與權限
|
||||
</Button>
|
||||
</Link>
|
||||
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<Shield className="h-6 w-6 text-[#01ab83]" />
|
||||
建立新角色
|
||||
</h1>
|
||||
<p className="text-gray-500 mt-1">
|
||||
設定角色名稱並分配對應的操作權限
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
type="submit"
|
||||
className="bg-[#01ab83] hover:bg-[#019a76]"
|
||||
className="button-filled-primary"
|
||||
disabled={processing}
|
||||
>
|
||||
<Check className="h-4 w-4 mr-2" />
|
||||
@@ -120,9 +127,25 @@ export default function RoleCreate({ groupedPermissions }: Props) {
|
||||
|
||||
{/* Role Name */}
|
||||
<div className="bg-white p-6 rounded-xl border border-gray-200 shadow-sm">
|
||||
<div className="max-w-md space-y-4">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="name">角色名稱 (英文代號)</Label>
|
||||
<Label htmlFor="display_name">顯示名稱 (中文/自定義)</Label>
|
||||
<Input
|
||||
id="display_name"
|
||||
placeholder="例如:行政管理員"
|
||||
value={data.display_name}
|
||||
onChange={e => setData('display_name', e.target.value)}
|
||||
/>
|
||||
{errors.display_name && (
|
||||
<p className="text-sm text-red-500">{errors.display_name}</p>
|
||||
)}
|
||||
<p className="text-xs text-gray-500">
|
||||
這是在介面上看到的名稱。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="name">英文代號 (系統識別用)</Label>
|
||||
<Input
|
||||
id="name"
|
||||
placeholder="e.g. sales-manager"
|
||||
|
||||
@@ -21,6 +21,7 @@ interface GroupedPermission {
|
||||
interface Role {
|
||||
id: number;
|
||||
name: string;
|
||||
display_name: string;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
@@ -32,6 +33,7 @@ interface Props {
|
||||
export default function RoleEdit({ role, groupedPermissions, currentPermissions }: Props) {
|
||||
const { data, setData, put, processing, errors } = useForm({
|
||||
name: role.name,
|
||||
display_name: role.display_name || '',
|
||||
permissions: currentPermissions,
|
||||
});
|
||||
|
||||
@@ -76,8 +78,9 @@ export default function RoleEdit({ role, groupedPermissions, currentPermissions
|
||||
'edit': '編輯',
|
||||
'delete': '刪除',
|
||||
'publish': '發布',
|
||||
'adjust': '調整',
|
||||
'adjust': '新增 / 調整',
|
||||
'transfer': '調撥',
|
||||
'safety_stock': '安全庫存設定',
|
||||
};
|
||||
|
||||
return map[action] || action;
|
||||
@@ -93,29 +96,34 @@ export default function RoleEdit({ role, groupedPermissions, currentPermissions
|
||||
>
|
||||
<Head title={`編輯角色 - ${role.name}`} />
|
||||
|
||||
<div className="p-8 max-w-7xl mx-auto">
|
||||
<form onSubmit={handleSubmit} className="space-y-8">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<Shield className="h-6 w-6 text-[#01ab83]" />
|
||||
編輯角色
|
||||
</h1>
|
||||
<p className="text-gray-500 mt-1">
|
||||
修改角色資料與權限設定
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<Link href={route('roles.index')}>
|
||||
<Button variant="outline" type="button">
|
||||
<ArrowLeft className="h-4 w-4 mr-2" />
|
||||
取消
|
||||
</Button>
|
||||
</Link>
|
||||
<div className="container mx-auto p-6 max-w-7xl">
|
||||
<form onSubmit={handleSubmit} className="space-y-6">
|
||||
{/* Header Area */}
|
||||
<div>
|
||||
<Link href={route('roles.index')}>
|
||||
<Button
|
||||
variant="outline"
|
||||
type="button"
|
||||
className="gap-2 button-outlined-primary mb-2"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
返回角色與權限
|
||||
</Button>
|
||||
</Link>
|
||||
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<Shield className="h-6 w-6 text-[#01ab83]" />
|
||||
編輯角色
|
||||
</h1>
|
||||
<p className="text-gray-500 mt-1">
|
||||
修改角色資料與權限設定
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
type="submit"
|
||||
className="bg-[#01ab83] hover:bg-[#019a76]"
|
||||
className="button-filled-primary"
|
||||
disabled={processing}
|
||||
>
|
||||
<Check className="h-4 w-4 mr-2" />
|
||||
@@ -126,15 +134,31 @@ export default function RoleEdit({ role, groupedPermissions, currentPermissions
|
||||
|
||||
{/* Role Name */}
|
||||
<div className="bg-white p-6 rounded-xl border border-gray-200 shadow-sm">
|
||||
<div className="max-w-md space-y-4">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="name">角色名稱 (英文代號)</Label>
|
||||
<Label htmlFor="display_name">顯示名稱 (中文/自定義)</Label>
|
||||
<Input
|
||||
id="display_name"
|
||||
placeholder="例如:行政管理員"
|
||||
value={data.display_name}
|
||||
onChange={e => setData('display_name', e.target.value)}
|
||||
/>
|
||||
{errors.display_name && (
|
||||
<p className="text-sm text-red-500">{errors.display_name}</p>
|
||||
)}
|
||||
<p className="text-xs text-gray-500">
|
||||
這是在介面上看到的名稱。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="name">英文代號 (系統識別用)</Label>
|
||||
<Input
|
||||
id="name"
|
||||
value={data.name}
|
||||
onChange={e => setData('name', e.target.value)}
|
||||
className="font-mono bg-gray-50"
|
||||
disabled={role.name === 'super-admin'} // Should be handled by controller redirect, but extra safety
|
||||
disabled={role.name === 'super-admin'}
|
||||
/>
|
||||
{errors.name && (
|
||||
<p className="text-sm text-red-500">{errors.name}</p>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout';
|
||||
import { Head, Link, router } from '@inertiajs/react';
|
||||
import { cn } from "@/lib/utils";
|
||||
import { Shield, Plus, Pencil, Trash2, Users } from 'lucide-react';
|
||||
import { Button } from '@/Components/ui/button';
|
||||
import {
|
||||
@@ -12,13 +13,30 @@ import {
|
||||
} from "@/Components/ui/table";
|
||||
import { format } from 'date-fns';
|
||||
import { toast } from 'sonner';
|
||||
import { Can } from '@/Components/Permission/Can';
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/Components/ui/dialog";
|
||||
|
||||
interface User {
|
||||
id: number;
|
||||
name: string;
|
||||
username: string;
|
||||
}
|
||||
|
||||
interface Role {
|
||||
id: number;
|
||||
name: string;
|
||||
display_name: string;
|
||||
users_count: number;
|
||||
permissions_count: number;
|
||||
created_at: string;
|
||||
users?: User[];
|
||||
}
|
||||
|
||||
interface Props {
|
||||
@@ -26,6 +44,8 @@ interface Props {
|
||||
}
|
||||
|
||||
export default function RoleIndex({ roles }: Props) {
|
||||
const [selectedRole, setSelectedRole] = useState<Role | null>(null);
|
||||
|
||||
const handleDelete = (id: number, name: string) => {
|
||||
if (confirm(`確定要刪除角色「${name}」嗎?此操作無法復原。`)) {
|
||||
router.delete(route('roles.destroy', id), {
|
||||
@@ -34,17 +54,6 @@ export default function RoleIndex({ roles }: Props) {
|
||||
}
|
||||
};
|
||||
|
||||
const translateRoleName = (name: string) => {
|
||||
const map: Record<string, string> = {
|
||||
'super-admin': '超級管理員',
|
||||
'admin': '管理員',
|
||||
'warehouse-manager': '倉庫主管',
|
||||
'purchaser': '採購人員',
|
||||
'viewer': '檢視者',
|
||||
};
|
||||
return map[name] || name;
|
||||
}
|
||||
|
||||
return (
|
||||
<AuthenticatedLayout
|
||||
breadcrumbs={[
|
||||
@@ -65,12 +74,14 @@ export default function RoleIndex({ roles }: Props) {
|
||||
設定系統角色與功能存取權限
|
||||
</p>
|
||||
</div>
|
||||
<Link href={route('roles.create')}>
|
||||
<Button className="button-filled-primary">
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
新增角色
|
||||
</Button>
|
||||
</Link>
|
||||
<Can permission="roles.create">
|
||||
<Link href={route('roles.create')}>
|
||||
<Button className="button-filled-primary">
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
新增角色
|
||||
</Button>
|
||||
</Link>
|
||||
</Can>
|
||||
</div>
|
||||
|
||||
<div className="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden">
|
||||
@@ -94,7 +105,7 @@ export default function RoleIndex({ roles }: Props) {
|
||||
</TableCell>
|
||||
<TableCell className="font-medium">
|
||||
<div className="flex items-center gap-2">
|
||||
{translateRoleName(role.name)}
|
||||
{role.display_name}
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="text-gray-500 font-mono text-xs">
|
||||
@@ -106,10 +117,19 @@ export default function RoleIndex({ roles }: Props) {
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell className="text-center">
|
||||
<div className="flex items-center justify-center gap-1 text-gray-600">
|
||||
<Users className="h-3 w-3" />
|
||||
<button
|
||||
onClick={() => role.users_count > 0 && setSelectedRole(role)}
|
||||
className={cn(
|
||||
"flex items-center justify-center gap-1 w-full h-full py-2 rounded-md transition-colors",
|
||||
role.users_count > 0
|
||||
? "text-[#01ab83] hover:bg-[#01ab83]/10 font-bold"
|
||||
: "text-gray-400 cursor-default"
|
||||
)}
|
||||
title={role.users_count > 0 ? "點擊查看成員名單" : ""}
|
||||
>
|
||||
<Users className="h-3.5 w-3.5" />
|
||||
{role.users_count}
|
||||
</div>
|
||||
</button>
|
||||
</TableCell>
|
||||
<TableCell className="text-left text-gray-500 text-sm">
|
||||
{format(new Date(role.created_at), 'yyyy/MM/dd')}
|
||||
@@ -117,26 +137,30 @@ export default function RoleIndex({ roles }: Props) {
|
||||
<TableCell className="text-center">
|
||||
{role.name !== 'super-admin' && (
|
||||
<div className="flex items-center justify-center gap-2">
|
||||
<Link href={route('roles.edit', role.id)}>
|
||||
<Can permission="roles.edit">
|
||||
<Link href={route('roles.edit', role.id)}>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="button-outlined-primary"
|
||||
title="編輯"
|
||||
>
|
||||
<Pencil className="h-4 w-4" />
|
||||
</Button>
|
||||
</Link>
|
||||
</Can>
|
||||
<Can permission="roles.delete">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="button-outlined-primary"
|
||||
title="編輯"
|
||||
className="button-outlined-error"
|
||||
title="刪除"
|
||||
disabled={role.users_count > 0}
|
||||
onClick={() => handleDelete(role.id, role.display_name)}
|
||||
>
|
||||
<Pencil className="h-4 w-4" />
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</Link>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="button-outlined-error"
|
||||
title="刪除"
|
||||
disabled={role.users_count > 0}
|
||||
onClick={() => handleDelete(role.id, translateRoleName(role.name))}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</Can>
|
||||
</div>
|
||||
)}
|
||||
</TableCell>
|
||||
@@ -146,6 +170,54 @@ export default function RoleIndex({ roles }: Props) {
|
||||
</Table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 成員名單對話框 */}
|
||||
<Dialog open={!!selectedRole} onOpenChange={(open) => !open && setSelectedRole(null)}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
<Users className="h-5 w-5 text-[#01ab83]" />
|
||||
{selectedRole?.display_name} - 成員名單
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
目前共有 {selectedRole?.users_count} 位使用者具備此角色權限
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="max-h-[60vh] overflow-y-auto pr-2">
|
||||
{selectedRole?.users && selectedRole.users.length > 0 ? (
|
||||
<div className="space-y-3">
|
||||
{selectedRole.users.map((user) => (
|
||||
<div
|
||||
key={user.id}
|
||||
className="flex items-center justify-between p-3 rounded-lg border border-gray-100 bg-gray-50/50"
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="h-8 w-8 rounded-full bg-white border border-gray-200 flex items-center justify-center text-xs font-bold text-gray-500 shadow-sm">
|
||||
{user.name.charAt(0)}
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm font-semibold text-gray-900">{user.name}</p>
|
||||
<p className="text-xs text-gray-500 font-mono italic">@{user.username}</p>
|
||||
</div>
|
||||
</div>
|
||||
<Link
|
||||
href={route('users.edit', user.id)}
|
||||
className="text-xs text-[#01ab83] hover:underline font-medium"
|
||||
>
|
||||
查看帳號
|
||||
</Link>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-center py-8 text-gray-500 italic">
|
||||
暫無成員
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</AuthenticatedLayout>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { Checkbox } from '@/Components/ui/checkbox';
|
||||
import { FormEvent } from 'react';
|
||||
|
||||
interface Props {
|
||||
roles: Record<string, string>; // ID -> Name map from pluck
|
||||
roles: Record<string, string>; // Name (ID) -> DisplayName map from pluck
|
||||
}
|
||||
|
||||
export default function UserCreate({ roles }: Props) {
|
||||
@@ -34,16 +34,6 @@ export default function UserCreate({ roles }: Props) {
|
||||
}
|
||||
};
|
||||
|
||||
const translateRoleName = (name: string) => {
|
||||
const map: Record<string, string> = {
|
||||
'super-admin': '超級管理員',
|
||||
'admin': '管理員',
|
||||
'warehouse-manager': '倉庫主管',
|
||||
'purchaser': '採購人員',
|
||||
'viewer': '檢視者',
|
||||
};
|
||||
return map[name] || name;
|
||||
}
|
||||
|
||||
return (
|
||||
<AuthenticatedLayout
|
||||
@@ -55,29 +45,34 @@ export default function UserCreate({ roles }: Props) {
|
||||
>
|
||||
<Head title="新增使用者" />
|
||||
|
||||
<div className="p-8 max-w-4xl mx-auto">
|
||||
<form onSubmit={handleSubmit} className="space-y-8">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<Users className="h-6 w-6 text-[#01ab83]" />
|
||||
新增使用者
|
||||
</h1>
|
||||
<p className="text-gray-500 mt-1">
|
||||
建立新帳號並設定初始密碼與角色
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<Link href={route('users.index')}>
|
||||
<Button variant="outline" type="button">
|
||||
<ArrowLeft className="h-4 w-4 mr-2" />
|
||||
取消
|
||||
</Button>
|
||||
</Link>
|
||||
<div className="container mx-auto p-6 max-w-7xl">
|
||||
<form onSubmit={handleSubmit} className="space-y-6">
|
||||
{/* Header Area */}
|
||||
<div>
|
||||
<Link href={route('users.index')}>
|
||||
<Button
|
||||
variant="outline"
|
||||
type="button"
|
||||
className="gap-2 button-outlined-primary mb-2"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
返回使用者管理
|
||||
</Button>
|
||||
</Link>
|
||||
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<Users className="h-6 w-6 text-[#01ab83]" />
|
||||
新增使用者
|
||||
</h1>
|
||||
<p className="text-gray-500 mt-1">
|
||||
建立新帳號並設定初始密碼與角色
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
type="submit"
|
||||
className="bg-[#01ab83] hover:bg-[#019a76]"
|
||||
className="button-filled-primary"
|
||||
disabled={processing}
|
||||
>
|
||||
<Check className="h-4 w-4 mr-2" />
|
||||
@@ -170,22 +165,22 @@ export default function UserCreate({ roles }: Props) {
|
||||
<div className="bg-white p-6 rounded-xl border border-gray-200 shadow-sm h-full">
|
||||
<h3 className="font-bold text-gray-900 border-b pb-2 mb-4">角色分配</h3>
|
||||
<div className="space-y-4">
|
||||
{Object.entries(roles).map(([id, name]) => (
|
||||
<div key={id} className="flex items-start space-x-3 p-2 hover:bg-gray-50 rounded-lg transition-colors">
|
||||
{Object.entries(roles).map(([roleName, displayName]) => (
|
||||
<div key={roleName} className="flex items-start space-x-3 p-2 hover:bg-gray-50 rounded-lg transition-colors">
|
||||
<Checkbox
|
||||
id={`role-${id}`}
|
||||
checked={data.roles.includes(name)}
|
||||
onCheckedChange={() => toggleRole(name)}
|
||||
id={`role-${roleName}`}
|
||||
checked={data.roles.includes(roleName)}
|
||||
onCheckedChange={() => toggleRole(roleName)}
|
||||
/>
|
||||
<div className="grid gap-1.5 leading-none">
|
||||
<label
|
||||
htmlFor={`role-${id}`}
|
||||
htmlFor={`role-${roleName}`}
|
||||
className="text-sm font-medium leading-none cursor-pointer"
|
||||
>
|
||||
{translateRoleName(name)}
|
||||
{displayName}
|
||||
</label>
|
||||
<p className="text-xs text-gray-500 font-mono">
|
||||
{name}
|
||||
{roleName}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -10,6 +10,7 @@ import { FormEvent } from 'react';
|
||||
interface Role {
|
||||
id: number;
|
||||
name: string;
|
||||
display_name: string;
|
||||
}
|
||||
|
||||
interface UserData {
|
||||
@@ -48,16 +49,6 @@ export default function UserEdit({ user, roles, currentRoles }: Props) {
|
||||
}
|
||||
};
|
||||
|
||||
const translateRoleName = (name: string) => {
|
||||
const map: Record<string, string> = {
|
||||
'super-admin': '超級管理員',
|
||||
'admin': '管理員',
|
||||
'warehouse-manager': '倉庫主管',
|
||||
'purchaser': '採購人員',
|
||||
'viewer': '檢視者',
|
||||
};
|
||||
return map[name] || name;
|
||||
}
|
||||
|
||||
return (
|
||||
<AuthenticatedLayout
|
||||
@@ -69,29 +60,34 @@ export default function UserEdit({ user, roles, currentRoles }: Props) {
|
||||
>
|
||||
<Head title={`編輯使用者 - ${user.name}`} />
|
||||
|
||||
<div className="p-8 max-w-4xl mx-auto">
|
||||
<form onSubmit={handleSubmit} className="space-y-8">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<Users className="h-6 w-6 text-[#01ab83]" />
|
||||
編輯使用者
|
||||
</h1>
|
||||
<p className="text-gray-500 mt-1">
|
||||
修改使用者資料、重設密碼或變更角色
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<Link href={route('users.index')}>
|
||||
<Button variant="outline" type="button">
|
||||
<ArrowLeft className="h-4 w-4 mr-2" />
|
||||
取消
|
||||
</Button>
|
||||
</Link>
|
||||
<div className="container mx-auto p-6 max-w-7xl">
|
||||
<form onSubmit={handleSubmit} className="space-y-6">
|
||||
{/* Header Area */}
|
||||
<div>
|
||||
<Link href={route('users.index')}>
|
||||
<Button
|
||||
variant="outline"
|
||||
type="button"
|
||||
className="gap-2 button-outlined-primary mb-2"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
返回使用者管理
|
||||
</Button>
|
||||
</Link>
|
||||
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<Users className="h-6 w-6 text-[#01ab83]" />
|
||||
編輯使用者
|
||||
</h1>
|
||||
<p className="text-gray-500 mt-1">
|
||||
修改使用者資料、重設密碼或變更角色
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
type="submit"
|
||||
className="bg-[#01ab83] hover:bg-[#019a76]"
|
||||
className="button-filled-primary"
|
||||
disabled={processing}
|
||||
>
|
||||
<Check className="h-4 w-4 mr-2" />
|
||||
@@ -203,7 +199,7 @@ export default function UserEdit({ user, roles, currentRoles }: Props) {
|
||||
htmlFor={`role-${role.id}`}
|
||||
className="text-sm font-medium leading-none cursor-pointer"
|
||||
>
|
||||
{translateRoleName(role.name)}
|
||||
{role.display_name}
|
||||
</label>
|
||||
<p className="text-xs text-gray-500 font-mono">
|
||||
{role.name}
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
} from "@/Components/ui/table";
|
||||
import { format } from 'date-fns';
|
||||
import { toast } from 'sonner';
|
||||
import { Can } from '@/Components/Permission/Can';
|
||||
|
||||
interface Role {
|
||||
id: number;
|
||||
@@ -88,12 +89,14 @@ export default function UserIndex({ users }: Props) {
|
||||
管理系統使用者帳號與角色分配
|
||||
</p>
|
||||
</div>
|
||||
<Link href={route('users.create')}>
|
||||
<Button className="button-filled-primary">
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
新增使用者
|
||||
</Button>
|
||||
</Link>
|
||||
<Can permission="users.create">
|
||||
<Link href={route('users.create')}>
|
||||
<Button className="button-filled-primary">
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
新增使用者
|
||||
</Button>
|
||||
</Link>
|
||||
</Can>
|
||||
</div>
|
||||
|
||||
<div className="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden">
|
||||
@@ -151,25 +154,29 @@ export default function UserIndex({ users }: Props) {
|
||||
</TableCell>
|
||||
<TableCell className="text-center">
|
||||
<div className="flex items-center justify-center gap-2">
|
||||
<Link href={route('users.edit', user.id)}>
|
||||
<Can permission="users.edit">
|
||||
<Link href={route('users.edit', user.id)}>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="button-outlined-primary"
|
||||
title="編輯"
|
||||
>
|
||||
<Pencil className="h-4 w-4" />
|
||||
</Button>
|
||||
</Link>
|
||||
</Can>
|
||||
<Can permission="users.delete">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="button-outlined-primary"
|
||||
title="編輯"
|
||||
className="button-outlined-error"
|
||||
title="刪除"
|
||||
onClick={() => handleDelete(user.id, user.name)}
|
||||
>
|
||||
<Pencil className="h-4 w-4" />
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</Link>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="button-outlined-error"
|
||||
title="刪除"
|
||||
onClick={() => handleDelete(user.id, user.name)}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</Can>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
|
||||
@@ -79,8 +79,11 @@ export default function Dashboard({ stats }: Props) {
|
||||
|
||||
<div className="p-8 max-w-7xl mx-auto">
|
||||
<div className="mb-8">
|
||||
<h1 className="text-3xl font-bold text-grey-0 mb-2">系統總覽</h1>
|
||||
<p className="text-grey-2">歡迎回來,這是您的小小冰室 ERP 營運數據概況。</p>
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<TrendingUp className="h-6 w-6 text-[#01ab83]" />
|
||||
系統總覽
|
||||
</h1>
|
||||
<p className="text-gray-500 mt-1">歡迎回來,這是您的小小冰室 ERP 營運數據概況。</p>
|
||||
</div>
|
||||
|
||||
{/* 主要數據卡片 */}
|
||||
|
||||
36
resources/js/Pages/Error/403.tsx
Normal file
36
resources/js/Pages/Error/403.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import { Link } from "@inertiajs/react";
|
||||
import { ShieldAlert, Home } from "lucide-react";
|
||||
|
||||
export default function Error403() {
|
||||
return (
|
||||
<div className="min-h-screen bg-slate-50 flex flex-col items-center justify-center p-6">
|
||||
<div className="max-w-md w-full text-center">
|
||||
{/* 圖示 */}
|
||||
<div className="mb-6 flex justify-center">
|
||||
<div className="w-24 h-24 bg-red-100 rounded-full flex items-center justify-center">
|
||||
<ShieldAlert className="w-12 h-12 text-red-500" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 標題 */}
|
||||
<h1 className="text-3xl font-bold text-slate-900 mb-2">
|
||||
無此權限
|
||||
</h1>
|
||||
|
||||
{/* 說明 */}
|
||||
<p className="text-slate-600 mb-8">
|
||||
您沒有存取此頁面的權限,請洽系統管理員。
|
||||
</p>
|
||||
|
||||
{/* 返回按鈕 */}
|
||||
<Link
|
||||
href="/"
|
||||
className="inline-flex items-center gap-2 px-6 py-3 bg-primary-main text-white rounded-lg hover:bg-primary-dark transition-colors"
|
||||
>
|
||||
<Home className="w-5 h-5" />
|
||||
返回首頁
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import { Head, router } from "@inertiajs/react";
|
||||
import { debounce } from "lodash";
|
||||
import Pagination from "@/Components/shared/Pagination";
|
||||
import { getBreadcrumbs } from "@/utils/breadcrumb";
|
||||
import { Can } from "@/Components/Permission/Can";
|
||||
|
||||
export interface Category {
|
||||
id: number;
|
||||
@@ -217,26 +218,32 @@ export default function ProductManagement({ products, categories, units, filters
|
||||
className="w-full md:w-[180px]"
|
||||
/>
|
||||
|
||||
{/* Add Button */}
|
||||
{/* Action Buttons */}
|
||||
<div className="flex gap-2 w-full md:w-auto">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setIsCategoryDialogOpen(true)}
|
||||
className="flex-1 md:flex-none button-outlined-primary"
|
||||
>
|
||||
管理分類
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setIsUnitDialogOpen(true)}
|
||||
className="flex-1 md:flex-none button-outlined-primary"
|
||||
>
|
||||
管理單位
|
||||
</Button>
|
||||
<Button onClick={handleAddProduct} className="flex-1 md:flex-none button-filled-primary">
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
新增商品
|
||||
</Button>
|
||||
<Can permission="products.edit">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setIsCategoryDialogOpen(true)}
|
||||
className="flex-1 md:flex-none button-outlined-primary"
|
||||
>
|
||||
管理分類
|
||||
</Button>
|
||||
</Can>
|
||||
<Can permission="products.edit">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setIsUnitDialogOpen(true)}
|
||||
className="flex-1 md:flex-none button-outlined-primary"
|
||||
>
|
||||
管理單位
|
||||
</Button>
|
||||
</Can>
|
||||
<Can permission="products.create">
|
||||
<Button onClick={handleAddProduct} className="flex-1 md:flex-none button-filled-primary">
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
新增商品
|
||||
</Button>
|
||||
</Can>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* 建立/編輯採購單頁面
|
||||
*/
|
||||
|
||||
import { ArrowLeft, Plus, Info } from "lucide-react";
|
||||
import { ArrowLeft, Plus, Info, ShoppingCart } from "lucide-react";
|
||||
import { Button } from "@/Components/ui/button";
|
||||
import { Input } from "@/Components/ui/input";
|
||||
import { Textarea } from "@/Components/ui/textarea";
|
||||
@@ -173,8 +173,11 @@ export default function CreatePurchaseOrder({
|
||||
</Link>
|
||||
|
||||
<div className="mb-6">
|
||||
<h1 className="mb-2">{order ? "編輯採購單" : "建立採購單"}</h1>
|
||||
<p className="text-gray-600">
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<ShoppingCart className="h-6 w-6 text-[#01ab83]" />
|
||||
{order ? "編輯採購單" : "建立採購單"}
|
||||
</h1>
|
||||
<p className="text-gray-500 mt-1">
|
||||
{order ? `修改採購單 ${order.poNumber} 的詳細資訊` : "填寫新採購單的資訊以開始流程"}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -14,6 +14,7 @@ import type { PurchaseOrder } from "@/types/purchase-order";
|
||||
import { debounce } from "lodash";
|
||||
import Pagination from "@/Components/shared/Pagination";
|
||||
import { getBreadcrumbs } from "@/utils/breadcrumb";
|
||||
import { Can } from "@/Components/Permission/Can";
|
||||
|
||||
interface Props {
|
||||
orders: {
|
||||
@@ -101,13 +102,15 @@ export default function PurchaseOrderIndex({ orders, filters, warehouses }: Prop
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
onClick={handleNavigateToCreateOrder}
|
||||
className="gap-2 button-filled-primary"
|
||||
>
|
||||
<Plus className="h-4 w-4" />
|
||||
建立採購單
|
||||
</Button>
|
||||
<Can permission="purchase_orders.create">
|
||||
<Button
|
||||
onClick={handleNavigateToCreateOrder}
|
||||
className="gap-2 button-filled-primary"
|
||||
>
|
||||
<Plus className="h-4 w-4" />
|
||||
建立採購單
|
||||
</Button>
|
||||
</Can>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* 查看採購單詳情頁面
|
||||
*/
|
||||
|
||||
import { ArrowLeft } from "lucide-react";
|
||||
import { ArrowLeft, ShoppingCart } from "lucide-react";
|
||||
import { Button } from "@/Components/ui/button";
|
||||
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
|
||||
import { Head, Link } from "@inertiajs/react";
|
||||
@@ -37,8 +37,11 @@ export default function ViewPurchaseOrderPage({ order }: Props) {
|
||||
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<div>
|
||||
<h1 className="mb-2">查看採購單</h1>
|
||||
<p className="text-gray-600">單號:{order.poNumber}</p>
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<ShoppingCart className="h-6 w-6 text-[#01ab83]" />
|
||||
查看採購單
|
||||
</h1>
|
||||
<p className="text-gray-500 mt-1">單號:{order.poNumber}</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<Link href={`/purchase-orders/${order.id}/edit`}>
|
||||
|
||||
11
resources/js/Pages/Vendor/Index.tsx
vendored
11
resources/js/Pages/Vendor/Index.tsx
vendored
@@ -8,6 +8,7 @@ import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
|
||||
import { Head, router } from "@inertiajs/react";
|
||||
import { debounce } from "lodash";
|
||||
import { getBreadcrumbs } from "@/utils/breadcrumb";
|
||||
import { Can } from "@/Components/Permission/Can";
|
||||
|
||||
export interface Vendor {
|
||||
id: number;
|
||||
@@ -160,10 +161,12 @@ export default function VendorManagement({ vendors, filters }: PageProps) {
|
||||
</div>
|
||||
|
||||
{/* Add Button */}
|
||||
<Button onClick={handleAddVendor} className="flex-1 md:flex-none button-filled-primary">
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
新增廠商
|
||||
</Button>
|
||||
<Can permission="vendors.create">
|
||||
<Button onClick={handleAddVendor} className="flex-1 md:flex-none button-filled-primary">
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
新增廠商
|
||||
</Button>
|
||||
</Can>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
15
resources/js/Pages/Vendor/Show.tsx
vendored
15
resources/js/Pages/Vendor/Show.tsx
vendored
@@ -4,7 +4,7 @@
|
||||
|
||||
import { useState } from "react";
|
||||
import { Head, Link, router } from "@inertiajs/react";
|
||||
import { Phone, Mail, Plus, ArrowLeft } from "lucide-react";
|
||||
import { Phone, Mail, Plus, ArrowLeft, Contact2 } from "lucide-react";
|
||||
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
|
||||
import { Label } from "@/Components/ui/label";
|
||||
import { Button } from "@/Components/ui/button";
|
||||
@@ -140,10 +140,15 @@ export default function VendorShow({ vendor, products }: ShowProps) {
|
||||
返回廠商資料管理
|
||||
</Button>
|
||||
</Link>
|
||||
<h1 className="mb-2">廠商詳細資訊</h1>
|
||||
<p className="text-gray-600">
|
||||
查看並管理供應商的詳細資料與供貨商品
|
||||
</p>
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<Contact2 className="h-6 w-6 text-[#01ab83]" />
|
||||
廠商詳細資訊
|
||||
</h1>
|
||||
<p className="text-gray-500 mt-1">查看並管理供應商的詳細資料與供貨商品</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 基本資料 */}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
|
||||
import { useState } from "react";
|
||||
import { Plus, Trash2, Calendar, ArrowLeft, Save } from "lucide-react";
|
||||
import { Plus, Trash2, Calendar, ArrowLeft, Save, Boxes } from "lucide-react";
|
||||
import { Button } from "@/Components/ui/button";
|
||||
import { Input } from "@/Components/ui/input";
|
||||
import { Label } from "@/Components/ui/label";
|
||||
@@ -183,8 +183,11 @@ export default function AddInventoryPage({ warehouse, products }: Props) {
|
||||
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="mb-2">新增庫存(手動入庫)</h1>
|
||||
<p className="text-gray-600 font-medium">
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<Boxes className="h-6 w-6 text-[#01ab83]" />
|
||||
新增庫存(手動入庫)
|
||||
</h1>
|
||||
<p className="text-gray-500 mt-1">
|
||||
為 <span className="font-semibold text-gray-900">{warehouse.name}</span> 新增庫存記錄
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -5,7 +5,7 @@ import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
|
||||
import { Button } from "@/Components/ui/button";
|
||||
import { Input } from "@/Components/ui/input";
|
||||
import { Label } from "@/Components/ui/label";
|
||||
import { ArrowLeft, Save, Trash2 } from "lucide-react";
|
||||
import { ArrowLeft, Save, Trash2, Boxes } from "lucide-react";
|
||||
import { Warehouse, WarehouseInventory } from "@/types/warehouse";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
@@ -88,20 +88,13 @@ export default function EditInventory({ warehouse, inventory, transactions = []
|
||||
</Button>
|
||||
</Link >
|
||||
|
||||
<div className="flex items-center gap-2 text-sm text-gray-500 mb-2">
|
||||
<span>商品與庫存管理</span>
|
||||
<span>/</span>
|
||||
<span>倉庫管理</span>
|
||||
<span>/</span>
|
||||
<span>庫存管理</span>
|
||||
<span>/</span>
|
||||
<span className="text-gray-900">編輯庫存品項</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="mb-2">編輯庫存品項</h1>
|
||||
<p className="text-gray-600">
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<Boxes className="h-6 w-6 text-[#01ab83]" />
|
||||
編輯庫存品項
|
||||
</h1>
|
||||
<p className="text-gray-500 mt-1">
|
||||
倉庫:<span className="font-medium text-gray-900">{warehouse.name}</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -12,6 +12,7 @@ import { Warehouse } from "@/types/warehouse";
|
||||
import Pagination from "@/Components/shared/Pagination";
|
||||
import { toast } from "sonner";
|
||||
import { getBreadcrumbs } from "@/utils/breadcrumb";
|
||||
import { Can } from "@/Components/Permission/Can";
|
||||
|
||||
interface PageProps {
|
||||
warehouses: {
|
||||
@@ -133,20 +134,24 @@ export default function WarehouseIndex({ warehouses, filters }: PageProps) {
|
||||
|
||||
{/* 操作按鈕 */}
|
||||
<div className="flex gap-2 w-full md:w-auto">
|
||||
<Button
|
||||
onClick={handleAddTransferOrder}
|
||||
className="flex-1 md:flex-initial button-outlined-primary"
|
||||
>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
新增撥補單
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleAddWarehouse}
|
||||
className="flex-1 md:flex-initial button-filled-primary"
|
||||
>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
新增倉庫
|
||||
</Button>
|
||||
<Can permission="inventory.transfer">
|
||||
<Button
|
||||
onClick={handleAddTransferOrder}
|
||||
className="flex-1 md:flex-initial button-outlined-primary"
|
||||
>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
新增撥補單
|
||||
</Button>
|
||||
</Can>
|
||||
<Can permission="warehouses.create">
|
||||
<Button
|
||||
onClick={handleAddWarehouse}
|
||||
className="flex-1 md:flex-initial button-filled-primary"
|
||||
>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
新增倉庫
|
||||
</Button>
|
||||
</Can>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useState, useMemo } from "react";
|
||||
import { ArrowLeft, PackagePlus, AlertTriangle, Shield } from "lucide-react";
|
||||
import { ArrowLeft, PackagePlus, AlertTriangle, Shield, Boxes } from "lucide-react";
|
||||
import { Button } from "@/Components/ui/button";
|
||||
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
|
||||
import { Head, Link, router } from "@inertiajs/react";
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/Components/ui/alert-dialog";
|
||||
import { Can } from "@/Components/Permission/Can";
|
||||
|
||||
// 庫存頁面 Props
|
||||
interface Props {
|
||||
@@ -107,8 +108,11 @@ export default function WarehouseInventoryPage({
|
||||
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="mb-2">庫存管理 - {warehouse.name}</h1>
|
||||
<p className="text-gray-600 font-medium">查看並管理此倉庫內的商品庫存數量與批號資訊</p>
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<Boxes className="h-6 w-6 text-[#01ab83]" />
|
||||
庫存管理 - {warehouse.name}
|
||||
</h1>
|
||||
<p className="text-gray-500 mt-1">查看並管理此倉庫內的商品庫存數量與批號資訊</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -116,15 +120,17 @@ export default function WarehouseInventoryPage({
|
||||
{/* 操作按鈕 (位於標題下方) */}
|
||||
<div className="flex items-center gap-3 mb-6">
|
||||
{/* 安全庫存設定按鈕 */}
|
||||
<Link href={route('warehouses.safety-stock.index', warehouse.id)}>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="button-outlined-primary"
|
||||
>
|
||||
<Shield className="mr-2 h-4 w-4" />
|
||||
安全庫存設定
|
||||
</Button>
|
||||
</Link>
|
||||
<Can permission="inventory.safety_stock">
|
||||
<Link href={route('warehouses.safety-stock.index', warehouse.id)}>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="button-outlined-primary"
|
||||
>
|
||||
<Shield className="mr-2 h-4 w-4" />
|
||||
安全庫存設定
|
||||
</Button>
|
||||
</Link>
|
||||
</Can>
|
||||
|
||||
{/* 庫存警告顯示 */}
|
||||
<Button
|
||||
@@ -139,14 +145,16 @@ export default function WarehouseInventoryPage({
|
||||
</Button>
|
||||
|
||||
{/* 新增庫存按鈕 */}
|
||||
<Link href={route('warehouses.inventory.create', warehouse.id)}>
|
||||
<Button
|
||||
className="button-filled-primary"
|
||||
>
|
||||
<PackagePlus className="mr-2 h-4 w-4" />
|
||||
新增庫存
|
||||
</Button>
|
||||
</Link>
|
||||
<Can permission="inventory.adjust">
|
||||
<Link href={route('warehouses.inventory.create', warehouse.id)}>
|
||||
<Button
|
||||
className="button-filled-primary"
|
||||
>
|
||||
<PackagePlus className="mr-2 h-4 w-4" />
|
||||
新增庫存
|
||||
</Button>
|
||||
</Link>
|
||||
</Can>
|
||||
</div>
|
||||
|
||||
{/* 篩選工具列 */}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Head, Link } from "@inertiajs/react";
|
||||
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
|
||||
import { Button } from "@/Components/ui/button";
|
||||
import { ArrowLeft } from "lucide-react";
|
||||
import { ArrowLeft, History } from "lucide-react";
|
||||
import { Warehouse } from "@/types/warehouse";
|
||||
import TransactionTable, { Transaction } from "@/Components/Warehouse/Inventory/TransactionTable";
|
||||
import { getInventoryBreadcrumbs } from "@/utils/breadcrumb";
|
||||
@@ -21,7 +21,7 @@ export default function InventoryHistory({ warehouse, inventory, transactions }:
|
||||
return (
|
||||
<AuthenticatedLayout breadcrumbs={getInventoryBreadcrumbs(warehouse.id, warehouse.name, "庫存變動紀錄")}>
|
||||
<Head title={`庫存異動紀錄 - ${inventory.productName}`} />
|
||||
<div className="container mx-auto p-6 max-w-4xl">
|
||||
<div className="container mx-auto p-6 max-w-7xl">
|
||||
{/* Header */}
|
||||
<div className="mb-6">
|
||||
<Link href={`/warehouses/${warehouse.id}/inventory`}>
|
||||
@@ -34,18 +34,13 @@ export default function InventoryHistory({ warehouse, inventory, transactions }:
|
||||
</Button>
|
||||
</Link>
|
||||
|
||||
<div className="flex items-center gap-2 text-sm text-gray-500 mb-2">
|
||||
<span>倉庫管理</span>
|
||||
<span>/</span>
|
||||
<span>庫存管理</span>
|
||||
<span>/</span>
|
||||
<span className="text-gray-900">庫存異動紀錄</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="mb-2">庫存異動紀錄</h1>
|
||||
<p className="text-gray-600">
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<History className="h-6 w-6 text-[#01ab83]" />
|
||||
庫存異動紀錄
|
||||
</h1>
|
||||
<p className="text-gray-500 mt-1">
|
||||
商品:<span className="font-medium text-gray-900">{inventory.productName}</span>
|
||||
{inventory.productCode && <span className="text-gray-500 ml-2">({inventory.productCode})</span>}
|
||||
</p>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { ArrowLeft, Plus } from "lucide-react";
|
||||
import { ArrowLeft, Plus, Shield } from "lucide-react";
|
||||
import { Button } from "@/Components/ui/button";
|
||||
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
|
||||
import { Head, Link, router } from "@inertiajs/react";
|
||||
@@ -14,6 +14,17 @@ import AddSafetyStockDialog from "@/Components/Warehouse/SafetyStock/AddSafetySt
|
||||
import EditSafetyStockDialog from "@/Components/Warehouse/SafetyStock/EditSafetyStockDialog";
|
||||
import { toast } from "sonner";
|
||||
import { getInventoryBreadcrumbs } from "@/utils/breadcrumb";
|
||||
import { Can } from "@/Components/Permission/Can";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/Components/ui/alert-dialog";
|
||||
|
||||
interface Props {
|
||||
warehouse: Warehouse;
|
||||
@@ -31,6 +42,7 @@ export default function SafetyStockPage({
|
||||
const [settings, setSettings] = useState<SafetyStockSetting[]>(initialSettings);
|
||||
const [showAddDialog, setShowAddDialog] = useState(false);
|
||||
const [editingSetting, setEditingSetting] = useState<SafetyStockSetting | null>(null);
|
||||
const [deleteId, setDeleteId] = useState<string | null>(null);
|
||||
|
||||
|
||||
// 當 Props 更新時同步本地 State
|
||||
@@ -71,10 +83,16 @@ export default function SafetyStockPage({
|
||||
});
|
||||
};
|
||||
|
||||
const handleDelete = (id: string) => {
|
||||
router.delete(route('warehouses.safety-stock.destroy', [warehouse.id, id]), {
|
||||
const handleDelete = () => {
|
||||
if (!deleteId) return;
|
||||
|
||||
router.delete(route('warehouses.safety-stock.destroy', [warehouse.id, deleteId]), {
|
||||
onSuccess: () => {
|
||||
setDeleteId(null);
|
||||
toast.success("已刪除安全庫存設定");
|
||||
},
|
||||
onError: () => {
|
||||
toast.error("刪除失敗");
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -101,18 +119,23 @@ export default function SafetyStockPage({
|
||||
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="mb-2">安全庫存設定 - {warehouse.name}</h1>
|
||||
<p className="text-gray-600 font-medium">
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<Shield className="h-6 w-6 text-[#01ab83]" />
|
||||
安全庫存設定 - {warehouse.name}
|
||||
</h1>
|
||||
<p className="text-gray-500 mt-1">
|
||||
設定商品的安全庫存量,當庫存低於安全值時將發出警告
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
onClick={() => setShowAddDialog(true)}
|
||||
className="button-filled-primary"
|
||||
>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
新增安全庫存
|
||||
</Button>
|
||||
<Can permission="inventory.safety_stock">
|
||||
<Button
|
||||
onClick={() => setShowAddDialog(true)}
|
||||
className="button-filled-primary"
|
||||
>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
新增安全庫存
|
||||
</Button>
|
||||
</Can>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -121,7 +144,7 @@ export default function SafetyStockPage({
|
||||
settings={settings}
|
||||
inventories={inventories}
|
||||
onEdit={setEditingSetting}
|
||||
onDelete={handleDelete}
|
||||
onDelete={setDeleteId}
|
||||
/>
|
||||
|
||||
{/* 新增對話框 */}
|
||||
@@ -143,6 +166,27 @@ export default function SafetyStockPage({
|
||||
onSave={handleEdit}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 刪除確認對話框 */}
|
||||
<AlertDialog open={!!deleteId} onOpenChange={(open) => !open && setDeleteId(null)}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>確認刪除安全庫存設定</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
您確定要刪除此項商品的安全庫存設定嗎?刪除後系統將不再針對此商品發出庫存不足警告。此動作無法復原。
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel className="button-outlined-primary">取消</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleDelete}
|
||||
className="bg-red-600 hover:bg-red-700 text-white"
|
||||
>
|
||||
確認刪除
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</AuthenticatedLayout>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user