feat(ui): standardize collapsible filters and date selection UI
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Successful in 50s
Koori-ERP-Deploy-System / deploy-production (push) Has been skipped

This commit is contained in:
2026-01-20 14:03:59 +08:00
parent daae429cd4
commit 74728c47b9
6 changed files with 517 additions and 222 deletions

View File

@@ -775,6 +775,38 @@ import { Input } from "@/Components/ui/input";
/> />
``` ```
## 11.8 篩選列規範 (Filter Bar Norms)
列表頁面的篩選區域Filter Bar應遵循以下規範以節省空間並保持層級清晰
1. **標籤文字 (Labels)**: 使用 **`text-xs`** (`12px`) 大小,顏色建議使用 `text-gray-500``text-grey-2`。這與一般表單 (`text-sm`) 不同,目的是降低篩選列的視覺權重。
2. **輸入元件高度**: 統一使用 **`h-9`** (`36px`)。
3. **佈局**:
- **容器內距**: 統一使用 **`p-5`** (`20px`)。
- **Grid 間距**: 建議使用 **`gap-4`** (`16px`) 或 `gap-6` (`24px`),但同一專案內需統一。本專案推薦 **`gap-4`**。
- **垂直間距**: Label 與 Input 之間使用 **`space-y-1`** (`4px`)。
- **排版**: 建議使用 Grid 系統 (`grid-cols-12`) 進行排版。
```tsx
<div className="space-y-1">
<Label className="text-xs font-medium text-grey-2">關鍵字搜尋</Label>
<Input className="h-9" placeholder="..." />
</div>
```
4. **操作按鈕區 (Action Bar)**:
- **位置**: 位於篩選列最下方。
- **樣式**: 統一使用 `flex items-center justify-end border-t border-grey-4 pt-5 gap-3`
- **說明**: `border-grey-4` 為標準通用邊框色,`pt-5` 與容器 padding (`p-5`) 呼應,維持視覺平衡。
5. **收合模式 (Collapsible Mode)**:
- **目的**: 節省垂直空間,預設隱藏較佔空間與低頻使用的篩選器(如日期區間)。
- **實作**:
- 預設狀態:若無相關篩選值,則預設為 **收合 (Collapsed)**
- 切換按鈕:位於 Action Bar 左側 (`mr-auto`)。
- 樣式Ghost Button + `ChevronDown`/`ChevronUp` Icon + 提示圓點 (Indicator)。
- **邏輯**: 若載入頁面時已有被隱藏的篩選值 (e.g. `date_start`),則強制 **展開 (Expanded)** 或顯示提示。
--- ---
## 12. 檢查清單 ## 12. 檢查清單

View File

@@ -42,7 +42,7 @@ class UtilityFeeController extends Controller
if ($sortField && $sortDirection) { if ($sortField && $sortDirection) {
$query->orderBy($sortField, $sortDirection); $query->orderBy($sortField, $sortDirection);
} else { } else {
$query->orderBy('transaction_date', 'desc'); $query->orderBy('created_at', 'desc');
} }
$fees = $query->paginate($request->input('per_page', 15))->withQueryString(); $fees = $query->paginate($request->input('per_page', 15))->withQueryString();

View File

@@ -4,13 +4,14 @@ import { Head, router } from '@inertiajs/react';
import { PageProps } from '@/types/global'; import { PageProps } from '@/types/global';
import Pagination from '@/Components/shared/Pagination'; import Pagination from '@/Components/shared/Pagination';
import { SearchableSelect } from "@/Components/ui/searchable-select"; import { SearchableSelect } from "@/Components/ui/searchable-select";
import { FileText, Search, RotateCcw, Calendar } from 'lucide-react'; import { FileText, Search, RotateCcw, Calendar, ChevronDown, ChevronUp } from 'lucide-react';
import LogTable, { Activity } from '@/Components/ActivityLog/LogTable'; import LogTable, { Activity } from '@/Components/ActivityLog/LogTable';
import ActivityDetailDialog from '@/Components/ActivityLog/ActivityDetailDialog'; import ActivityDetailDialog from '@/Components/ActivityLog/ActivityDetailDialog';
import { Button } from '@/Components/ui/button'; import { Button } from '@/Components/ui/button';
import { Input } from '@/Components/ui/input'; import { Input } from '@/Components/ui/input';
import { Label } from '@/Components/ui/label'; import { Label } from '@/Components/ui/label';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/Components/ui/select"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/Components/ui/select";
import { getDateRange } from "@/utils/format";
interface PaginationLinks { interface PaginationLinks {
url: string | null; url: string | null;
@@ -54,6 +55,21 @@ export default function ActivityLogIndex({ activities, filters, subject_types, u
const [event, setEvent] = useState(filters.event || 'all'); const [event, setEvent] = useState(filters.event || 'all');
const [subjectType, setSubjectType] = useState(filters.subject_type || 'all'); const [subjectType, setSubjectType] = useState(filters.subject_type || 'all');
const [causer, setCauser] = useState(filters.causer_id || 'all'); const [causer, setCauser] = useState(filters.causer_id || 'all');
const [dateRangeType, setDateRangeType] = useState('custom');
// Advanced Filter Toggle
const [showAdvancedFilter, setShowAdvancedFilter] = useState(
!!(filters.date_start || filters.date_end)
);
const handleDateRangeChange = (type: string) => {
setDateRangeType(type);
if (type === 'custom') return;
const { start, end } = getDateRange(type);
setDateStart(start);
setDateEnd(end);
};
const handleFilter = () => { const handleFilter = () => {
router.get( router.get(
@@ -79,6 +95,7 @@ export default function ActivityLogIndex({ activities, filters, subject_types, u
setEvent('all'); setEvent('all');
setSubjectType('all'); setSubjectType('all');
setCauser('all'); setCauser('all');
setDateRangeType('custom');
router.get( router.get(
route('activity-logs.index'), route('activity-logs.index'),
@@ -144,44 +161,29 @@ export default function ActivityLogIndex({ activities, filters, subject_types, u
</div> </div>
{/* 篩選區塊 */} {/* 篩選區塊 */}
<div className="bg-white p-5 rounded-lg shadow-sm border border-gray-200 mb-6"> <div className="bg-white p-5 rounded-lg shadow-sm border border-grey-4 mb-6">
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 mb-4"> <div className="grid grid-cols-1 md:grid-cols-12 gap-4 mb-4">
{/* 關鍵字搜尋 */} {/* 關鍵字搜尋 */}
<div className="space-y-1"> <div className="md:col-span-4 space-y-1">
<Label className="text-xs text-gray-500"></Label> <Label className="text-xs font-medium text-grey-1"></Label>
<div className="relative"> <div className="relative">
<Search className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" /> <Search className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400" />
<Input <Input
placeholder="搜尋描述、內容..." placeholder="搜尋描述、內容..."
value={search} value={search}
onChange={(e) => setSearch(e.target.value)} onChange={(e) => setSearch(e.target.value)}
className="pl-9" className="pl-10 h-9 block"
onKeyDown={(e) => e.key === 'Enter' && handleFilter()} onKeyDown={(e) => e.key === 'Enter' && handleFilter()}
/> />
</div> </div>
</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"> <div className="md:col-span-2 space-y-1">
<Label className="text-xs text-gray-500"></Label> <Label className="text-xs font-medium text-grey-1"></Label>
<Select value={event} onValueChange={setEvent}> <Select value={event} onValueChange={setEvent}>
<SelectTrigger> <SelectTrigger className="h-9">
<SelectValue placeholder="選擇事件類型" /> <SelectValue placeholder="所有事件" />
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
<SelectItem value="all"></SelectItem> <SelectItem value="all"></SelectItem>
@@ -193,8 +195,8 @@ export default function ActivityLogIndex({ activities, filters, subject_types, u
</div> </div>
{/* 操作對象 */} {/* 操作對象 */}
<div className="space-y-1"> <div className="md:col-span-3 space-y-1">
<Label className="text-xs text-gray-500"></Label> <Label className="text-xs font-medium text-grey-1"></Label>
<SearchableSelect <SearchableSelect
value={subjectType} value={subjectType}
onValueChange={setSubjectType} onValueChange={setSubjectType}
@@ -202,55 +204,128 @@ export default function ActivityLogIndex({ activities, filters, subject_types, u
{ label: "所有對象", value: "all" }, { label: "所有對象", value: "all" },
...subject_types ...subject_types
]} ]}
placeholder="選擇操作對象" placeholder="選擇對象"
className="w-full" className="w-full h-9"
/> />
</div> </div>
{/* 日期範圍 - 開始 */} {/* 操作人員 */}
<div className="space-y-1"> <div className="md:col-span-3 space-y-1">
<Label className="text-xs text-gray-500"></Label> <Label className="text-xs font-medium text-grey-1"></Label>
<div className="relative"> <SearchableSelect
<Calendar className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" /> value={causer}
<Input onValueChange={setCauser}
type="date" options={[
value={dateStart} { label: "所有人員", value: "all" },
onChange={(e) => setDateStart(e.target.value)} ...users
className="pl-9 block w-full" ]}
/> placeholder="選擇人員"
</div> className="w-full h-9"
</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> </div>
<div className="flex items-center justify-end gap-3 pt-2 border-t border-gray-100"> {/* Row 2: Date Filters (Collapsible) */}
{showAdvancedFilter && (
<div className="grid grid-cols-1 md:grid-cols-12 gap-4 items-end animate-in fade-in slide-in-from-top-2 duration-200">
<div className="md:col-span-6 space-y-2">
<Label className="text-xs font-medium text-grey-1"></Label>
<div className="flex flex-wrap gap-2">
{[
{ label: "今日", value: "today" },
{ label: "昨日", value: "yesterday" },
{ label: "本週", value: "this_week" },
{ label: "本月", value: "this_month" },
{ label: "上月", value: "last_month" },
].map((opt) => (
<Button
key={opt.value}
size="sm"
onClick={() => handleDateRangeChange(opt.value)}
className={
dateRangeType === opt.value
? 'button-filled-primary h-9 px-4 shadow-sm'
: 'button-outlined-primary h-9 px-4 bg-white'
}
>
{opt.label}
</Button>
))}
</div>
</div>
<div className="md:col-span-6">
<div className="grid grid-cols-2 gap-4 items-end">
<div className="space-y-1">
<Label className="text-xs font-medium text-grey-2"></Label>
<div className="relative">
<Calendar className="absolute left-2.5 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400 pointer-events-none" />
<Input
type="date"
value={dateStart}
onChange={(e) => {
setDateStart(e.target.value);
setDateRangeType('custom');
}}
// block w-full to ensure it fills space
className="pl-9 block w-full h-9 bg-white"
/>
</div>
</div>
<div className="space-y-1">
<Label className="text-xs font-medium text-grey-2"></Label>
<div className="relative">
<Calendar className="absolute left-2.5 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400 pointer-events-none" />
<Input
type="date"
value={dateEnd}
onChange={(e) => {
setDateEnd(e.target.value);
setDateRangeType('custom');
}}
className="pl-9 block w-full h-9 bg-white"
/>
</div>
</div>
</div>
</div>
</div>
)}
{/* Action Bar */}
<div className="flex items-center justify-end border-t border-grey-4 pt-5 gap-3 mt-4">
<Button
variant="ghost"
size="sm"
onClick={() => setShowAdvancedFilter(!showAdvancedFilter)}
className="mr-auto text-gray-500 hover:text-gray-900 h-9"
>
{showAdvancedFilter ? (
<>
<ChevronUp className="h-4 w-4 mr-1" />
</>
) : (
<>
<ChevronDown className="h-4 w-4 mr-1" />
{(dateStart || dateEnd) && (
<span className="ml-2 w-2 h-2 rounded-full bg-primary-main" />
)}
</>
)}
</Button>
<Button <Button
variant="outline" variant="outline"
onClick={handleReset} onClick={handleReset}
className="flex items-center gap-2 button-outlined-primary" className="flex items-center gap-2 button-outlined-primary h-9"
> >
<RotateCcw className="h-4 w-4" /> <RotateCcw className="h-4 w-4" />
</Button> </Button>
<Button <Button onClick={handleFilter} className="button-filled-primary h-9 px-6 gap-2">
onClick={handleFilter}
className="flex items-center gap-2 button-filled-primary"
>
<Search className="h-4 w-4" /> <Search className="h-4 w-4" />
</Button> </Button>
</div> </div>
</div> </div>
@@ -264,32 +339,21 @@ export default function ActivityLogIndex({ activities, filters, subject_types, u
from={activities.from} from={activities.from}
/> />
<div className="mt-4 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4"> <div className="mt-6">
<div className="flex items-center gap-2 text-sm text-gray-500"> <Pagination
<span></span> links={activities.links}
<SearchableSelect total={activities.total}
value={perPage} current_page={activities.current_page}
onValueChange={handlePerPageChange} last_page={activities.last_page}
options={[ per_page={perPage}
{ label: "10", value: "10" }, onPerPageChange={handlePerPageChange}
{ label: "20", value: "20" }, />
{ label: "50", value: "50" },
{ label: "100", value: "100" }
]}
className="w-[100px] h-8"
showSearch={false}
/>
<span></span>
</div>
<div className="w-full sm:w-auto flex justify-center sm:justify-end">
<Pagination links={activities.links} />
</div>
</div> </div>
</div> </div>
<ActivityDetailDialog <ActivityDetailDialog
open={detailOpen} isOpen={detailOpen}
onOpenChange={setDetailOpen} onClose={() => setDetailOpen(false)}
activity={selectedActivity} activity={selectedActivity}
/> />
</AuthenticatedLayout> </AuthenticatedLayout>

View File

@@ -3,7 +3,7 @@
*/ */
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import { Plus, ShoppingCart, Search, RotateCcw, Calendar } from 'lucide-react'; import { Plus, ShoppingCart, Search, RotateCcw, Calendar, ChevronDown, ChevronUp } from 'lucide-react';
import { Button } from "@/Components/ui/button"; import { Button } from "@/Components/ui/button";
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout"; import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
import { Head, router } from "@inertiajs/react"; import { Head, router } from "@inertiajs/react";
@@ -11,6 +11,7 @@ import PurchaseOrderTable from "@/Components/PurchaseOrder/PurchaseOrderTable";
import type { PurchaseOrder } from "@/types/purchase-order"; import type { PurchaseOrder } from "@/types/purchase-order";
import Pagination from "@/Components/shared/Pagination"; import Pagination from "@/Components/shared/Pagination";
import { getBreadcrumbs } from "@/utils/breadcrumb"; import { getBreadcrumbs } from "@/utils/breadcrumb";
import { getDateRange } from "@/utils/format";
import { Can } from "@/Components/Permission/Can"; import { Can } from "@/Components/Permission/Can";
import { SearchableSelect } from "@/Components/ui/searchable-select"; import { SearchableSelect } from "@/Components/ui/searchable-select";
import { Input } from "@/Components/ui/input"; import { Input } from "@/Components/ui/input";
@@ -52,6 +53,12 @@ export default function PurchaseOrderIndex({ orders, filters, warehouses }: Prop
const [dateStart, setDateStart] = useState(filters.date_start || ""); const [dateStart, setDateStart] = useState(filters.date_start || "");
const [dateEnd, setDateEnd] = useState(filters.date_end || ""); const [dateEnd, setDateEnd] = useState(filters.date_end || "");
const [perPage, setPerPage] = useState<string>(filters.per_page || "10"); const [perPage, setPerPage] = useState<string>(filters.per_page || "10");
const [dateRangeType, setDateRangeType] = useState('custom');
// Advanced Filter Toggle
const [showAdvancedFilter, setShowAdvancedFilter] = useState(
!!(filters.date_start || filters.date_end)
);
// 同步 URL 參數到 State (雖有初始值,但若由外部連結進入可確保同步) // 同步 URL 參數到 State (雖有初始值,但若由外部連結進入可確保同步)
useEffect(() => { useEffect(() => {
@@ -86,10 +93,20 @@ export default function PurchaseOrderIndex({ orders, filters, warehouses }: Prop
setWarehouseId("all"); setWarehouseId("all");
setDateStart(""); setDateStart("");
setDateEnd(""); setDateEnd("");
setDateRangeType("custom");
router.get(route('purchase-orders.index')); router.get(route('purchase-orders.index'));
}; };
const handleDateRangeChange = (type: string) => {
setDateRangeType(type);
if (type === 'custom') return;
const { start, end } = getDateRange(type);
setDateStart(start);
setDateEnd(end);
};
const handlePerPageChange = (value: string) => { const handlePerPageChange = (value: string) => {
setPerPage(value); setPerPage(value);
router.get( router.get(
@@ -135,27 +152,26 @@ export default function PurchaseOrderIndex({ orders, filters, warehouses }: Prop
{/* 篩選區塊 */} {/* 篩選區塊 */}
<div className="bg-white p-5 rounded-lg shadow-sm border border-gray-200 mb-6"> <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"> {/* Row 1: Search, Status, Warehouse */}
{/* 關鍵字搜尋 */} <div className="grid grid-cols-1 md:grid-cols-12 gap-4 mb-4">
<div className="space-y-1"> <div className="md:col-span-4 space-y-1">
<Label className="text-xs text-gray-500"></Label> <Label className="text-xs font-medium text-grey-1"></Label>
<div className="relative"> <div className="relative">
<Search className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" /> <Search className="absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 h-4 w-4" />
<Input <Input
placeholder="搜尋採購單號、廠商..." placeholder="搜尋採購單號、廠商..."
value={search} value={search}
onChange={(e) => setSearch(e.target.value)} onChange={(e) => setSearch(e.target.value)}
className="pl-9" className="pl-10 h-9 block"
onKeyDown={(e) => e.key === 'Enter' && handleFilter()} onKeyDown={(e) => e.key === 'Enter' && handleFilter()}
/> />
</div> </div>
</div> </div>
{/* 狀態篩選 */} <div className="md:col-span-4 space-y-1">
<div className="space-y-1"> <Label className="text-xs font-medium text-grey-1"></Label>
<Label className="text-xs text-gray-500"></Label>
<Select value={status} onValueChange={setStatus}> <Select value={status} onValueChange={setStatus}>
<SelectTrigger> <SelectTrigger className="h-9">
<SelectValue placeholder="選擇狀態" /> <SelectValue placeholder="選擇狀態" />
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
@@ -171,9 +187,8 @@ export default function PurchaseOrderIndex({ orders, filters, warehouses }: Prop
</Select> </Select>
</div> </div>
{/* 倉庫篩選 */} <div className="md:col-span-4 space-y-1">
<div className="space-y-1"> <Label className="text-xs font-medium text-grey-1"></Label>
<Label className="text-xs text-gray-500"></Label>
<SearchableSelect <SearchableSelect
value={warehouseId} value={warehouseId}
onValueChange={setWarehouseId} onValueChange={setWarehouseId}
@@ -182,54 +197,113 @@ export default function PurchaseOrderIndex({ orders, filters, warehouses }: Prop
...warehouses.map(w => ({ label: w.name, value: String(w.id) })) ...warehouses.map(w => ({ label: w.name, value: String(w.id) }))
]} ]}
placeholder="選擇倉庫" placeholder="選擇倉庫"
className="w-full" className="w-full h-9"
/> />
</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={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>
<div className="flex items-center justify-end gap-3 pt-2 border-t border-gray-100"> {/* Row 2: Date Filters (Collapsible) */}
{showAdvancedFilter && (
<div className="grid grid-cols-1 md:grid-cols-12 gap-4 items-end animate-in fade-in slide-in-from-top-2 duration-200">
<div className="md:col-span-6 space-y-2">
<Label className="text-xs font-medium text-grey-1"></Label>
<div className="flex flex-wrap gap-2">
{[
{ label: "今日", value: "today" },
{ label: "昨日", value: "yesterday" },
{ label: "本週", value: "this_week" },
{ label: "本月", value: "this_month" },
{ label: "上月", value: "last_month" },
].map((opt) => (
<Button
key={opt.value}
size="sm"
onClick={() => handleDateRangeChange(opt.value)}
className={
dateRangeType === opt.value
? 'button-filled-primary h-9 px-4 shadow-sm'
: 'button-outlined-primary h-9 px-4 bg-white'
}
>
{opt.label}
</Button>
))}
</div>
</div>
<div className="md:col-span-6">
<div className="grid grid-cols-2 gap-4 items-end">
<div className="space-y-1">
<Label className="text-xs text-grey-2 font-medium"></Label>
<div className="relative">
<Calendar className="absolute left-2.5 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400 pointer-events-none" />
<Input
type="date"
value={dateStart}
onChange={(e) => {
setDateStart(e.target.value);
setDateRangeType('custom');
}}
className="pl-9 block w-full h-9 bg-white"
/>
</div>
</div>
<div className="space-y-1">
<Label className="text-xs text-grey-2 font-medium"></Label>
<div className="relative">
<Calendar className="absolute left-2.5 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400 pointer-events-none" />
<Input
type="date"
value={dateEnd}
onChange={(e) => {
setDateEnd(e.target.value);
setDateRangeType('custom');
}}
className="pl-9 block w-full h-9 bg-white text-left"
/>
</div>
</div>
</div>
</div>
</div>
)}
<div className="flex items-center justify-end border-t border-grey-4 pt-5 gap-3 mt-4">
<Button
variant="ghost"
size="sm"
onClick={() => setShowAdvancedFilter(!showAdvancedFilter)}
className="mr-auto text-gray-500 hover:text-gray-900 h-9"
>
{showAdvancedFilter ? (
<>
<ChevronUp className="h-4 w-4 mr-1" />
</>
) : (
<>
<ChevronDown className="h-4 w-4 mr-1" />
{(dateStart || dateEnd) && (
<span className="ml-2 w-2 h-2 rounded-full bg-primary-main" />
)}
</>
)}
</Button>
<Button <Button
variant="outline" variant="outline"
onClick={handleReset} onClick={handleReset}
className="flex items-center gap-2 button-outlined-primary" className="flex items-center gap-2 button-outlined-primary h-9"
> >
<RotateCcw className="h-4 w-4" /> <RotateCcw className="h-4 w-4" />
</Button> </Button>
<Button <Button
onClick={handleFilter} onClick={handleFilter}
className="flex items-center gap-2 button-filled-primary" className="flex items-center gap-2 button-filled-primary h-9 px-6"
> >
<Search className="h-4 w-4" /> <Search className="h-4 w-4" />
</Button> </Button>
</div> </div>
</div> </div>

View File

@@ -10,10 +10,12 @@ import {
Trash2, Trash2,
FileText, FileText,
Calendar, Calendar,
Filter, RotateCcw,
ArrowUpDown, ArrowUpDown,
ArrowUp, ArrowUp,
ArrowDown ArrowDown,
ChevronDown,
ChevronUp
} from 'lucide-react'; } from 'lucide-react';
import { Label } from "@/Components/ui/label"; import { Label } from "@/Components/ui/label";
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout"; import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
@@ -41,7 +43,7 @@ import {
AlertDialogTitle, AlertDialogTitle,
} from "@/Components/ui/alert-dialog"; } from "@/Components/ui/alert-dialog";
import { Can } from "@/Components/Permission/Can"; import { Can } from "@/Components/Permission/Can";
import { formatDateWithDayOfWeek, formatInvoiceNumber } from "@/utils/format"; import { formatDateWithDayOfWeek, formatInvoiceNumber, getDateRange } from "@/utils/format";
interface PageProps { interface PageProps {
fees: { fees: {
@@ -71,15 +73,30 @@ export default function UtilityFeeIndex({ fees, availableCategories, filters }:
const [categoryFilter, setCategoryFilter] = useState<string>(filters.category || "all"); const [categoryFilter, setCategoryFilter] = useState<string>(filters.category || "all");
const [dateStart, setDateStart] = useState(filters.date_start || ""); const [dateStart, setDateStart] = useState(filters.date_start || "");
const [dateEnd, setDateEnd] = useState(filters.date_end || ""); const [dateEnd, setDateEnd] = useState(filters.date_end || "");
const [dateRangeType, setDateRangeType] = useState("custom");
const [isDialogOpen, setIsDialogOpen] = useState(false); const [isDialogOpen, setIsDialogOpen] = useState(false);
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false); const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false);
const [editingFee, setEditingFee] = useState<UtilityFee | null>(null); const [editingFee, setEditingFee] = useState<UtilityFee | null>(null);
const [deletingFeeId, setDeletingFeeId] = useState<number | null>(null); const [deletingFeeId, setDeletingFeeId] = useState<number | null>(null);
// Advanced Filter Toggle
const [showAdvancedFilter, setShowAdvancedFilter] = useState(
!!(filters.date_start || filters.date_end)
);
// Sorting // Sorting
const [sortField, setSortField] = useState<string | null>(filters.sort_field || 'transaction_date'); const [sortField, setSortField] = useState<string | null>(filters.sort_field || null);
const [sortDirection, setSortDirection] = useState<"asc" | "desc" | null>(filters.sort_direction as "asc" | "desc" || 'desc'); const [sortDirection, setSortDirection] = useState<"asc" | "desc" | null>(filters.sort_direction as "asc" | "desc" || null);
const handleDateRangeChange = (type: string) => {
setDateRangeType(type);
if (type === "custom") return;
const { start, end } = getDateRange(type);
setDateStart(start);
setDateEnd(end);
};
const handleSearch = () => { const handleSearch = () => {
router.get( router.get(
@@ -101,6 +118,7 @@ export default function UtilityFeeIndex({ fees, availableCategories, filters }:
setCategoryFilter("all"); setCategoryFilter("all");
setDateStart(""); setDateStart("");
setDateEnd(""); setDateEnd("");
setDateRangeType("custom");
router.get(route("utility-fees.index")); router.get(route("utility-fees.index"));
}; };
@@ -197,91 +215,150 @@ export default function UtilityFeeIndex({ fees, availableCategories, filters }:
</Can> </Can>
</div> </div>
{/* Toolbar */} <div className="bg-white rounded-xl shadow-sm border border-grey-4 p-5 mb-6">
<div className="bg-white rounded-lg shadow-sm border p-4 mb-6"> <div className="flex flex-col gap-4">
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4"> {/* Row 1: Search and Category */}
{/* Search */} <div className="grid grid-cols-1 md:grid-cols-12 gap-4">
<div className="space-y-1"> <div className="md:col-span-8 space-y-1">
<Label className="text-xs text-gray-500"></Label> <Label className="text-xs font-medium text-grey-1"></Label>
<div className="relative"> <div className="relative">
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 h-4 w-4" /> <Search className="absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 h-4 w-4" />
<Input <Input
placeholder="搜尋發票備註..." placeholder="搜尋發票號碼、說明或備註..."
value={searchTerm} value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)} onChange={(e) => setSearchTerm(e.target.value)}
onKeyDown={(e) => e.key === "Enter" && handleSearch()} onKeyDown={(e) => e.key === "Enter" && handleSearch()}
className="pl-10" className="pl-10 h-9 block"
/>
{searchTerm && (
<button
onClick={() => setSearchTerm("")}
className="absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-400 hover:text-gray-600 transition-colors"
>
<X className="h-4 w-4" />
</button>
)}
</div>
</div>
<div className="md:col-span-4 space-y-1">
<Label className="text-xs font-medium text-grey-1"></Label>
<SearchableSelect
value={categoryFilter}
onValueChange={setCategoryFilter}
options={[
{ label: "所有類別", value: "all" },
...availableCategories.map(c => ({ label: c, value: c }))
]}
placeholder="篩選類別"
className="h-9"
/> />
{searchTerm && ( </div>
<button </div>
onClick={() => setSearchTerm("")}
className="absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-400 hover:text-gray-600" {/* Row 2: Date Filters (Collapsible) */}
> {showAdvancedFilter && (
<X className="h-4 w-4" /> <div className="grid grid-cols-1 md:grid-cols-12 gap-4 items-end animate-in fade-in slide-in-from-top-2 duration-200">
</button> <div className="md:col-span-6 space-y-2">
<Label className="text-xs font-medium text-grey-1"></Label>
<div className="flex flex-wrap gap-2">
{[
{ label: "今日", value: "today" },
{ label: "昨日", value: "yesterday" },
{ label: "本週", value: "this_week" },
{ label: "本月", value: "this_month" },
{ label: "上月", value: "last_month" },
].map((opt) => (
<Button
key={opt.value}
size="sm"
onClick={() => handleDateRangeChange(opt.value)}
className={
dateRangeType === opt.value
? 'button-filled-primary h-9 px-4 shadow-sm'
: 'button-outlined-primary h-9 px-4 bg-white'
}
>
{opt.label}
</Button>
))}
</div>
</div>
<div className="md:col-span-6">
<div className="grid grid-cols-2 gap-4 items-end">
<div className="space-y-1">
<Label className="text-xs text-grey-2 font-medium"></Label>
<div className="relative">
<Calendar className="absolute left-2.5 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400 pointer-events-none" />
<Input
type="date"
value={dateStart}
onChange={(e) => {
setDateStart(e.target.value);
setDateRangeType('custom');
}}
className="pl-9 block w-full h-9 bg-white"
/>
</div>
</div>
<div className="space-y-1">
<Label className="text-xs text-grey-2 font-medium"></Label>
<div className="relative">
<Calendar className="absolute left-2.5 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400 pointer-events-none" />
<Input
type="date"
value={dateEnd}
onChange={(e) => {
setDateEnd(e.target.value);
setDateRangeType('custom');
}}
className="pl-9 block w-full h-9 bg-white"
/>
</div>
</div>
</div>
</div>
</div>
)}
{/* Action Buttons */}
<div className="flex items-center justify-end border-t border-grey-4 pt-5 gap-3">
<Button
variant="ghost"
size="sm"
onClick={() => setShowAdvancedFilter(!showAdvancedFilter)}
className="mr-auto text-gray-500 hover:text-gray-900 h-9"
>
{showAdvancedFilter ? (
<>
<ChevronUp className="h-4 w-4 mr-1" />
</>
) : (
<>
<ChevronDown className="h-4 w-4 mr-1" />
{(dateStart || dateEnd) && (
<span className="ml-2 w-2 h-2 rounded-full bg-primary-main" />
)}
</>
)} )}
</div> </Button>
<Button
variant="outline"
onClick={handleClearFilters}
className="flex items-center gap-2 button-outlined-primary h-9"
>
<RotateCcw className="h-4 w-4" />
</Button>
<Button
onClick={handleSearch}
className="button-filled-primary h-9 px-6 gap-2"
>
<Search className="h-4 w-4" />
</Button>
</div> </div>
{/* Date Range Start */}
<div className="space-y-1">
<Label className="text-xs text-gray-500"></Label>
<div className="relative">
<Calendar className="absolute left-2.5 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400 pointer-events-none" />
<Input
type="date"
value={dateStart}
onChange={(e) => setDateStart(e.target.value)}
className="pl-9 bg-white block w-full"
placeholder="開始日期"
/>
</div>
</div>
{/* Date Range End */}
<div className="space-y-1">
<Label className="text-xs text-gray-500"></Label>
<div className="relative">
<Calendar className="absolute left-2.5 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400 pointer-events-none" />
<Input
type="date"
value={dateEnd}
onChange={(e) => setDateEnd(e.target.value)}
className="pl-9 bg-white block w-full"
placeholder="結束日期"
/>
</div>
</div>
{/* Category Filter */}
<div className="space-y-1">
<Label className="text-xs text-gray-500"></Label>
<SearchableSelect
value={categoryFilter}
onValueChange={setCategoryFilter}
options={[
{ label: "所有類別", value: "all" },
...availableCategories.map(c => ({ label: c, value: c }))
]}
placeholder="篩選類別"
/>
</div>
</div>
<div className="mt-4 flex justify-end gap-2">
<Button
variant="outline"
onClick={handleClearFilters}
className="button-outlined-primary h-9 mt-auto"
>
</Button>
<Button
onClick={handleSearch}
className="button-filled-primary h-9 gap-2 mt-auto"
>
<Filter className="h-4 w-4" />
</Button>
</div> </div>
</div> </div>

View File

@@ -135,3 +135,51 @@ export const formatDateTime = (datetime: string): string => {
hour12: false, hour12: false,
}); });
}; };
/**
* 獲取日期區間YYYY-MM-DD 格式)
* 支援: today, yesterday, this_week, this_month, last_month
*/
export const getDateRange = (type: string): { start: string, end: string } => {
const now = new Date();
// Reset time to avoid timezone issues when calculating dates
now.setHours(12, 0, 0, 0);
let start = new Date(now);
let end = new Date(now);
const format = (d: Date) => {
const year = d.getFullYear();
const month = String(d.getMonth() + 1).padStart(2, "0");
const day = String(d.getDate()).padStart(2, "0");
return `${year}-${month}-${day}`;
};
switch (type) {
case "today":
break;
case "yesterday":
start.setDate(now.getDate() - 1);
end.setDate(now.getDate() - 1);
break;
case "this_week":
// 週一為一週的第一天
const dayOfWeek = now.getDay() || 7;
start.setDate(now.getDate() - dayOfWeek + 1);
end.setDate(now.getDate() + (7 - dayOfWeek));
break;
case "this_month":
start = new Date(now.getFullYear(), now.getMonth(), 1);
end = new Date(now.getFullYear(), now.getMonth() + 1, 0);
break;
case "last_month":
start = new Date(now.getFullYear(), now.getMonth() - 1, 1);
end = new Date(now.getFullYear(), now.getMonth(), 0);
break;
}
return {
start: format(start),
end: format(end)
};
};