This repository has been archived on 2025-07-07. You can view files and clone it, but cannot push or open issues or pull requests.
Files
eternos/frontend/style/components/cart-summary.tsx
2025-02-16 11:17:40 +03:00

52 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client"
import { useCart } from "@/contexts/cart-context"
import { useAuth } from "@/contexts/auth-context"
import { Button } from "./ui/button"
import { useRouter } from "next/navigation"
export function CartSummary() {
const { items, getTotalItems, getTotalQuantity } = useCart()
const { isLoggedIn } = useAuth()
const router = useRouter()
const totalPrice = items.reduce((sum, item) => sum + item.price * item.quantity, 0)
const handleCheckout = () => {
if (!isLoggedIn) {
router.push('/login')
} else {
router.push('/checkout')
}
}
if (getTotalItems() === 0) {
return (
<div className="bg-white p-4 rounded-lg">
<h2 className="text-lg font-semibold mb-4">Ваша корзина</h2>
<p className="text-gray-500">В вашей корзине пока нет товаров</p>
</div>
)
}
return (
<div className="bg-white p-4 rounded-lg">
<h2 className="text-lg font-semibold mb-4">Ваша корзина</h2>
<div className="space-y-2 mb-4">
<div className="flex justify-between">
<span>Товары ({getTotalItems()} наименований, {getTotalQuantity()} шт.)</span>
<span>{totalPrice} </span>
</div>
</div>
<div className="flex justify-between text-lg font-bold mb-4">
<span>Итого</span>
<span>{totalPrice} </span>
</div>
{/* <Button className="w-full" size="lg" onClick={handleCheckout}>
{isLoggedIn ? "Перейти к оформлению" : "Войти для оформления"}
</Button> */}
</div>
)
}