feat: 統一採購單與操作紀錄 UI、增強各模組操作紀錄功能
- 統一採購單篩選列與表單樣式 (移除舊元件、標準化 Input) - 增強操作紀錄功能 (加入篩選、快照、詳細異動比對) - 統一刪除確認視窗與按鈕樣式 - 修復庫存編輯頁面樣式 - 實作採購單品項異動紀錄 - 實作角色分配異動紀錄 - 擴充供應商與倉庫模組紀錄
This commit is contained in:
@@ -4,9 +4,13 @@ import { Head, router } from '@inertiajs/react';
|
||||
import { PageProps } from '@/types/global';
|
||||
import Pagination from '@/Components/shared/Pagination';
|
||||
import { SearchableSelect } from "@/Components/ui/searchable-select";
|
||||
import { FileText } from 'lucide-react';
|
||||
import { FileText, Search, RotateCcw, Calendar } from 'lucide-react';
|
||||
import LogTable, { Activity } from '@/Components/ActivityLog/LogTable';
|
||||
import ActivityDetailDialog from '@/Components/ActivityLog/ActivityDetailDialog';
|
||||
import { Button } from '@/Components/ui/button';
|
||||
import { Input } from '@/Components/ui/input';
|
||||
import { Label } from '@/Components/ui/label';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/Components/ui/select";
|
||||
|
||||
interface PaginationLinks {
|
||||
url: string | null;
|
||||
@@ -27,14 +31,62 @@ interface Props extends PageProps {
|
||||
per_page?: string;
|
||||
sort_by?: string;
|
||||
sort_order?: 'asc' | 'desc';
|
||||
search?: string;
|
||||
date_start?: string;
|
||||
date_end?: string;
|
||||
event?: string;
|
||||
subject_type?: string;
|
||||
causer_id?: string;
|
||||
};
|
||||
subject_types: { label: string; value: string }[];
|
||||
users: { label: string; value: string }[];
|
||||
}
|
||||
|
||||
export default function ActivityLogIndex({ activities, filters }: Props) {
|
||||
export default function ActivityLogIndex({ activities, filters, subject_types, users }: Props) {
|
||||
const [perPage, setPerPage] = useState<string>(filters.per_page || "10");
|
||||
const [selectedActivity, setSelectedActivity] = useState<Activity | null>(null);
|
||||
const [detailOpen, setDetailOpen] = useState(false);
|
||||
|
||||
// Filter States
|
||||
const [search, setSearch] = useState(filters.search || '');
|
||||
const [dateStart, setDateStart] = useState(filters.date_start || '');
|
||||
const [dateEnd, setDateEnd] = useState(filters.date_end || '');
|
||||
const [event, setEvent] = useState(filters.event || 'all');
|
||||
const [subjectType, setSubjectType] = useState(filters.subject_type || 'all');
|
||||
const [causer, setCauser] = useState(filters.causer_id || 'all');
|
||||
|
||||
const handleFilter = () => {
|
||||
router.get(
|
||||
route('activity-logs.index'),
|
||||
{
|
||||
...filters,
|
||||
search: search,
|
||||
date_start: dateStart,
|
||||
date_end: dateEnd,
|
||||
event: event === 'all' ? undefined : event,
|
||||
subject_type: subjectType === 'all' ? undefined : subjectType,
|
||||
causer_id: causer === 'all' ? undefined : causer,
|
||||
page: 1 // Reset to first page on filter
|
||||
},
|
||||
{ preserveState: true, replace: true }
|
||||
);
|
||||
};
|
||||
|
||||
const handleReset = () => {
|
||||
setSearch('');
|
||||
setDateStart('');
|
||||
setDateEnd('');
|
||||
setEvent('all');
|
||||
setSubjectType('all');
|
||||
setCauser('all');
|
||||
|
||||
router.get(
|
||||
route('activity-logs.index'),
|
||||
{ per_page: perPage, sort_by: filters.sort_by, sort_order: filters.sort_order },
|
||||
{ preserveState: true, replace: true }
|
||||
);
|
||||
};
|
||||
|
||||
const handleViewDetail = (activity: Activity) => {
|
||||
setSelectedActivity(activity);
|
||||
setDetailOpen(true);
|
||||
@@ -91,6 +143,118 @@ export default function ActivityLogIndex({ activities, filters }: Props) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 篩選區塊 */}
|
||||
<div className="bg-white p-5 rounded-lg shadow-sm border border-gray-200 mb-6">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 mb-4">
|
||||
{/* 關鍵字搜尋 */}
|
||||
<div className="space-y-1">
|
||||
<Label className="text-xs text-gray-500">關鍵字搜尋</Label>
|
||||
<div className="relative">
|
||||
<Search className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" />
|
||||
<Input
|
||||
placeholder="搜尋描述、內容..."
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
className="pl-9"
|
||||
onKeyDown={(e) => e.key === 'Enter' && handleFilter()}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 操作人員 */}
|
||||
<div className="space-y-1">
|
||||
<Label className="text-xs text-gray-500">操作人員</Label>
|
||||
<SearchableSelect
|
||||
value={causer}
|
||||
onValueChange={setCauser}
|
||||
options={[
|
||||
{ label: "所有人員", value: "all" },
|
||||
...users
|
||||
]}
|
||||
placeholder="選擇操作人員"
|
||||
className="w-full"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 事件類型 */}
|
||||
<div className="space-y-1">
|
||||
<Label className="text-xs text-gray-500">事件類型</Label>
|
||||
<Select value={event} onValueChange={setEvent}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="選擇事件類型" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">所有事件</SelectItem>
|
||||
<SelectItem value="created">新增 (Created)</SelectItem>
|
||||
<SelectItem value="updated">更新 (Updated)</SelectItem>
|
||||
<SelectItem value="deleted">刪除 (Deleted)</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{/* 操作對象 */}
|
||||
<div className="space-y-1">
|
||||
<Label className="text-xs text-gray-500">操作對象</Label>
|
||||
<SearchableSelect
|
||||
value={subjectType}
|
||||
onValueChange={setSubjectType}
|
||||
options={[
|
||||
{ label: "所有對象", value: "all" },
|
||||
...subject_types
|
||||
]}
|
||||
placeholder="選擇操作對象"
|
||||
className="w-full"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 日期範圍 - 開始 */}
|
||||
<div className="space-y-1">
|
||||
<Label className="text-xs text-gray-500">開始日期</Label>
|
||||
<div className="relative">
|
||||
<Calendar className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" />
|
||||
<Input
|
||||
type="date"
|
||||
value={dateStart}
|
||||
onChange={(e) => setDateStart(e.target.value)}
|
||||
className="pl-9 block w-full"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 日期範圍 - 結束 */}
|
||||
<div className="space-y-1">
|
||||
<Label className="text-xs text-gray-500">結束日期</Label>
|
||||
<div className="relative">
|
||||
<Calendar className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" />
|
||||
<Input
|
||||
type="date"
|
||||
value={dateEnd}
|
||||
onChange={(e) => setDateEnd(e.target.value)}
|
||||
className="pl-9 block w-full text-left"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-end gap-3 pt-2 border-t border-gray-100">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={handleReset}
|
||||
className="flex items-center gap-2 button-outlined-primary"
|
||||
>
|
||||
<RotateCcw className="h-4 w-4" />
|
||||
重置條件
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleFilter}
|
||||
className="flex items-center gap-2 button-filled-primary"
|
||||
>
|
||||
<Search className="h-4 w-4" />
|
||||
查詢紀錄
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<LogTable
|
||||
activities={activities.data}
|
||||
sortField={filters.sort_by}
|
||||
@@ -100,7 +264,7 @@ export default function ActivityLogIndex({ activities, filters }: Props) {
|
||||
from={activities.from}
|
||||
/>
|
||||
|
||||
<div className="mt-4 flex flex-col sm:flex-row items-center justify-between gap-4">
|
||||
<div className="mt-4 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
|
||||
<div className="flex items-center gap-2 text-sm text-gray-500">
|
||||
<span>每頁顯示</span>
|
||||
<SearchableSelect
|
||||
@@ -112,12 +276,14 @@ export default function ActivityLogIndex({ activities, filters }: Props) {
|
||||
{ label: "50", value: "50" },
|
||||
{ label: "100", value: "100" }
|
||||
]}
|
||||
className="w-[80px] h-8"
|
||||
className="w-[100px] h-8"
|
||||
showSearch={false}
|
||||
/>
|
||||
<span>筆</span>
|
||||
</div>
|
||||
<Pagination links={activities.links} />
|
||||
<div className="w-full sm:w-auto flex justify-center sm:justify-end">
|
||||
<Pagination links={activities.links} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import {
|
||||
TableRow,
|
||||
} from "@/Components/ui/table";
|
||||
import { format } from 'date-fns';
|
||||
import { toast } from 'sonner';
|
||||
import { Can } from '@/Components/Permission/Can';
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
@@ -23,6 +22,16 @@ import {
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/Components/ui/dialog";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/Components/ui/alert-dialog";
|
||||
|
||||
interface User {
|
||||
id: number;
|
||||
@@ -50,11 +59,23 @@ interface Props {
|
||||
|
||||
export default function RoleIndex({ roles, filters = {} }: Props) {
|
||||
const [selectedRole, setSelectedRole] = useState<Role | null>(null);
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null);
|
||||
const [deleteName, setDeleteName] = useState<string>('');
|
||||
const [modelOpen, setModelOpen] = useState(false);
|
||||
|
||||
const handleDelete = (id: number, name: string) => {
|
||||
if (confirm(`確定要刪除角色「${name}」嗎?此操作無法復原。`)) {
|
||||
router.delete(route('roles.destroy', id), {
|
||||
onSuccess: () => toast.success('角色已刪除'),
|
||||
const confirmDelete = (id: number, name: string) => {
|
||||
setDeleteId(id);
|
||||
setDeleteName(name);
|
||||
setModelOpen(true);
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
if (deleteId) {
|
||||
router.delete(route('roles.destroy', deleteId), {
|
||||
onSuccess: () => {
|
||||
setModelOpen(false);
|
||||
},
|
||||
onFinish: () => setModelOpen(false),
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -212,7 +233,7 @@ export default function RoleIndex({ roles, filters = {} }: Props) {
|
||||
className="button-outlined-error"
|
||||
title="刪除"
|
||||
disabled={role.users_count > 0}
|
||||
onClick={() => handleDelete(role.id, role.display_name)}
|
||||
onClick={() => confirmDelete(role.id, role.display_name)}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
@@ -274,6 +295,23 @@ export default function RoleIndex({ roles, filters = {} }: Props) {
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
<AlertDialog open={modelOpen} onOpenChange={setModelOpen}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>確定要刪除此角色嗎?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
您即將刪除角色「{deleteName}」。此操作無法復原,請確認是否繼續。
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||
<AlertDialogAction onClick={handleDelete} className="button-filled-error">
|
||||
確認刪除
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</AuthenticatedLayout>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,11 +12,20 @@ import {
|
||||
TableRow,
|
||||
} from "@/Components/ui/table";
|
||||
import { format } from 'date-fns';
|
||||
import { toast } from 'sonner';
|
||||
import { Can } from '@/Components/Permission/Can';
|
||||
import { cn } from "@/lib/utils";
|
||||
import Pagination from "@/Components/shared/Pagination";
|
||||
import { SearchableSelect } from "@/Components/ui/searchable-select";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/Components/ui/alert-dialog";
|
||||
|
||||
interface Role {
|
||||
id: number;
|
||||
@@ -54,12 +63,23 @@ interface Props {
|
||||
|
||||
export default function UserIndex({ users, filters }: Props) {
|
||||
const [perPage, setPerPage] = useState<string>(filters.per_page || "10");
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null);
|
||||
const [deleteName, setDeleteName] = useState<string>('');
|
||||
const [modelOpen, setModelOpen] = useState(false);
|
||||
|
||||
const handleDelete = (id: number, name: string) => {
|
||||
if (confirm(`確定要刪除使用者「${name}」嗎?此操作無法復原。`)) {
|
||||
router.delete(route('users.destroy', id), {
|
||||
onSuccess: () => toast.success('使用者已刪除'),
|
||||
onError: () => toast.error('刪除失敗,請檢查權限'),
|
||||
const confirmDelete = (id: number, name: string) => {
|
||||
setDeleteId(id);
|
||||
setDeleteName(name);
|
||||
setModelOpen(true);
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
if (deleteId) {
|
||||
router.delete(route('users.destroy', deleteId), {
|
||||
onSuccess: () => {
|
||||
setModelOpen(false);
|
||||
},
|
||||
onFinish: () => setModelOpen(false),
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -229,7 +249,7 @@ export default function UserIndex({ users, filters }: Props) {
|
||||
size="sm"
|
||||
className="button-outlined-error"
|
||||
title="刪除"
|
||||
onClick={() => handleDelete(user.id, user.name)}
|
||||
onClick={() => confirmDelete(user.id, user.name)}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
@@ -243,7 +263,7 @@ export default function UserIndex({ users, filters }: Props) {
|
||||
</div>
|
||||
|
||||
{/* 分頁元件 - 統一樣式 */}
|
||||
<div className="mt-4 flex flex-col sm:flex-row items-center justify-between gap-4">
|
||||
<div className="mt-4 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
|
||||
<div className="flex items-center gap-2 text-sm text-gray-500">
|
||||
<span>每頁顯示</span>
|
||||
<SearchableSelect
|
||||
@@ -255,14 +275,33 @@ export default function UserIndex({ users, filters }: Props) {
|
||||
{ label: "50", value: "50" },
|
||||
{ label: "100", value: "100" }
|
||||
]}
|
||||
className="w-[80px] h-8"
|
||||
className="w-[100px] h-8"
|
||||
showSearch={false}
|
||||
/>
|
||||
<span>筆</span>
|
||||
</div>
|
||||
<Pagination links={users.links} />
|
||||
<div className="w-full sm:w-auto flex justify-center sm:justify-end">
|
||||
<Pagination links={users.links} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AuthenticatedLayout>
|
||||
|
||||
<AlertDialog open={modelOpen} onOpenChange={setModelOpen}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>確定要刪除此使用者嗎?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
您即將刪除使用者「{deleteName}」。此操作無法復原,請確認是否繼續。
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||
<AlertDialogAction onClick={handleDelete} className="button-filled-error">
|
||||
確認刪除
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</AuthenticatedLayout >
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user