"use client"; import { useState } from "react"; import { Check, MessageSquareText, ThumbsDown, ThumbsUp } from "lucide-react"; interface AnswerFeedbackProps { traceId: string; conversationId: string; } type Rating = "helpful" | "not_helpful"; export function AnswerFeedback({ traceId, conversationId }: AnswerFeedbackProps) { const [rating, setRating] = useState(null); const [comment, setComment] = useState(""); const [state, setState] = useState<"idle" | "saving" | "saved" | "error">("idle"); const choose = (next: Rating) => { setRating(next); setState("idle"); }; const submit = async () => { if (!rating || state === "saving") return; setState("saving"); try { const response = await fetch("/api/feedback", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ traceId, rating, comment, conversationId }), }); setState(response.ok ? "saved" : "error"); } catch { setState("error"); } }; if (state === "saved") { return (
Đã ghi nhận phản hồi. Cảm ơn anh/chị.
); } return (
Câu trả lời này có hữu ích không?
{rating && (