Skip to content

Commit f92b669

Browse files
committed
i swear if forever young loses the BCC im gonna rename this project
1 parent 63724b3 commit f92b669

11 files changed

Lines changed: 274 additions & 122 deletions

File tree

‎package-lock.json‎

Lines changed: 148 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
"preview": "vite preview"
1212
},
1313
"dependencies": {
14+
"@reduxjs/toolkit": "^2.13.0",
1415
"@tailwindcss/vite": "^4.3.3",
1516
"axios": "^1.20.0",
1617
"faizen-react-components": "github:SA-Faizeen/faizen-react-components",
1718
"react": "^19.2.8",
1819
"react-dom": "^19.2.8",
20+
"react-hot-toast": "^2.6.1",
1921
"react-icons": "^5.7.0",
22+
"react-redux": "^9.3.1",
2023
"react-router-dom": "^7.18.4",
2124
"react-slick": "^0.31.0",
2225
"slick-carousel": "^2.0.0",

‎src/components/FilterGroup.jsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { GoDotFill } from "react-icons/go";
66
* @param {string} props.title - Group heading
77
* @param {{ label: string, color?: string }[]} props.items - Options; a color adds a dot
88
*/
9-
const FilterGroup = ({ title, items }) => {
9+
const FilterGroup = ({ title, items, onClick }) => {
1010
return (
1111
<div>
1212
<h3 className="text-ink pb-8.75 text-xl font-bold">{title}</h3>
@@ -15,6 +15,7 @@ const FilterGroup = ({ title, items }) => {
1515
<li key={item.label} className="shop-category">
1616
<button
1717
type="button"
18+
onClick={onClick}
1819
className="flex cursor-pointer items-center gap-x-2.5"
1920
>
2021
{item.color && <GoDotFill color={item.color} />}

‎src/components/ProductActions.jsx‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import { FaArrowsRotate, FaCartShopping, FaHeart } from "react-icons/fa6";
2+
import { useDispatch } from "react-redux";
3+
import toast from "react-hot-toast";
4+
import { addToCart } from "../store/cartSlice";
25

36
/**
47
* A text button with an icon beside it, used in the product action panel.
58
* @param {Object} props
69
* @param {React.ReactNode} props.icon - Icon element, e.g. <FaHeart />
710
* @param {React.ReactNode} props.children - Button label
811
* @param {string} [props.className] - Extra classes to add
12+
* @param {function} [props.onClick] - Click handler
913
*/
10-
const ProductActionButton = ({ icon, children, className = "" }) => {
14+
const ProductActionButton = ({ icon, children, onClick, className = "" }) => {
1115
return (
1216
<button
1317
type="button"
18+
onClick={onClick}
1419
className={`flex cursor-pointer items-center gap-x-4 ${className}`}
1520
>
1621
<span className="text-muted hover:text-ink duration-300 ease-in-out hover:font-bold">
@@ -25,9 +30,12 @@ const ProductActionButton = ({ icon, children, className = "" }) => {
2530
* Panel of product actions that slides up from below its parent on hover.
2631
* The parent must have the classes `group relative overflow-hidden`.
2732
* @param {Object} props
33+
* @param {Object} [props.product] - Product data to add to cart
2834
* @param {string} [props.className] - Extra classes to add
2935
*/
30-
const ProductActions = ({ className = "" }) => {
36+
const ProductActions = ({ product, className = "" }) => {
37+
const dispatch = useDispatch();
38+
3139
return (
3240
<div
3341
className={`absolute top-full left-0 flex h-auto w-full flex-col items-end gap-y-5 bg-white pt-2 pr-7.5 text-base transition-transform duration-300 ease-in-out group-focus-within:-translate-y-full group-hover:-translate-y-full ${className}`}
@@ -38,7 +46,15 @@ const ProductActions = ({ className = "" }) => {
3846
<ProductActionButton icon={<FaArrowsRotate />}>
3947
Compare
4048
</ProductActionButton>
41-
<ProductActionButton icon={<FaCartShopping />}>
49+
<ProductActionButton
50+
icon={<FaCartShopping />}
51+
onClick={() => {
52+
if (product) {
53+
dispatch(addToCart(product));
54+
toast.success(`${product.name} added to cart!`);
55+
}
56+
}}
57+
>
4258
Add to Cart
4359
</ProductActionButton>
4460
</div>

‎src/components/ProductCard.jsx‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,25 @@ import ProductActions from "./ProductActions";
88
*
99
* @component
1010
* @param {Object} props
11+
* @param {string|number} [props.id] - Product ID.
1112
* @param {string} props.img - URL (or import path) of the product image.
1213
* @param {string} props.name - Product name shown as the card title.
1314
* @param {string|number} props.price - Price label displayed alongside the name.
1415
* @param {string} props.color - Color / variant description shown below the name.
1516
* @param {boolean} [props.badge=true] - Whether to render the {@link ProductBadge}.
1617
* @param {string} [props.badgeText="New"] - Text displayed inside the badge.
1718
* @returns {JSX.Element}
18-
*
19-
* @example
20-
* <ProductCard
21-
* img="/images/watch.png"
22-
* name="Classic Watch"
23-
* price="$120"
24-
* color="Midnight Black"
25-
* badge={true}
26-
* badgeText="Sale"
27-
* />
2819
*/
29-
const ProductCard = ({ img, name, price, color, badge = true, badgeText="New" }) => {
20+
const ProductCard = ({ id, img, name, price, color, badge = true, badgeText="New" }) => {
21+
const productId = id || name;
3022
return (
3123
<div>
3224
<div className="group relative overflow-hidden">
3325
<img src={img} alt={name} />
3426
{badge && (
3527
<ProductBadge label={badgeText} className="absolute top-5 left-5" />
3628
)}
37-
<ProductActions />
29+
<ProductActions product={{ id: productId, img, name, price, color }} />
3830
</div>
3931
<div className="pt-4.5">
4032
<Flex className="items-baseline justify-between gap-x-4">
@@ -47,4 +39,4 @@ const ProductCard = ({ img, name, price, color, badge = true, badgeText="New" })
4739
);
4840
};
4941

50-
export default ProductCard;
42+
export default ProductCard;

0 commit comments

Comments
 (0)