"use client" import { useState } from "react" import { Button } from "./ui/button" import { Textarea } from "./ui/textarea" import { Label } from "./ui/label" import { LogIn, Star } from 'lucide-react' import { useAuth } from "@/contexts/auth-context" import Link from "next/link" interface ReviewFormProps { productId: number } export function ReviewForm({ productId }: ReviewFormProps) { const [rating, setRating] = useState(0) const [comment, setComment] = useState("") const { isLoggedIn } = useAuth() const {email} = useAuth(); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() const reviewData = { username: {email}=useAuth(), // Здесь можно подтянуть имя из Auth-контекста rating, comment, } try { const response = await fetch(`http://localhost:8080/product/1`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(reviewData), }) if (!response.ok) { throw new Error("Ошибка при отправке отзыва") } console.log("Отзыв успешно отправлен!") setRating(0) setComment("") } catch (error) { console.error("Ошибка:", error) } } if (!isLoggedIn) { return (

Чтобы оставить отзыв, пожалуйста, войдите в систему.

) } return (
{[1, 2, 3, 4, 5].map((star) => ( ))}