mirror of
https://github.com/ForFarmTeam/ForFarm.git
synced 2025-12-19 14:04:08 +01:00
refactor: rename InventoryItemStatus to InventoryStatus and update related types
This commit is contained in:
parent
f8390f1ee5
commit
80d6897f3b
@ -1,7 +1,7 @@
|
||||
import axiosInstance from "./config";
|
||||
import type {
|
||||
InventoryItem,
|
||||
InventoryItemStatus,
|
||||
InventoryStatus,
|
||||
InventoryItemCategory,
|
||||
CreateInventoryItemInput,
|
||||
UpdateInventoryItemInput,
|
||||
@ -14,9 +14,9 @@ import type {
|
||||
*
|
||||
*
|
||||
*/
|
||||
export async function fetchInventoryStatus(): Promise<InventoryItemStatus[]> {
|
||||
export async function fetchInventoryStatus(): Promise<InventoryStatus[]> {
|
||||
try {
|
||||
const response = await axiosInstance.get<InventoryItemStatus[]>(
|
||||
const response = await axiosInstance.get<InventoryStatus[]>(
|
||||
"/inventory/status"
|
||||
);
|
||||
return response.data;
|
||||
@ -44,56 +44,9 @@ export async function fetchInventoryItems(): Promise<InventoryItem[]> {
|
||||
const response = await axiosInstance.get<InventoryItem[]>("/inventory");
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
// console.error("Error while fetching inventory items! " + 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",
|
||||
},
|
||||
];
|
||||
console.error("Error while fetching inventory items! " + error);
|
||||
throw error;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -36,14 +36,14 @@ import { cn } from "@/lib/utils";
|
||||
import { createInventoryItem } from "@/api/inventory";
|
||||
import type {
|
||||
CreateInventoryItemInput,
|
||||
InventoryItemStatus,
|
||||
InventoryStatus,
|
||||
InventoryItemCategory,
|
||||
HarvestUnits,
|
||||
} from "@/types";
|
||||
|
||||
interface AddInventoryItemProps {
|
||||
inventoryCategory: InventoryItemCategory[];
|
||||
inventoryStatus: InventoryItemStatus[];
|
||||
inventoryStatus: InventoryStatus[];
|
||||
harvestUnits: HarvestUnits[];
|
||||
}
|
||||
|
||||
|
||||
@ -27,11 +27,7 @@ import {
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import {
|
||||
InventoryItemStatus,
|
||||
InventoryItemCategory,
|
||||
HarvestUnits,
|
||||
} from "@/types";
|
||||
import { InventoryStatus, InventoryItemCategory, HarvestUnits } from "@/types";
|
||||
import { updateInventoryItem } from "@/api/inventory";
|
||||
import type { UpdateInventoryItemInput } from "@/types";
|
||||
|
||||
@ -42,7 +38,7 @@ export interface EditInventoryItemProps {
|
||||
statusId: string;
|
||||
unitId: string;
|
||||
quantity: number;
|
||||
fetchedInventoryStatus: InventoryItemStatus[];
|
||||
fetchedInventoryStatus: InventoryStatus[];
|
||||
fetchedInventoryCategory: InventoryItemCategory[];
|
||||
fetchedHarvestUnits: HarvestUnits[];
|
||||
}
|
||||
|
||||
@ -103,16 +103,19 @@ export default function InventoryPage() {
|
||||
...item,
|
||||
status:
|
||||
inventoryStatus.find(
|
||||
(statusItem) => statusItem.id.toString() === item.statusId
|
||||
(statusItem) => statusItem.id.toString() === item.statusId.toString()
|
||||
)?.name || "",
|
||||
category:
|
||||
inventoryCategory.find(
|
||||
(categoryItem) =>
|
||||
categoryItem.id.toString() === item.categoryId.toString()
|
||||
)?.name || "",
|
||||
categoryId: item.categoryId.toString(),
|
||||
unit:
|
||||
harvestUnits.find((unit) => unit.id.toString() === item.unitId)
|
||||
harvestUnits.find((unit) => unit.id === item.unitId)
|
||||
?.name || "",
|
||||
unitId: item.unitId.toString(),
|
||||
statusId: item.statusId.toString(),
|
||||
fetchedInventoryStatus: inventoryStatus,
|
||||
fetchedInventoryCategory: inventoryCategory,
|
||||
fetchedHarvestUnits: harvestUnits,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -161,15 +161,8 @@ export type CreateInventoryItemInput = {
|
||||
};
|
||||
|
||||
export type UpdateInventoryItemInput = CreateInventoryItemInput & {};
|
||||
export interface CreateInventoryItemInput {
|
||||
name: string;
|
||||
categoryId: number;
|
||||
quantity: number;
|
||||
unitId: number;
|
||||
dateAdded: string;
|
||||
statusId: number;
|
||||
}
|
||||
export type UpdateInventoryItemInput = Partial<CreateInventoryItemInput> & { id: string };
|
||||
|
||||
// export type UpdateInventoryItemInput = Partial<CreateInventoryItemInput> & { id: string };
|
||||
|
||||
export interface Blog {
|
||||
id: number;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user