refactor: rename InventoryItemStatus to InventoryStatus and update related types

This commit is contained in:
Pattadon 2025-04-03 11:05:36 +07:00
parent f8390f1ee5
commit 80d6897f3b
6 changed files with 2856 additions and 3596 deletions

View File

@ -1,7 +1,7 @@
import axiosInstance from "./config"; import axiosInstance from "./config";
import type { import type {
InventoryItem, InventoryItem,
InventoryItemStatus, InventoryStatus,
InventoryItemCategory, InventoryItemCategory,
CreateInventoryItemInput, CreateInventoryItemInput,
UpdateInventoryItemInput, UpdateInventoryItemInput,
@ -14,9 +14,9 @@ import type {
* *
* *
*/ */
export async function fetchInventoryStatus(): Promise<InventoryItemStatus[]> { export async function fetchInventoryStatus(): Promise<InventoryStatus[]> {
try { try {
const response = await axiosInstance.get<InventoryItemStatus[]>( const response = await axiosInstance.get<InventoryStatus[]>(
"/inventory/status" "/inventory/status"
); );
return response.data; return response.data;
@ -44,56 +44,9 @@ export async function fetchInventoryItems(): Promise<InventoryItem[]> {
const response = await axiosInstance.get<InventoryItem[]>("/inventory"); const response = await axiosInstance.get<InventoryItem[]>("/inventory");
return response.data; return response.data;
} catch (error) { } catch (error) {
// console.error("Error while fetching inventory items! " + error); console.error("Error while fetching inventory items! " + error);
// throw error; throw error;
// Fallback dummy data
return [
{
id: "1",
name: "Tomato Seeds",
categoryId: "1",
quantity: 500,
unitId: "1",
lastUpdated: "2023-03-01",
statusId: "1",
},
{
id: "2",
name: "NPK Fertilizer",
categoryId: "3",
quantity: 200,
unitId: "2",
lastUpdated: "2023-03-05",
statusId: "2",
},
{
id: "3",
name: "Corn Seeds",
categoryId: "1",
quantity: 300,
unitId: "1",
lastUpdated: "2023-03-10",
statusId: "3",
},
{
id: "4",
name: "Organic Compost",
categoryId: "3",
quantity: 150,
unitId: "2",
lastUpdated: "2023-03-15",
statusId: "1",
},
{
id: "5",
name: "Wheat Seeds",
categoryId: "1",
quantity: 250,
unitId: "2",
lastUpdated: "2023-03-20",
statusId: "2",
},
];
} }
} }

View File

@ -36,14 +36,14 @@ import { cn } from "@/lib/utils";
import { createInventoryItem } from "@/api/inventory"; import { createInventoryItem } from "@/api/inventory";
import type { import type {
CreateInventoryItemInput, CreateInventoryItemInput,
InventoryItemStatus, InventoryStatus,
InventoryItemCategory, InventoryItemCategory,
HarvestUnits, HarvestUnits,
} from "@/types"; } from "@/types";
interface AddInventoryItemProps { interface AddInventoryItemProps {
inventoryCategory: InventoryItemCategory[]; inventoryCategory: InventoryItemCategory[];
inventoryStatus: InventoryItemStatus[]; inventoryStatus: InventoryStatus[];
harvestUnits: HarvestUnits[]; harvestUnits: HarvestUnits[];
} }

View File

@ -27,11 +27,7 @@ import {
SelectTrigger, SelectTrigger,
SelectValue, SelectValue,
} from "@/components/ui/select"; } from "@/components/ui/select";
import { import { InventoryStatus, InventoryItemCategory, HarvestUnits } from "@/types";
InventoryItemStatus,
InventoryItemCategory,
HarvestUnits,
} from "@/types";
import { updateInventoryItem } from "@/api/inventory"; import { updateInventoryItem } from "@/api/inventory";
import type { UpdateInventoryItemInput } from "@/types"; import type { UpdateInventoryItemInput } from "@/types";
@ -42,7 +38,7 @@ export interface EditInventoryItemProps {
statusId: string; statusId: string;
unitId: string; unitId: string;
quantity: number; quantity: number;
fetchedInventoryStatus: InventoryItemStatus[]; fetchedInventoryStatus: InventoryStatus[];
fetchedInventoryCategory: InventoryItemCategory[]; fetchedInventoryCategory: InventoryItemCategory[];
fetchedHarvestUnits: HarvestUnits[]; fetchedHarvestUnits: HarvestUnits[];
} }

View File

@ -103,16 +103,19 @@ export default function InventoryPage() {
...item, ...item,
status: status:
inventoryStatus.find( inventoryStatus.find(
(statusItem) => statusItem.id.toString() === item.statusId (statusItem) => statusItem.id.toString() === item.statusId.toString()
)?.name || "", )?.name || "",
category: category:
inventoryCategory.find( inventoryCategory.find(
(categoryItem) => (categoryItem) =>
categoryItem.id.toString() === item.categoryId.toString() categoryItem.id.toString() === item.categoryId.toString()
)?.name || "", )?.name || "",
categoryId: item.categoryId.toString(),
unit: unit:
harvestUnits.find((unit) => unit.id.toString() === item.unitId) harvestUnits.find((unit) => unit.id === item.unitId)
?.name || "", ?.name || "",
unitId: item.unitId.toString(),
statusId: item.statusId.toString(),
fetchedInventoryStatus: inventoryStatus, fetchedInventoryStatus: inventoryStatus,
fetchedInventoryCategory: inventoryCategory, fetchedInventoryCategory: inventoryCategory,
fetchedHarvestUnits: harvestUnits, fetchedHarvestUnits: harvestUnits,

File diff suppressed because it is too large Load Diff

View File

@ -161,15 +161,8 @@ export type CreateInventoryItemInput = {
}; };
export type UpdateInventoryItemInput = CreateInventoryItemInput & {}; export type UpdateInventoryItemInput = CreateInventoryItemInput & {};
export interface CreateInventoryItemInput {
name: string; // export type UpdateInventoryItemInput = Partial<CreateInventoryItemInput> & { id: string };
categoryId: number;
quantity: number;
unitId: number;
dateAdded: string;
statusId: number;
}
export type UpdateInventoryItemInput = Partial<CreateInventoryItemInput> & { id: string };
export interface Blog { export interface Blog {
id: number; id: number;