From ea214e3cf14a86a42c73a56dd4df2daf78d3107d Mon Sep 17 00:00:00 2001 From: THIS ONE IS A LITTLE BIT TRICKY KRUB Date: Fri, 4 Apr 2025 14:13:25 +0700 Subject: [PATCH] feat: streamline inventory item editing by simplifying category, unit, and status ID retrieval --- .../inventory/edit-inventory-item.tsx | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/frontend/app/(sidebar)/inventory/edit-inventory-item.tsx b/frontend/app/(sidebar)/inventory/edit-inventory-item.tsx index 6218db6..9420996 100644 --- a/frontend/app/(sidebar)/inventory/edit-inventory-item.tsx +++ b/frontend/app/(sidebar)/inventory/edit-inventory-item.tsx @@ -1,12 +1,8 @@ "use client"; import { useState } from "react"; -import { CalendarIcon } from "lucide-react"; -import { format } from "date-fns"; import { useMutation, useQueryClient } from "@tanstack/react-query"; - import { Button } from "@/components/ui/button"; -import { Calendar } from "@/components/ui/calendar"; import { Dialog, DialogContent, @@ -92,9 +88,11 @@ export function EditInventoryItem({ const category = fetchedInventoryCategory.find( (c) => c.name === itemCategory - ); - const unit = fetchedHarvestUnits.find((u) => u.name === itemUnit); - const status = fetchedInventoryStatus.find((s) => s.name === itemStatus); + )?.id; + const unit = fetchedHarvestUnits.find((u) => u.name === itemUnit)?.id; + const status = fetchedInventoryStatus.find( + (s) => s.name === itemStatus + )?.id; if (!category || !unit || !status) { setError( @@ -103,16 +101,13 @@ export function EditInventoryItem({ return; } // console.log("Mutate called"); - console.log(item.id); + // console.log(item.id); mutation.mutate({ name: itemName, - categoryId: item.categoryId ?? 0, + categoryId: category, quantity: itemQuantity ?? 0, - unitId: - fetchedHarvestUnits.find((unit) => unit.name === itemUnit)?.id ?? 0, - statusId: - fetchedInventoryStatus.find((status) => status.name === itemStatus) - ?.id ?? 0, + unitId: unit, + statusId: status, dateAdded: new Date().toISOString(), }); };