-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproduct-listing.html
More file actions
79 lines (62 loc) · 2.66 KB
/
Copy pathproduct-listing.html
File metadata and controls
79 lines (62 loc) · 2.66 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Farmers Market - Add Products</title>
<link rel="stylesheet" href="product-listing.css">
</head>
<body>
<header>
<h1 class="heading">AgriBaazarConnect - Add Products</h1>
</header>
<div class="main-container">
<main class="content">
<div class="container">
<header class="product-header">
<h2>Add New Product</h2>
</header>
<form id="product-form">
<label for="name">Product Name:</label>
<input type="text" id="name" name="name" required><br>
<label for="description">Description:</label>
<textarea id="description" name="description"></textarea><br>
<label for="price">Price (₹):</label>
<input type="number" id="price" name="price" required min="0"><br>
<label for="quantity">Quantity:</label>
<input type="number" id="quantity" name="quantity" required min="0"><br>
<button type="submit">Add Product</button>
</form>
<div id="message"></div>
</div>
</main>
</div>
<footer>
<p>© 2024 AgriBaazarConnect. All rights reserved.</p>
</footer>
<script>
document.getElementById('product-form').addEventListener('submit', async function (e) {
e.preventDefault();
const name = document.getElementById('name').value;
const description = document.getElementById('description').value;
const price = document.getElementById('price').value;
const quantity = document.getElementById('quantity').value;
const token = localStorage.getItem('token'); // Retrieve the stored token
const response = await fetch('http://localhost:5000/api/products/add', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({ name, description, price, quantity })
});
const result = await response.json();
if (response.ok) {
document.getElementById('message').innerHTML = 'Product added successfully!';
} else {
document.getElementById('message').innerHTML = `Error: ${result.msg || 'Failed to add product'}`;
}
});
</script>
</body>
</html>