feat: add cart on front
This commit is contained in:
@@ -42,8 +42,8 @@ export default function Cart() {
|
||||
>
|
||||
<span className="font-medium ">{ci.item.name}</span>
|
||||
<span>
|
||||
{ci.quanitity} x {ci.item.price} ={" "}
|
||||
{ci.quantity * ci.item.price}
|
||||
{ci.quantity} x {ci.item.price}р. ={" "}
|
||||
{ci.quantity * ci.item.price}р.
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
|
||||
@@ -34,10 +34,27 @@ export default function Shop() {
|
||||
});
|
||||
}, [items, activeCategory]);
|
||||
|
||||
const handleAddToCart = (product, selectedWeight) => {
|
||||
console.log(`Добавлен товар ${product.name}, Вес ${selectedWeight} кг`);
|
||||
const handleAddToCart = async (product, selectedWeight) => {
|
||||
try {
|
||||
await api.addToCart({
|
||||
item_id: product.id,
|
||||
quanity: selectedWeight,
|
||||
});
|
||||
alert(`${product.name} добавлен в корзину`);
|
||||
} catch (err) {
|
||||
console.error("Ошибка при добавлении товара в корзину", err);
|
||||
alert("Не удалось добавить товар в корзину");
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return(
|
||||
<PageLayout>
|
||||
<p className="text-white grow">Загрузка...</p>
|
||||
</PageLayout>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<PageLayout>
|
||||
<main className="px-6 md:px-16 grow w-full ">
|
||||
|
||||
Reference in New Issue
Block a user