first commit

This commit is contained in:
2025-12-30 15:03:19 +08:00
commit c735c36009
902 changed files with 83591 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
/**
* 庫存篩選 Hook
* 處理庫存項目的搜尋和類型篩選邏輯
*/
import { useMemo } from "react";
import { WarehouseInventory } from "../types/warehouse";
import { AVAILABLE_PRODUCTS } from "../constants/products";
export const useInventoryFilter = (
items: WarehouseInventory[],
searchTerm: string,
typeFilter: string
) => {
return useMemo(() => {
return items.filter((item) => {
const matchesSearch =
item.productName.toLowerCase().includes(searchTerm.toLowerCase()) ||
item.batchNumber.toLowerCase().includes(searchTerm.toLowerCase());
// 根據類型篩選
let matchesType = true;
if (typeFilter !== "all") {
const product = AVAILABLE_PRODUCTS.find((p) => p.id === item.productId);
matchesType = product?.type === typeFilter;
}
return matchesSearch && matchesType;
});
}, [items, searchTerm, typeFilter]);
};

View File

@@ -0,0 +1,52 @@
/**
* 庫存表單 Hook
* 處理新增庫存項目的表單狀態和邏輯
*/
import { useState } from "react";
import { WarehouseInventory } from "../types/warehouse";
export interface InventoryFormData {
productId: string;
batchNumber: string;
quantity: number;
expiryDate: string;
safetyStock: number;
lastInboundDate: string;
lastOutboundDate: string;
}
const initialFormData: InventoryFormData = {
productId: "",
batchNumber: "",
quantity: 0,
expiryDate: "",
safetyStock: 0,
lastInboundDate: "",
lastOutboundDate: "",
};
export const useInventoryForm = () => {
const [formData, setFormData] = useState<InventoryFormData>(initialFormData);
const resetForm = (defaultProductId?: string) => {
setFormData({
...initialFormData,
productId: defaultProductId || "",
});
};
const updateField = <K extends keyof InventoryFormData>(
field: K,
value: InventoryFormData[K]
) => {
setFormData((prev) => ({ ...prev, [field]: value }));
};
return {
formData,
setFormData,
resetForm,
updateField,
};
};

View File

@@ -0,0 +1,23 @@
/**
* 倉庫篩選 Hook
* 處理倉庫的搜尋和類別篩選邏輯
*/
import { useMemo } from "react";
import { Warehouse } from "../types/warehouse";
export const useWarehouseFilter = (
warehouses: Warehouse[],
searchTerm: string,
typeFilter: string
) => {
return useMemo(() => {
return warehouses.filter((warehouse) => {
const matchesSearch = warehouse.name
.toLowerCase()
.includes(searchTerm.toLowerCase());
const matchesType = typeFilter === "all" || warehouse.type === typeFilter;
return matchesSearch && matchesType;
});
}, [warehouses, searchTerm, typeFilter]);
};