first commit
This commit is contained in:
31
source-code/ERP(A-b)-倉庫管理/src/hooks/useInventoryFilter.ts
Normal file
31
source-code/ERP(A-b)-倉庫管理/src/hooks/useInventoryFilter.ts
Normal 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]);
|
||||
};
|
||||
Binary file not shown.
52
source-code/ERP(A-b)-倉庫管理/src/hooks/useInventoryForm.ts
Normal file
52
source-code/ERP(A-b)-倉庫管理/src/hooks/useInventoryForm.ts
Normal 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,
|
||||
};
|
||||
};
|
||||
Binary file not shown.
23
source-code/ERP(A-b)-倉庫管理/src/hooks/useWarehouseFilter.ts
Normal file
23
source-code/ERP(A-b)-倉庫管理/src/hooks/useWarehouseFilter.ts
Normal 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]);
|
||||
};
|
||||
Binary file not shown.
Reference in New Issue
Block a user