feat: add cart on front

This commit is contained in:
2026-06-23 20:38:41 +03:00
parent d9745d972a
commit 733e3f6208
5 changed files with 31 additions and 8 deletions
+2 -2
View File
@@ -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>
))}
+19 -2
View File
@@ -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 ">