-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathpage.tsx
More file actions
81 lines (72 loc) · 2.31 KB
/
page.tsx
File metadata and controls
81 lines (72 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'use client';
import { useState } from "react";
import { useRouter } from "next/navigation";
export default function AddItemPage() {
const router = useRouter();
const [name, setName] = useState("");
const [description, setDescription] = useState("");
const [lastSeenPlace, setLastSeenPlace] = useState("");
const [contactInfo, setContactInfo] = useState("");
const handleSave = () => {
// Save the item to local storage or a backend API
const newItem = {
id: Date.now(), // Generate a unique ID
name,
description,
lastSeenPlace,
contactInfo,
status: "lost", // Default status
};
// Save to local storage (for demonstration purposes)
// Get the existing items or default to an empty array
const existingItemsString = localStorage.getItem("lostFoundItems");
const existingItems = existingItemsString ? JSON.parse(existingItemsString) : [];
// Add the new item and save back to local storage
localStorage.setItem(
"lostFoundItems",
JSON.stringify([...existingItems, newItem])
);
// Redirect back to the LostFound page
router.push("/lost-found");
};
return (
<div className="p-4 max-w-md mx-auto">
<h1 className="text-2xl font-bold mb-4">Add New Item</h1>
<div className="space-y-4">
<input
type="text"
placeholder="Item Name"
className="w-full p-2 border rounded"
value={name}
onChange={(e) => setName(e.target.value)}
/>
<textarea
placeholder="Description"
className="w-full p-2 border rounded"
value={description}
onChange={(e) => setDescription(e.target.value)}
/>
<input
type="text"
placeholder="Last Seen Place"
className="w-full p-2 border rounded"
value={lastSeenPlace}
onChange={(e) => setLastSeenPlace(e.target.value)}
/>
<input
type="text"
placeholder="Contact Info"
className="w-full p-2 border rounded"
value={contactInfo}
onChange={(e) => setContactInfo(e.target.value)}
/>
<button
className="w-full bg-blue-600 text-white py-2 rounded hover:bg-blue-700"
onClick={handleSave}
>
Save
</button>
</div>
</div>
);
}