diff --git a/backend/package-lock.json b/backend/package-lock.json index 93f8554b..7f66d27b 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "@google/generative-ai": "^0.21.0", "bcryptjs": "^2.4.3", "cors": "^2.8.5", "dotenv": "^16.0.3", @@ -1330,6 +1331,14 @@ "resolved": "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz", "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==" }, + "node_modules/@google/generative-ai": { + "version": "0.21.0", + "resolved": "https://registry.npmjs.org/@google/generative-ai/-/generative-ai-0.21.0.tgz", + "integrity": "sha512-7XhUbtnlkSEZK15kN3t+tzIMxsbKm/dSkKBFalj+20NvPKe1kBY7mR2P7vuijEn+f06z5+A8bVGKO0v39cr6Wg==", + "engines": { + "node": ">=18.0.0" + } + }, "node_modules/@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", diff --git a/frontend/src/AgroRentAI/NavigateProducts.jsx b/frontend/src/AgroRentAI/NavigateProducts.jsx index 46963e0c..fd7b846a 100644 --- a/frontend/src/AgroRentAI/NavigateProducts.jsx +++ b/frontend/src/AgroRentAI/NavigateProducts.jsx @@ -2,29 +2,41 @@ import React, { useState, useEffect } from 'react'; import { Search, ShoppingCart, ChevronDown, Star } from 'lucide-react'; import img1 from "../assets/116.jpg"; import axios from 'axios'; +import { useNavigate } from 'react-router-dom'; // Assuming the categories list is the same const categories = ['All', 'Farming Technology', 'Farming Equipment', 'Agriculture']; -const ProductCard = ({ product }) => ( -
- {product.name} -
-

{product.name}

-

{product.description}

-
- ${product.price}/day - -
-
- - {product.rating} +const ProductCard = ({ product }) => { + const navigate = useNavigate(); + + const handleRentNowClick = () => { + navigate(`/RentProductDetails/${product._id}`); // Assuming product.id uniquely identifies the product + }; + + return ( +
+ {product.name} +
+

{product.name}

+

{product.description}

+
+ ${product.price}/day + +
+
+ + {product.rating} +
-
-); + ); +}; const FilterSidebar = ({ selectedCategory, setSelectedCategory, priceRange, setPriceRange }) => (
@@ -82,11 +94,14 @@ const RentalMarketplace = () => { const [filteredProducts, setFilteredProducts] = useState([]); const [selectedCategory, setSelectedCategory] = useState('All'); const [priceRange, setPriceRange] = useState({ min: 0, max: 100 }); + const ApiUrl = process.env.NODE_ENV === 'production' + ? 'https://agrotech-ai-11j3.onrender.com' + : 'http://localhost:8080'; useEffect(() => { const fetchProducts = async () => { try { - const response = await fetch(`https://agrotech-ai-11j3.onrender.com/api/rent-products`); + const response = await fetch(`${ApiUrl}/api/rent-products`); const data = await response.json(); setProducts(data); setFilteredProducts(data); // Initialize filteredProducts diff --git a/frontend/src/AgroRentAI/RentProductDetails.jsx b/frontend/src/AgroRentAI/RentProductDetails.jsx new file mode 100644 index 00000000..64175850 --- /dev/null +++ b/frontend/src/AgroRentAI/RentProductDetails.jsx @@ -0,0 +1,111 @@ +import React, { useState, useEffect } from 'react'; +import { Star } from 'lucide-react'; +import { useParams } from 'react-router-dom'; + +const RentProductDetails = () => { + const [product, setProduct] = useState(null); + const [quantity, setQuantity] = useState(1); + const ApiUrl = process.env.NODE_ENV === 'production' + ? 'https://agrotech-ai-11j3.onrender.com' + : 'http://localhost:8080'; + + const {productId} = useParams() + // Fetch product details by product ID + useEffect(() => { + const fetchProductDetails = async () => { + + const response = await fetch(`${ApiUrl}/api/rent-products/${productId}`); + const data = await response.json(); + setProduct(data); + }; + + fetchProductDetails(); + }, [productId]); + + const handleAddToCart = () => { + // Implement the add-to-cart functionality here + console.log(`Added ${quantity} of ${product.name} to cart`); + }; + + const handleProceedToCheckout = () => { + // Redirect to checkout page or handle checkout logic + console.log('Proceeding to checkout'); + }; + + if (!product) { + return

Loading...

; + } + + return ( +
+ {/* Heading */} +

Product Details

+ +
+
+ {/* Product Image */} +
+ {product.name} +
+ + {/* Product Details */} +
+

{product.name}

+
+ + {product.rating} / 5 +
+

{product.description}

+ + {/* Category */} +
+ {product.category.map((cat, index) => ( + + {cat} + + ))} +
+ + {/* Price */} +

${product.price} / day

+ + {/* Quantity Selector */} +
+ + setQuantity(Math.max(1, e.target.value))} + className="w-16 text-center border border-green-300 rounded-md" + /> +
+ + {/* Add to Cart and Checkout Buttons */} +
+ + +
+
+
+
+
+ + + ); +}; + +export default RentProductDetails; diff --git a/frontend/src/MainContent.jsx b/frontend/src/MainContent.jsx index e42983aa..3312ecd5 100644 --- a/frontend/src/MainContent.jsx +++ b/frontend/src/MainContent.jsx @@ -46,7 +46,11 @@ import ElectricalElectronicsShops from './components/ElectricalElectronicsShops' import HeroSectionRent from './AgroRentAI/HeroSectionRent'; import NavigateProducts from './AgroRentAI/NavigateProducts'; import RentUserDashboard from './AgroRentAI/RentUserDashboard'; + +import RentProductDetails from './AgroRentAI/RentProductDetails'; + import RentAdminDashboard from './AgroRentAI/RentAdminDashboard'; + //AgroShopAI import HomeShop from './AgroShopAI/pages/HomeShop'; import ShopFooter from './AgroShopAI/components/ShopFooter'; @@ -145,8 +149,11 @@ const MainContent = () => { } /> } /> } /> - } /> + + } /> + } /> + } /> {/* AgroShopAI Routes */} } />