Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added Wishlist page #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"react-razorpay": "^2.0.1",
"react-redux": "^8.1.2",
"react-router-dom": "^6.16.0",
"redux-persist": "^6.0.0"
"redux-persist": "^6.0.0",
"uuid": "^10.0.0"
},
"devDependencies": {
"@types/react": "^18.2.15",
Expand Down
4 changes: 4 additions & 0 deletions client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import Retailer_home from "./pages/Retailer-home";
import Product from "./pages/Product";
import Cart from "./pages/Cart";
import ScrollToTop from "./components/ScrollToTop";
import Wishlist from "./pages/Wishlist/wishlist";
import './App.css'
function App() {
return (
<BrowserRouter>
Expand All @@ -30,7 +32,9 @@ function App() {
<Route path="about" element={<About />} />
<Route path="product" element={<Product />} />
<Route path="cart" element={<Cart />} />
<Route path="wishlist" element={<Wishlist />} />
<Route path="retailer" element={<Layout_retailer />}>

<Route index element={<Retailer_home />} />
</Route>
</Route>
Expand Down
62 changes: 62 additions & 0 deletions client/src/pages/Wishlist/wishlist.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// src/components/Wishlist.js
import React, { useState } from 'react';
import { v4 as uuidv4 } from 'uuid'; // For generating unique keys

const Wishlist = () => {
const [wishlist, setWishlist] = useState([]);

const addToWishlist = (product) => {
if (!wishlist.some(item => item.id === product.id)) {
setWishlist(prevWishlist => [...prevWishlist, { ...product, id: uuidv4() }]);
}
};

const removeFromWishlist = (productId) => {
setWishlist(prevWishlist => prevWishlist.filter(item => item.id !== productId));
};

const products = [
{ id: uuidv4(), name: 'Running Shoes' },
{ id: uuidv4(), name: 'Basketball Shoes' },
{ id: uuidv4(), name: 'Casual Shoes' },
];

return (
<div className="p-4">
<h1 className="text-3xl font-bold mb-4">Wishlist</h1>
<div className="space-y-4">
{products.map(product => (
<div key={product.id} className="flex justify-between items-center bg-white p-4 rounded-lg shadow-md">
<span>{product.name}</span>
<button
onClick={() => addToWishlist(product)}
className="px-4 py-2 rounded bg-gray-300 text-gray-800 hover:bg-gray-400 hover:text-gray-900"
>
Add to Wishlist
</button>
</div>
))}
</div>
<h2 className="text-2xl font-bold my-4">My Wishlist</h2>
{wishlist.length === 0 ? (
<p>No items in wishlist</p>
) : (
<ul>
{wishlist.map(item => (
<li key={item.id} className="flex justify-between items-center bg-white p-4 rounded-lg shadow-md">
<span>{item.name}</span>
<button
onClick={() => removeFromWishlist(item.id)}
className="px-4 py-2 rounded bg-red-500 text-white"
>
Remove
</button>
</li>
))}
</ul>
)}
</div>
);
};

export default Wishlist;
Loading