ehsan-dashboards/dashboards/VPN_chanel/frontend/app/feedback/page.tsx

160 lines
7.5 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 React, { useState, useEffect } from 'react';
import { BrainCircuit, RefreshCw, GitCompare, ArrowLeftRight, CheckCircle2, AlertOctagon } from 'lucide-react';
import { InfoTooltip } from '@/components/InfoTooltip';
const API_BASE = process.env.NEXT_PUBLIC_API_URL || '';
interface FeedbackLog {
id: string;
draft_id: string;
original_ai_text: string;
final_human_text: string;
diff_analysis: {
similarity_ratio?: number;
category?: string;
summary?: string;
};
rejection_reason: string | null;
created_at: string;
}
export default function FeedbackPage() {
const [logs, setLogs] = useState<FeedbackLog[]>([]);
const [loading, setLoading] = useState(true);
const fetchLogs = async () => {
setLoading(true);
try {
const res = await fetch(`${API_BASE}/api/v1/feedback-logs`);
if (res.ok) {
const data = await res.json();
setLogs(data);
}
} catch (err) {
console.error('Failed to load feedback logs', err);
} finally {
setLoading(false);
}
};
useEffect(() => {
fetchLogs();
}, []);
return (
<div className="max-w-7xl mx-auto space-y-8" dir="rtl">
{/* Header */}
<div className="bg-slate-900 border border-slate-800 p-6 rounded-3xl shadow-xl flex flex-col md:flex-row md:items-center justify-between gap-4">
<div>
<div className="flex items-center gap-2">
<h1 className="text-2xl font-black text-white tracking-tight">حافظه یادگیری و دیف‌های انسانی هوش مصنوعی</h1>
<InfoTooltip
title="Active Learning & Prompt Memory"
text="هر ویرایش سردبیر در این بخش تحلیل شده و تفاوت‌های نگارشی استخراج می‌گردد. در چرخه‌های بعدی، این نکات به پرامپت Agent B تزریق می‌شوند."
/>
</div>
<p className="text-xs text-slate-400 mt-1">
سیستم خودبه‌خود با ویرایش‌های شما یاد می‌گیرد و کپی‌رایتینگ به مرور به سلیقه دقیق برند نزدیک‌تر می‌شود.
</p>
</div>
<button
onClick={fetchLogs}
className="flex items-center gap-2 px-4 py-2.5 bg-slate-800 hover:bg-slate-700 text-slate-200 rounded-xl text-xs font-medium transition"
>
<RefreshCw className={`w-4 h-4 ${loading ? 'animate-spin' : ''}`} />
بروزرسانی لاگ‌ها
</button>
</div>
{/* Logs List */}
{loading ? (
<div className="text-center py-24 text-slate-500 text-xs">در حال بارگذاری لاگ‌های یادگیری...</div>
) : logs.length === 0 ? (
<div className="text-center py-24 bg-slate-900/50 border border-slate-800/80 rounded-3xl p-8">
<BrainCircuit className="w-12 h-12 text-slate-600 mx-auto mb-3" />
<h3 className="text-sm font-semibold text-slate-300">هنوز لاگ ویرایشی ثبت نشده است</h3>
<p className="text-xs text-slate-500 mt-1 max-w-sm mx-auto">
هنگامی که در صفحه «صندوق بررسی»، متنی را ویرایش کرده و ذخیره کنید، تحلیل دیف متنی در اینجا نمایش داده می‌شود.
</p>
</div>
) : (
<div className="space-y-6">
{logs.map((log) => (
<div key={log.id} className="bg-slate-900/90 border border-slate-800 rounded-2xl p-6 shadow-xl">
<div className="flex flex-wrap items-center justify-between gap-4 pb-4 border-b border-slate-800">
<div className="flex items-center gap-2.5">
<span className="p-1.5 bg-indigo-500/10 text-indigo-400 rounded-lg">
<GitCompare className="w-4 h-4" />
</span>
<span className="text-xs font-semibold text-slate-200">
شناسه لاگ: {log.id.slice(0, 8)}...
</span>
<InfoTooltip text="شناسه یکتای تغییرات ثبت‌شده در جدول feedback_logs." />
{log.diff_analysis?.summary && (
<span className="px-2.5 py-0.5 bg-slate-800 text-indigo-300 rounded-md text-[11px] border border-slate-700">
{log.diff_analysis.summary}
</span>
)}
</div>
<div className="flex items-center gap-3 text-xs">
{log.diff_analysis?.similarity_ratio !== undefined && (
<div className="flex items-center gap-1 bg-slate-800 px-2.5 py-1 rounded-md text-slate-300">
<span>شباهت:</span>
<span className="font-mono font-bold text-indigo-400">
{Math.round(log.diff_analysis.similarity_ratio * 100)}%
</span>
<InfoTooltip text="ضریب شباهت متنی بر مبنای الگوریتم توالی‌یابی کاراکتری (difflib SequenceMatcher)." />
</div>
)}
<span className="text-slate-500 font-mono">
{new Date(log.created_at).toLocaleString('fa-IR')}
</span>
</div>
</div>
{log.rejection_reason ? (
<div className="mt-4 p-4 bg-rose-500/10 border border-rose-500/30 rounded-xl text-xs text-rose-300 flex items-center gap-2">
<AlertOctagon className="w-4 h-4" />
<span>دلیل رد پست: {log.rejection_reason}</span>
</div>
) : (
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 mt-5">
{/* Original AI */}
<div className="bg-slate-950/60 border border-slate-800/60 rounded-xl p-4">
<div className="flex items-center justify-between mb-2">
<span className="text-[11px] font-semibold text-slate-400">متن اولیه هوش مصنوعی (قبل از ویرایش)</span>
<InfoTooltip text="خروجی مستقیم مدل بدون مداخله انسانی." />
</div>
<div className="text-xs text-slate-400 leading-relaxed whitespace-pre-wrap max-h-48 overflow-y-auto">
{log.original_ai_text}
</div>
</div>
{/* Final Human Edited */}
<div className="bg-slate-950/90 border border-emerald-500/30 rounded-xl p-4">
<div className="flex items-center justify-between mb-2">
<span className="text-[11px] font-semibold text-emerald-400 flex items-center gap-1">
<CheckCircle2 className="w-3.5 h-3.5" />
متن نهایی ویراستار انسانی (الگوی مطلوب برند)
</span>
<InfoTooltip text="متنی که سردبیر نهایی کرده و جهت آموزش به عنوان نمونه پرامپت تزریق می‌شود." />
</div>
<div className="text-xs text-slate-200 leading-relaxed whitespace-pre-wrap max-h-48 overflow-y-auto">
{log.final_human_text}
</div>
</div>
</div>
)}
</div>
))}
</div>
)}
</div>
);
}