import { createSignal, onMount, Show } from "solid-js"; import ReviewForm from "./ReviewForm"; interface ToastMessage { type: "success" | "error"; message: string; } interface User { id: string; name: string; email: string; avatar?: string; } export default function ReviewFormContainer() { const [isAuthenticated, setIsAuthenticated] = createSignal(false); const [currentUser, setCurrentUser] = createSignal(undefined); const [isLoading, setIsLoading] = createSignal(true); const [toast, setToast] = createSignal(null); const showToast = (message: ToastMessage): void => { setToast(message); setTimeout(() => setToast(null), 3000); }; onMount(async () => { try { const response = await fetch("/api/auth/me", { method: "GET", credentials: "include", }); const data = await response.json(); if (data.authenticated && data.user) { setIsAuthenticated(true); setCurrentUser({ id: data.user.id, name: data.user.name || "Пользователь", email: data.user.email, avatar: data.user.avatar, }); } } catch (error) { console.error("[ReviewForm] Ошибка проверки авторизации:", error); } finally { setIsLoading(false); } }); const handleSubmit = async (data: { name: string; surname: string; profession: string; rating: number; text: string; }) => { try { const response = await fetch("/api/reviews", { method: "POST", headers: { "Content-Type": "application/json" }, credentials: "include", body: JSON.stringify({ name: data.name, surname: data.surname, profession: data.profession, rating: data.rating, text: data.text, }), }); if (!response.ok) { const errorData = await response.json(); throw new Error(errorData.error || "Failed to create review"); } showToast({ type: "success", message: "Спасибо! Ваш отзыв отправлен на модерацию." }); } catch (error) { console.error("[ReviewForm] Ошибка создания отзыва:", error); showToast({ type: "error", message: "Не удалось отправить отзыв. Попробуйте позже." }); } }; return ( <> {(t) => (
{t().message}
)}

Загрузка...

Авторизуйтесь, чтобы оставить отзыв

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

Войти в кабинет

Нет аккаунта?{" "} Зарегистрироваться

}>
); }