chore: transfer repo
This commit is contained in:
62
components/products/AddToBoxButton.tsx
Normal file
62
components/products/AddToBoxButton.tsx
Normal file
@@ -0,0 +1,62 @@
|
||||
'use client';
|
||||
|
||||
import { Button } from "@/components/ui/Button";
|
||||
import { useAppDispatch } from "@/lib/redux/hooks";
|
||||
import { addToBox } from "@/lib/redux/slices/boxSlice";
|
||||
import { useState } from "react";
|
||||
|
||||
interface AddToBoxButtonProps {
|
||||
productId: string;
|
||||
name: string;
|
||||
price: number;
|
||||
image: string;
|
||||
variantId?: string;
|
||||
color?: string;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function AddToBoxButton({
|
||||
productId,
|
||||
name,
|
||||
price,
|
||||
image,
|
||||
variantId,
|
||||
color,
|
||||
className = ""
|
||||
}: AddToBoxButtonProps) {
|
||||
const dispatch = useAppDispatch();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const handleAddToBox = () => {
|
||||
if (isLoading) return;
|
||||
|
||||
setIsLoading(true);
|
||||
|
||||
dispatch(addToBox({
|
||||
id: productId,
|
||||
name,
|
||||
price,
|
||||
image,
|
||||
quantity: 1,
|
||||
variantId,
|
||||
color
|
||||
}));
|
||||
|
||||
// Add a small delay to simulate adding to cart for better UX
|
||||
setTimeout(() => {
|
||||
setIsLoading(false);
|
||||
}, 500);
|
||||
};
|
||||
|
||||
return (
|
||||
<Button
|
||||
onClick={handleAddToBox}
|
||||
disabled={isLoading}
|
||||
variant="primary"
|
||||
size="lg"
|
||||
className={`w-full ${className}`}
|
||||
>
|
||||
{isLoading ? "Dodaje se..." : "Dodaj u box"}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user