mirror of
https://github.com/ForFarmTeam/ForFarm.git
synced 2025-12-19 14:04:08 +01:00
feat: enhance AddInventoryItem component with inventory categories, statuses, and units
This commit is contained in:
parent
6413032537
commit
c8b824d01f
@ -18,7 +18,11 @@ import {
|
|||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
import {
|
||||||
|
Popover,
|
||||||
|
PopoverContent,
|
||||||
|
PopoverTrigger,
|
||||||
|
} from "@/components/ui/popover";
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
@ -30,16 +34,31 @@ import {
|
|||||||
} from "@/components/ui/select";
|
} from "@/components/ui/select";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { createInventoryItem } from "@/api/inventory";
|
import { createInventoryItem } from "@/api/inventory";
|
||||||
import type { CreateInventoryItemInput } from "@/types";
|
import type {
|
||||||
|
CreateInventoryItemInput,
|
||||||
|
InventoryItemStatus,
|
||||||
|
InventoryItemCategory,
|
||||||
|
HarvestUnits,
|
||||||
|
} from "@/types";
|
||||||
|
|
||||||
export function AddInventoryItem() {
|
interface AddInventoryItemProps {
|
||||||
|
inventoryCategory: InventoryItemCategory[];
|
||||||
|
inventoryStatus: InventoryItemStatus[];
|
||||||
|
harvestUnits: HarvestUnits[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function AddInventoryItem({
|
||||||
|
inventoryCategory,
|
||||||
|
inventoryStatus,
|
||||||
|
harvestUnits,
|
||||||
|
}: AddInventoryItemProps) {
|
||||||
const [date, setDate] = useState<Date | undefined>();
|
const [date, setDate] = useState<Date | undefined>();
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [itemName, setItemName] = useState("");
|
const [itemName, setItemName] = useState("");
|
||||||
const [itemType, setItemType] = useState("");
|
|
||||||
const [itemCategory, setItemCategory] = useState("");
|
const [itemCategory, setItemCategory] = useState("");
|
||||||
const [itemQuantity, setItemQuantity] = useState(0);
|
const [itemQuantity, setItemQuantity] = useState(0);
|
||||||
const [itemUnit, setItemUnit] = useState("");
|
const [itemUnit, setItemUnit] = useState("");
|
||||||
|
const [itemStatus, setItemStatus] = useState("");
|
||||||
|
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
@ -50,7 +69,6 @@ export function AddInventoryItem() {
|
|||||||
queryClient.invalidateQueries({ queryKey: ["inventoryItems"] });
|
queryClient.invalidateQueries({ queryKey: ["inventoryItems"] });
|
||||||
// Reset form fields and close dialog.
|
// Reset form fields and close dialog.
|
||||||
setItemName("");
|
setItemName("");
|
||||||
setItemType("");
|
|
||||||
setItemCategory("");
|
setItemCategory("");
|
||||||
setItemQuantity(0);
|
setItemQuantity(0);
|
||||||
setItemUnit("");
|
setItemUnit("");
|
||||||
@ -61,10 +79,9 @@ export function AddInventoryItem() {
|
|||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
// Basic validation (you can extend this as needed)
|
// Basic validation (you can extend this as needed)
|
||||||
if (!itemName || !itemType || !itemCategory || !itemUnit) return;
|
if (!itemName || !itemCategory || !itemUnit) return;
|
||||||
mutation.mutate({
|
mutation.mutate({
|
||||||
name: itemName,
|
name: itemName,
|
||||||
type: itemType,
|
|
||||||
category: itemCategory,
|
category: itemCategory,
|
||||||
quantity: itemQuantity,
|
quantity: itemQuantity,
|
||||||
unit: itemUnit,
|
unit: itemUnit,
|
||||||
@ -79,43 +96,61 @@ export function AddInventoryItem() {
|
|||||||
<DialogContent className="sm:max-w-[425px]">
|
<DialogContent className="sm:max-w-[425px]">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>Add Inventory Item</DialogTitle>
|
<DialogTitle>Add Inventory Item</DialogTitle>
|
||||||
<DialogDescription>Add a new plantation or fertilizer item to your inventory.</DialogDescription>
|
<DialogDescription>
|
||||||
|
Add a new plantation or fertilizer item to your inventory.
|
||||||
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<div className="grid gap-4 py-4">
|
<div className="grid gap-4 py-4">
|
||||||
<div className="grid grid-cols-4 items-center gap-4">
|
<div className="grid grid-cols-4 items-center gap-4">
|
||||||
<Label htmlFor="name" className="text-right">
|
<Label htmlFor="name" className="text-right">
|
||||||
Name
|
Name
|
||||||
</Label>
|
</Label>
|
||||||
<Input id="name" className="col-span-3" value={itemName} onChange={(e) => setItemName(e.target.value)} />
|
<Input
|
||||||
|
id="name"
|
||||||
|
className="col-span-3"
|
||||||
|
value={itemName}
|
||||||
|
onChange={(e) => setItemName(e.target.value)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-4 items-center gap-4">
|
<div className="grid grid-cols-4 items-center gap-4">
|
||||||
<Label htmlFor="type" className="text-right">
|
<Label htmlFor="type" className="text-right">
|
||||||
Type
|
Category
|
||||||
</Label>
|
</Label>
|
||||||
<Select value={itemType} onValueChange={setItemType}>
|
<Select value={itemCategory} onValueChange={setItemCategory}>
|
||||||
<SelectTrigger className="col-span-3">
|
<SelectTrigger className="col-span-3">
|
||||||
<SelectValue placeholder="Select type" />
|
<SelectValue placeholder="Select type" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectGroup>
|
<SelectGroup>
|
||||||
<SelectLabel>Type</SelectLabel>
|
<SelectLabel>Category</SelectLabel>
|
||||||
<SelectItem value="plantation">Plantation</SelectItem>
|
{inventoryCategory.map((categoryItem, _) => (
|
||||||
<SelectItem value="fertilizer">Fertilizer</SelectItem>
|
<SelectItem key={categoryItem.id} value={categoryItem.name}>
|
||||||
|
{categoryItem.name}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
</SelectGroup>
|
</SelectGroup>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-4 items-center gap-4">
|
<div className="grid grid-cols-4 items-center gap-4">
|
||||||
<Label htmlFor="category" className="text-right">
|
<Label htmlFor="type" className="text-right">
|
||||||
Category
|
Status
|
||||||
</Label>
|
</Label>
|
||||||
<Input
|
<Select value={itemStatus} onValueChange={setItemStatus}>
|
||||||
id="category"
|
<SelectTrigger className="col-span-3">
|
||||||
className="col-span-3"
|
<SelectValue placeholder="Select status" />
|
||||||
placeholder="e.g., Seeds, Organic"
|
</SelectTrigger>
|
||||||
value={itemCategory}
|
<SelectContent>
|
||||||
onChange={(e) => setItemCategory(e.target.value)}
|
<SelectGroup>
|
||||||
/>
|
<SelectLabel>Status</SelectLabel>
|
||||||
|
{inventoryStatus.map((statusItem, _) => (
|
||||||
|
<SelectItem key={statusItem.id} value={statusItem.name}>
|
||||||
|
{statusItem.name}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectGroup>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-4 items-center gap-4">
|
<div className="grid grid-cols-4 items-center gap-4">
|
||||||
<Label htmlFor="quantity" className="text-right">
|
<Label htmlFor="quantity" className="text-right">
|
||||||
@ -130,16 +165,24 @@ export function AddInventoryItem() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-4 items-center gap-4">
|
<div className="grid grid-cols-4 items-center gap-4">
|
||||||
<Label htmlFor="unit" className="text-right">
|
<Label htmlFor="type" className="text-right">
|
||||||
Unit
|
Unit
|
||||||
</Label>
|
</Label>
|
||||||
<Input
|
<Select value={itemUnit} onValueChange={setItemUnit}>
|
||||||
id="unit"
|
<SelectTrigger className="col-span-3">
|
||||||
className="col-span-3"
|
<SelectValue placeholder="Select status" />
|
||||||
placeholder="e.g., kg, packets"
|
</SelectTrigger>
|
||||||
value={itemUnit}
|
<SelectContent>
|
||||||
onChange={(e) => setItemUnit(e.target.value)}
|
<SelectGroup>
|
||||||
/>
|
<SelectLabel>Unit</SelectLabel>
|
||||||
|
{harvestUnits.map((unit, _) => (
|
||||||
|
<SelectItem key={unit.id} value={unit.name}>
|
||||||
|
{unit.name}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectGroup>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-4 items-center gap-4">
|
<div className="grid grid-cols-4 items-center gap-4">
|
||||||
<Label htmlFor="date" className="text-right">
|
<Label htmlFor="date" className="text-right">
|
||||||
@ -149,13 +192,22 @@ export function AddInventoryItem() {
|
|||||||
<PopoverTrigger asChild>
|
<PopoverTrigger asChild>
|
||||||
<Button
|
<Button
|
||||||
variant={"outline"}
|
variant={"outline"}
|
||||||
className={cn("col-span-3 justify-start text-left font-normal", !date && "text-muted-foreground")}>
|
className={cn(
|
||||||
|
"col-span-3 justify-start text-left font-normal",
|
||||||
|
!date && "text-muted-foreground"
|
||||||
|
)}
|
||||||
|
>
|
||||||
<CalendarIcon className="mr-2 h-4 w-4" />
|
<CalendarIcon className="mr-2 h-4 w-4" />
|
||||||
{date ? format(date, "PPP") : "Pick a date"}
|
{date ? format(date, "PPP") : "Pick a date"}
|
||||||
</Button>
|
</Button>
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent className="w-auto p-0">
|
<PopoverContent className="w-auto p-0">
|
||||||
<Calendar mode="single" selected={date} onSelect={setDate} initialFocus />
|
<Calendar
|
||||||
|
mode="single"
|
||||||
|
selected={date}
|
||||||
|
onSelect={setDate}
|
||||||
|
initialFocus
|
||||||
|
/>
|
||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
</Popover>
|
</Popover>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -221,7 +221,11 @@ export default function InventoryPage() {
|
|||||||
value={searchTerm}
|
value={searchTerm}
|
||||||
onChange={(e) => setSearchTerm(e.target.value)}
|
onChange={(e) => setSearchTerm(e.target.value)}
|
||||||
/>
|
/>
|
||||||
<AddInventoryItem />
|
<AddInventoryItem
|
||||||
|
inventoryCategory={inventoryCategory}
|
||||||
|
inventoryStatus={inventoryStatus}
|
||||||
|
harvestUnits={harvestUnits}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="border rounded-md">
|
<div className="border rounded-md">
|
||||||
<Table>
|
<Table>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user