Skip to content

Commit 0ff8810

Browse files
committed
Updated logic for user inventory to close selection modal and open item edit modal
1 parent 0303b09 commit 0ff8810

2 files changed

Lines changed: 33 additions & 8 deletions

File tree

client/src/components/ui/popups/user_inventory_select_popup.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@ type ItemModalProps = {
1313
isOpen: boolean;
1414
item: InventoryItem | null;
1515
onClose: () => void;
16+
onEdit: (item: InventoryItem) => void;
1617
};
1718

18-
function UserInventorySelectPopup({ isOpen, item, onClose }: ItemModalProps) {
19+
function UserInventorySelectPopup({
20+
isOpen,
21+
item,
22+
onClose,
23+
onEdit,
24+
}: ItemModalProps) {
1925
if (!isOpen || !item) return null;
2026
return (
21-
<div
22-
className="fixed inset-0 z-50 flex items-center justify-center bg-black/40"
23-
onClick={onClose}
24-
>
27+
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40">
28+
{/* onClick={onClose} */}
2529
<div className="w-full max-w-md rounded-xl bg-white p-6 shadow-lg">
2630
{/* Header */}
2731
<div className="mb-3 flex items-center justify-between">
@@ -67,11 +71,20 @@ function UserInventorySelectPopup({ isOpen, item, onClose }: ItemModalProps) {
6771

6872
{/* Footer */}
6973
<div className="flex justify-end gap-3 border-t pt-4">
70-
<Link href="/user_inventory">
74+
{/* <Link href="/user_inventory">
7175
<button className="rounded bg-blue-600 px-4 py-2 text-white hover:bg-blue-700">
7276
Edit
7377
</button>
74-
</Link>
78+
</Link> */}
79+
<button
80+
className="rounded bg-blue-600 px-4 py-2 text-white hover:bg-blue-700"
81+
onClick={() => {
82+
onClose(); // close current modal
83+
onEdit(item); // tell parent to open edit modal
84+
}}
85+
>
86+
Edit
87+
</button>
7588
<button
7689
onClick={onClose}
7790
className="rounded bg-gray-200 px-4 py-2 hover:bg-gray-300"

client/src/components/ui/user_tables/user_inventory_table.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// src/pages/user_dashboard.tsx (Update the import path)
22
//import "";
3-
import { useEffect,useState } from "react";
3+
import { useEffect, useState } from "react";
44

5+
import UserInventoryEditPopup from "../popups/user_inventory_edit_popup";
56
import InventoryItemModal from "../popups/user_inventory_select_popup";
67

78
export type InventoryItem = {
@@ -14,6 +15,7 @@ const UserInventoryTable = () => {
1415
const [inventory, setInventory] = useState<InventoryItem[]>([]);
1516
const [selectedItem, setSelectedItem] = useState<InventoryItem | null>(null);
1617
const [isModalOpen, setIsModalOpen] = useState(false);
18+
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
1719

1820
// Mock data (replace with Django API call later)
1921
useEffect(() => {
@@ -67,6 +69,16 @@ const UserInventoryTable = () => {
6769
isOpen={isModalOpen}
6870
item={selectedItem}
6971
onClose={() => setIsModalOpen(false)}
72+
onEdit={(item) => {
73+
setIsModalOpen(false);
74+
setSelectedItem(item);
75+
setIsEditModalOpen(true);
76+
}}
77+
/>
78+
<UserInventoryEditPopup
79+
isOpen={isEditModalOpen}
80+
item={selectedItem}
81+
onClose={() => setIsEditModalOpen(false)}
7082
/>
7183
</>
7284
);

0 commit comments

Comments
 (0)