Latest Changes as per feedback
This commit is contained in:
parent
2b47d2b3c8
commit
e6c13e8ef5
|
@ -1 +0,0 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
Before Width: | Height: | Size: 1.5 KiB |
12
src/App.jsx
12
src/App.jsx
|
@ -38,18 +38,18 @@ const App = () => {
|
|||
];
|
||||
|
||||
return (
|
||||
<div className="bg-gradient-to-r from-blue-500 via-blue-300 to-blue-100 min-h-screen flex flex-col items-center justify-center text-white">
|
||||
<div className="bg-gradient-to-r from-blue-500 via-blue-300 to-blue-100 min-h-screen flex flex-col items-center text-white">
|
||||
<header className="w-full py-4 fixed top-0 bg-black bg-opacity-80 z-10">
|
||||
<Navbar />
|
||||
</header>
|
||||
<div className="w-full max-w-screen-lg mt-20 p-4">
|
||||
<div className="flex flex-wrap justify-between items-center mb-6 bg-white p-4 rounded-lg shadow">
|
||||
<div className="flex flex-wrap justify-between items-center mb-6 p-4">
|
||||
<Dropdown
|
||||
name="category"
|
||||
value={filters?.category}
|
||||
onChange={handleFilterChange}
|
||||
options={categoryOptions}
|
||||
className="border border-gray-300 bg-black text-white rounded p-2"
|
||||
className="bg-slate-800 text-white rounded p-2 cursor-pointer"
|
||||
/>
|
||||
|
||||
<Dropdown
|
||||
|
@ -57,7 +57,7 @@ const App = () => {
|
|||
value={filters?.price}
|
||||
onChange={handleFilterChange}
|
||||
options={priceOptions}
|
||||
className="border border-gray-300 bg-black text-white rounded p-2"
|
||||
className="bg-slate-800 text-white rounded p-2 ml-2 cursor-pointer"
|
||||
/>
|
||||
|
||||
<Dropdown
|
||||
|
@ -65,11 +65,11 @@ const App = () => {
|
|||
value={filters?.rating}
|
||||
onChange={handleFilterChange}
|
||||
options={ratingOptions}
|
||||
className="border border-gray-300 bg-black text-white rounded p-2"
|
||||
className="bg-slate-800 text-white rounded p-2 cursor-pointer"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6 ">
|
||||
{filteredProducts?.map((product) => (
|
||||
<ProductCard key={product?.id} product={product} />
|
||||
))}
|
||||
|
|
81
src/assets/SvgIcons/svgIcons.jsx
Normal file
81
src/assets/SvgIcons/svgIcons.jsx
Normal file
|
@ -0,0 +1,81 @@
|
|||
/* eslint-disable react/no-unknown-property */
|
||||
const crossIcon = (
|
||||
<svg
|
||||
width="20px"
|
||||
height="18px"
|
||||
viewBox="0 0 128 128"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
ariaHidden="true"
|
||||
role="img"
|
||||
className="iconify iconify--noto"
|
||||
preserveAspectRatio="xMidYMid meet"
|
||||
>
|
||||
<path
|
||||
d="M58.9 78.6l-41.3 41.9c-1.5 1.5-3.2 2.5-5 3c4.1 1.2 8.6.2 11.8-3l38.2-38.1c.8-.8 2.1-.8 2.8 0l-3.7-3.8c-.7-.8-2-.8-2.8 0z"
|
||||
fill="#c33"
|
||||
></path>
|
||||
|
||||
<path
|
||||
d="M82.3 65.4c-.8-.8-.8-2 0-2.8l38.2-38.1c4.7-4.7 4.7-12.3 0-17s-12.2-4.7-16.9 0L65.4 45.6c-.8.8-2 .8-2.8 0L24.5 7.5c-4.7-4.7-12.3-4.7-17 0c-.4.4-.7.8-1 1.2c.2-.3.4-.5.6-.7c4.7-4.6 10.1-2.5 14.8 2.2l37.6 38.5c.8.8 2 .8 2.8 0l39.3-39.2c4.7-4.7 9.4-5.1 14.1-.4s3.9 9.6-.8 14.3L75.6 62.6c-.8.8-.8 2 0 2.8c0 0 38.1 38.2 38 38.2c4.7 4.7 6.5 10 1.8 14.7s-10.6 3.5-15.3-1.1l3.4 3.4c4.7 4.7 12.3 4.7 17 0s4.7-12.2 0-16.9c0-.1-38.2-38.3-38.2-38.3z"
|
||||
fill="#c33"
|
||||
></path>
|
||||
|
||||
<path
|
||||
d="M115.4 118.3c4.7-4.7 2.9-10-1.8-14.7c.1 0-38-38.2-38-38.2c-.8-.8-.8-2 0-2.8l39.3-39.2c4.7-4.7 5.5-9.6.8-14.3s-9.4-4.3-14.1.4L62.3 48.7c-.8.8-2 .8-2.8 0L21.9 10.2C17.2 5.5 11.8 3.4 7.1 8c-.2.2-.4.4-.6.7c-3.7 4.7-3.3 11.4 1 15.7l38.1 38.2c.8.8.8 2.1 0 2.8L7.5 103.5c-4.7 4.7-4.7 12.3 0 17c1.5 1.5 3.2 2.5 5 3c1.8-.6 3.6-1.6 5-3l41.3-41.9c.8-.8 2.1-.8 2.8 0l3.7 3.8l34.7 34.8c4.8 4.6 10.7 5.8 15.4 1.1z"
|
||||
fill="#f44336"
|
||||
></path>
|
||||
|
||||
<g fill="#ffffff">
|
||||
<path
|
||||
d="M55 56.4c-1.1-1.6-32.3-33.1-32.3-33.1s-2.3-2.6-4.7-.8c-2.2 1.7-1.1 4.3.1 5.6s29 29.7 30.4 30.9c1.3 1.2 3.9 1.4 5.5.6s1.8-2.1 1-3.2z"
|
||||
opacity=".2"
|
||||
></path>
|
||||
|
||||
<circle cx="12.2" cy="19" r="3.3" opacity=".2"></circle>
|
||||
</g>
|
||||
|
||||
<path
|
||||
d="M72.1 81.8c1.1 1.6 32.8 32.6 32.8 32.6s2.3 2.6 4.7.7c2.2-1.7 1-4.3-.2-5.6c-1.2-1.3-29.4-29.3-30.8-30.5c-1.3-1.2-3.9-1.3-5.5-.5s-1.8 2.2-1 3.3z"
|
||||
opacity=".2"
|
||||
fill="#ffffff"
|
||||
></path>
|
||||
</svg>
|
||||
);
|
||||
|
||||
const crossSecond = (
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 48 48"
|
||||
width="20px"
|
||||
height="20px"
|
||||
>
|
||||
<path
|
||||
fill="#F44336"
|
||||
d="M21.5 4.5H26.501V43.5H21.5z"
|
||||
transform="rotate(45.001 24 24)"
|
||||
/>
|
||||
<path
|
||||
fill="#F44336"
|
||||
d="M21.5 4.5H26.5V43.501H21.5z"
|
||||
transform="rotate(135.008 24 24)"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
|
||||
const starIcon = (
|
||||
<svg
|
||||
width="15px"
|
||||
height="15px"
|
||||
viewBox="0 -0.5 32 32"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M16.0005 0L21.4392 9.27275L32.0005 11.5439L24.8005 19.5459L25.889 30.2222L16.0005 25.895L6.11194 30.2222L7.20049 19.5459L0.000488281 11.5439L10.5618 9.27275L16.0005 0Z"
|
||||
fill="#FFCB45"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
|
||||
export { crossIcon, crossSecond, starIcon };
|
|
@ -1 +0,0 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
Before Width: | Height: | Size: 4 KiB |
|
@ -13,7 +13,9 @@ const Navbar = () => {
|
|||
return (
|
||||
<div>
|
||||
<nav className="flex justify-between items-center max-w-6xl mx-auto">
|
||||
<h1 className="text-2xl font-bold tracking-widest">Assignment-5</h1>
|
||||
<h1 className="text-2xl font-bold tracking-widest cursor-pointer">
|
||||
Assignment-5
|
||||
</h1>
|
||||
<ul className="flex space-x-6 text-lg">
|
||||
<li className="hover:text-gray-300 transition duration-300 cursor-pointer">
|
||||
Home
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/* eslint-disable react/prop-types */
|
||||
import { useContext } from "react";
|
||||
import { CartContext } from "../cartContext";
|
||||
import { starIcon } from "../../assets/SvgIcons/svgIcons";
|
||||
|
||||
const ProductCard = ({ product }) => {
|
||||
const { addToCart } = useContext(CartContext);
|
||||
|
@ -10,23 +11,30 @@ const ProductCard = ({ product }) => {
|
|||
<img
|
||||
src={product?.image}
|
||||
alt={product?.title}
|
||||
className="w-full h-48 object-cover rounded-t-lg mt-4"
|
||||
className="w-full h-48 object-fill rounded-t-lg mt-4 p-4"
|
||||
/>
|
||||
<div className="p-4">
|
||||
<h3 className="text-lg font-semibold text-gray-800">
|
||||
<h5 className="text-sm font-semibold text-gray-800 line-clamp-1">
|
||||
{product?.title}
|
||||
</h3>
|
||||
<p className="text-gray-600 text-justify">{product?.description}</p>
|
||||
<p className="mt-2 text-xl font-bold text-gray-900 underline">
|
||||
</h5>
|
||||
<p className="text-gray-600 text-justify line-clamp-3 text-xs">
|
||||
{product?.description}
|
||||
</p>
|
||||
<p className="mt-2 text-sm font-bold text-gray-900">
|
||||
${product?.price}
|
||||
</p>
|
||||
<p className="mt-2 text-xl text-gray-900">
|
||||
<p className="mt-2 text-sm text-gray-900">
|
||||
Category: {product?.category}
|
||||
</p>
|
||||
<p className="mt-2 text-m text-gray-900">{product?.rating?.rate}⭐️ </p>
|
||||
<p className="mt-2 text-sm text-gray-900">
|
||||
<span className="flex gap-1">
|
||||
Ratings: <b>{product?.rating?.rate}</b>
|
||||
<p className="mt-0.5">{starIcon}</p>
|
||||
</span>{" "}
|
||||
</p>
|
||||
<button
|
||||
onClick={() => addToCart(product)}
|
||||
className="flex px-4 py-2 items-center bg-gray-800 text-white text-xs font-bold uppercase rounded hover:bg-gray-700 focus:outline-none focus:bg-gray-700 mt-4 "
|
||||
className="flex px-4 py-2 items-center bg-gray-800 text-white text-xs font-bold uppercase rounded hover:bg-gray-700 focus:outline-none focus:bg-gray-700 mt-4"
|
||||
>
|
||||
Add to cart
|
||||
</button>
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
export const fetchProducts = async () => {
|
||||
const response = await fetch("https://fakestoreapi.com/products");
|
||||
if (!response?.ok) {
|
||||
throw new Error(`${response?.status} error occurred`);
|
||||
try {
|
||||
const response = await fetch("https://fakestoreapi.com/products");
|
||||
if (!response?.ok) {
|
||||
throw new Error(`${response?.status} error occurred`);
|
||||
}
|
||||
return await response?.json();
|
||||
} catch (error) {
|
||||
console.log("An error occured:", error?.message || error);
|
||||
throw error;
|
||||
}
|
||||
return response?.json();
|
||||
};
|
||||
|
|
|
@ -47,15 +47,20 @@ export const CartProvider = ({ children }) => {
|
|||
}
|
||||
};
|
||||
|
||||
const removeItem = (item) => {
|
||||
setCartItems(cartItems?.filter((cartItem) => cartItem?.id !== item?.id));
|
||||
};
|
||||
|
||||
const clearCart = () => {
|
||||
setCartItems([]);
|
||||
};
|
||||
|
||||
const getCartTotal = () => {
|
||||
return cartItems?.reduce(
|
||||
(total, item) => total + item?.price * item?.quantity,
|
||||
const total = cartItems?.reduce(
|
||||
(sum, item) => sum + item?.price * item?.quantity,
|
||||
0
|
||||
);
|
||||
return total?.toFixed(2);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -75,6 +80,7 @@ export const CartProvider = ({ children }) => {
|
|||
cartItems,
|
||||
addToCart,
|
||||
removeFromCart,
|
||||
removeItem,
|
||||
clearCart,
|
||||
getCartTotal,
|
||||
}}
|
||||
|
|
|
@ -1,77 +1,120 @@
|
|||
import PropTypes from "prop-types";
|
||||
import { useContext } from "react";
|
||||
/* eslint-disable react/prop-types */
|
||||
import { useContext, useState } from "react";
|
||||
import { CartContext } from "../cartContext";
|
||||
import { crossIcon, crossSecond } from "../../assets/SvgIcons/svgIcons";
|
||||
|
||||
export default function Cart({ showModal, toggle }) {
|
||||
const { cartItems, addToCart, removeFromCart, clearCart, getCartTotal } =
|
||||
useContext(CartContext);
|
||||
const {
|
||||
cartItems,
|
||||
addToCart,
|
||||
removeFromCart,
|
||||
removeItem,
|
||||
clearCart,
|
||||
getCartTotal,
|
||||
} = useContext(CartContext);
|
||||
|
||||
const [checkout, setCheckout] = useState("");
|
||||
|
||||
const handleCheckOut = () => {
|
||||
setCheckout("Your Order has been checked out");
|
||||
setTimeout(() => {
|
||||
setCheckout("");
|
||||
}, 3000);
|
||||
};
|
||||
|
||||
return (
|
||||
showModal && (
|
||||
<div className="flex-col flex items-center fixed inset-0 left-1/4 bg-white dark:bg-black gap-8 p-10 text-black dark:text-white font-normal uppercase text-sm overflow-x-auto">
|
||||
<h1 className="flex text-2xl font-bold items-center">Cart</h1>
|
||||
<div className="absolute right-16 top-10">
|
||||
<button className="px-4 py-2 text-xl" onClick={toggle}>
|
||||
❌
|
||||
<div className="fixed inset-0 left-1/4 bg-white dark:bg-slate-800 gap-8 p-10 text-black dark:text-white font-normal text-sm overflow-x-auto overflow-y-scroll no-scrollbar">
|
||||
<div className="flex flex-col gap-y-2 items-start">
|
||||
<h1 className="text-lg font-bold">Total: ${getCartTotal()}</h1>
|
||||
<button
|
||||
className="px-4 py-2 bg-gray-500 text-white text-xs font-bold rounded hover:bg-gray-600 focus:outline-none"
|
||||
onClick={handleCheckOut}
|
||||
>
|
||||
Checkout
|
||||
</button>
|
||||
</div>
|
||||
<div className="flex flex-col gap-4">
|
||||
{cartItems?.map((item) => (
|
||||
<div className="flex justify-between items-center" key={item?.id}>
|
||||
<div className="flex gap-4">
|
||||
<img
|
||||
src={item?.image}
|
||||
alt={item?.title}
|
||||
className="rounded-md h-24"
|
||||
/>
|
||||
<div className="flex flex-col">
|
||||
<h1 className="text-lg font-bold">{item?.title}</h1>
|
||||
<p className="text-gray-600">${item?.price}</p>
|
||||
<div className="flex items-center justify-center w-full">
|
||||
{cartItems?.length > 0 ? (
|
||||
<div className="flex flex-col justify-between items-center">
|
||||
{checkout && (
|
||||
<p className="mt-4 text-green-500 font-bold">{checkout}</p>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<h1 className="text-lg font-bold">Your cart is empty</h1>
|
||||
)}
|
||||
</div>
|
||||
<h1 className="flex text-4xl font-bold items-center justify-center w-full h-full">
|
||||
Cart Details
|
||||
</h1>
|
||||
|
||||
<div className="flex flex-col absolute right-5 top-0 gap-y-20">
|
||||
<div className="ml-5 top-5">
|
||||
<button className="px-4 py-2 text-xl mt-4" onClick={toggle}>
|
||||
{crossIcon}
|
||||
</button>
|
||||
</div>
|
||||
<div className="mr-6">
|
||||
<button
|
||||
className="px-4 py-2 bg-gray-500 text-white text-xs font-bold rounded hover:bg-gray-600 focus:outline-none focus:bg-gray-700 "
|
||||
onClick={() => {
|
||||
clearCart();
|
||||
}}
|
||||
>
|
||||
Clear cart
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-col items-start gap-4 w-full mt-8">
|
||||
{cartItems?.map((item) => (
|
||||
<div
|
||||
className="flex justify-between items-start rounded-lg border border-white p-4 min-w-full"
|
||||
key={item?.id}
|
||||
>
|
||||
<div className="flex gap-4">
|
||||
<img
|
||||
src={item?.image}
|
||||
alt={item?.title}
|
||||
className="rounded-md h-24 w-24"
|
||||
/>
|
||||
<div className="flex flex-col w-96">
|
||||
<h1 className="text-lg font-bold w-full">{item?.title}</h1>
|
||||
<p className="text-slate-300">${item?.price}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex gap-4 items-center ml-8">
|
||||
<button
|
||||
className="px-3 py-1 bg-gray-500 text-white text-l font-bold rounded hover:bg-gray-600 focus:outline-none focus:bg-gray-700"
|
||||
onClick={() => {
|
||||
removeFromCart(item);
|
||||
}}
|
||||
>
|
||||
-
|
||||
</button>
|
||||
<p>{item?.quantity}</p>
|
||||
<button
|
||||
className="px-3 py-1 bg-gray-500 text-white text-l font-bold rounded hover:bg-gray-600 focus:outline-none focus:bg-gray-700"
|
||||
onClick={() => {
|
||||
addToCart(item);
|
||||
}}
|
||||
>
|
||||
+
|
||||
</button>
|
||||
|
||||
<button
|
||||
className="px-3 py-1 text-red-600"
|
||||
onClick={() => {
|
||||
removeItem(item);
|
||||
}}
|
||||
>
|
||||
{crossSecond}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex gap-4">
|
||||
<button
|
||||
className="px-4 py-2 bg-gray-800 text-white text-l font-bold uppercase rounded hover:bg-gray-700 focus:outline-none focus:bg-gray-700"
|
||||
onClick={() => {
|
||||
addToCart(item);
|
||||
}}
|
||||
>
|
||||
+
|
||||
</button>
|
||||
<p>{item?.quantity}</p>
|
||||
<button
|
||||
className="px-4 py-2 bg-gray-800 text-white text-l font-bold uppercase rounded hover:bg-gray-700 focus:outline-none focus:bg-gray-700"
|
||||
onClick={() => {
|
||||
removeFromCart(item);
|
||||
}}
|
||||
>
|
||||
-
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
{cartItems?.length > 0 ? (
|
||||
<div className="flex flex-col justify-between items-center">
|
||||
<h1 className="text-lg font-bold">Total: ${getCartTotal()}</h1>
|
||||
<button
|
||||
className="px-4 py-2 bg-gray-800 text-white text-xs font-bold uppercase rounded hover:bg-gray-700 focus:outline-none focus:bg-gray-700"
|
||||
onClick={() => {
|
||||
clearCart();
|
||||
}}
|
||||
>
|
||||
Clear cart
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<h1 className="text-lg font-bold">Your cart is empty</h1>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Cart.propTypes = {
|
||||
showModal: PropTypes.bool,
|
||||
toggle: PropTypes.func,
|
||||
};
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
/* eslint-disable react/prop-types */
|
||||
// src/components/Dropdown.jsx
|
||||
const Dropdown = ({ name, value, onChange, options, className }) => {
|
||||
return (
|
||||
<select name={name} value={value} onChange={onChange} className={className}>
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
@tailwind utilities;
|
||||
|
||||
@layer utilities {
|
||||
.no-scrollbar::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.no-scrollbar {
|
||||
-ms-overflow-style: none;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue