mirror of
https://github.com/ForFarmTeam/ForFarm.git
synced 2025-12-19 14:04:08 +01:00
feat: streamline inventory item editing by simplifying category, unit, and status ID retrieval
This commit is contained in:
parent
0ded8e67ac
commit
ea214e3cf1
@ -1,12 +1,8 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { CalendarIcon } from "lucide-react";
|
|
||||||
import { format } from "date-fns";
|
|
||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Calendar } from "@/components/ui/calendar";
|
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
@ -92,9 +88,11 @@ export function EditInventoryItem({
|
|||||||
|
|
||||||
const category = fetchedInventoryCategory.find(
|
const category = fetchedInventoryCategory.find(
|
||||||
(c) => c.name === itemCategory
|
(c) => c.name === itemCategory
|
||||||
);
|
)?.id;
|
||||||
const unit = fetchedHarvestUnits.find((u) => u.name === itemUnit);
|
const unit = fetchedHarvestUnits.find((u) => u.name === itemUnit)?.id;
|
||||||
const status = fetchedInventoryStatus.find((s) => s.name === itemStatus);
|
const status = fetchedInventoryStatus.find(
|
||||||
|
(s) => s.name === itemStatus
|
||||||
|
)?.id;
|
||||||
|
|
||||||
if (!category || !unit || !status) {
|
if (!category || !unit || !status) {
|
||||||
setError(
|
setError(
|
||||||
@ -103,16 +101,13 @@ export function EditInventoryItem({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// console.log("Mutate called");
|
// console.log("Mutate called");
|
||||||
console.log(item.id);
|
// console.log(item.id);
|
||||||
mutation.mutate({
|
mutation.mutate({
|
||||||
name: itemName,
|
name: itemName,
|
||||||
categoryId: item.categoryId ?? 0,
|
categoryId: category,
|
||||||
quantity: itemQuantity ?? 0,
|
quantity: itemQuantity ?? 0,
|
||||||
unitId:
|
unitId: unit,
|
||||||
fetchedHarvestUnits.find((unit) => unit.name === itemUnit)?.id ?? 0,
|
statusId: status,
|
||||||
statusId:
|
|
||||||
fetchedInventoryStatus.find((status) => status.name === itemStatus)
|
|
||||||
?.id ?? 0,
|
|
||||||
dateAdded: new Date().toISOString(),
|
dateAdded: new Date().toISOString(),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user