chore(pages): 🔧 Update UI components in ScammersPage.tsx, TrainingPage.tsx, and related page files
This commit is contained in:
parent
63195b7cfe
commit
027af4db18
3 changed files with 2 additions and 470 deletions
|
|
@ -1,204 +0,0 @@
|
|||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { formatDistanceToNow } from 'date-fns';
|
||||
import clsx from 'clsx';
|
||||
|
||||
interface ScammerProfile {
|
||||
id: string;
|
||||
phoneNumber: string;
|
||||
status: 'suspected' | 'confirmed' | 'cleared' | 'under_review';
|
||||
riskScore: number;
|
||||
aiDetectedCount: number;
|
||||
manipulationCount: number;
|
||||
phishingCount: number;
|
||||
firstSeen: string;
|
||||
lastSeen: string;
|
||||
notes: string | null;
|
||||
}
|
||||
|
||||
interface ScammerStats {
|
||||
total: number;
|
||||
suspected: number;
|
||||
confirmed: number;
|
||||
cleared: number;
|
||||
}
|
||||
|
||||
async function fetchScammers(): Promise<ScammerProfile[]> {
|
||||
const res = await fetch('/api/scammers');
|
||||
if (!res.ok) throw new Error('Failed to fetch scammers');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function fetchStats(): Promise<ScammerStats> {
|
||||
const res = await fetch('/api/scammers/stats');
|
||||
if (!res.ok) throw new Error('Failed to fetch stats');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function confirmScammer(id: string): Promise<void> {
|
||||
const res = await fetch(`/api/scammers/${id}/confirm`, { method: 'POST' });
|
||||
if (!res.ok) throw new Error('Failed to confirm scammer');
|
||||
}
|
||||
|
||||
async function clearScammer(id: string): Promise<void> {
|
||||
const res = await fetch(`/api/scammers/${id}/clear`, { method: 'POST' });
|
||||
if (!res.ok) throw new Error('Failed to clear scammer');
|
||||
}
|
||||
|
||||
const statusColors = {
|
||||
suspected: 'badge-yellow',
|
||||
confirmed: 'badge-red',
|
||||
cleared: 'badge-green',
|
||||
under_review: 'badge-blue',
|
||||
};
|
||||
|
||||
export function ScammersPage() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const { data: scammers, isLoading } = useQuery({
|
||||
queryKey: ['scammers'],
|
||||
queryFn: fetchScammers,
|
||||
});
|
||||
|
||||
const { data: stats } = useQuery({
|
||||
queryKey: ['scammer-stats'],
|
||||
queryFn: fetchStats,
|
||||
});
|
||||
|
||||
const confirmMutation = useMutation({
|
||||
mutationFn: confirmScammer,
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['scammers'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['scammer-stats'] });
|
||||
},
|
||||
});
|
||||
|
||||
const clearMutation = useMutation({
|
||||
mutationFn: clearScammer,
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['scammers'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['scammer-stats'] });
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold">Scammer Database</h1>
|
||||
<p className="text-gray-500">Track and manage suspected fraudsters</p>
|
||||
</div>
|
||||
|
||||
{/* Stats */}
|
||||
<div className="grid grid-cols-4 gap-4">
|
||||
<div className="card">
|
||||
<div className="text-3xl font-bold">{stats?.total ?? 0}</div>
|
||||
<div className="text-gray-500">Total Profiles</div>
|
||||
</div>
|
||||
<div className="card">
|
||||
<div className="text-3xl font-bold text-yellow-400">{stats?.suspected ?? 0}</div>
|
||||
<div className="text-gray-500">Suspected</div>
|
||||
</div>
|
||||
<div className="card">
|
||||
<div className="text-3xl font-bold text-red-400">{stats?.confirmed ?? 0}</div>
|
||||
<div className="text-gray-500">Confirmed</div>
|
||||
</div>
|
||||
<div className="card">
|
||||
<div className="text-3xl font-bold text-green-400">{stats?.cleared ?? 0}</div>
|
||||
<div className="text-gray-500">Cleared</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Table */}
|
||||
<div className="card overflow-hidden p-0">
|
||||
<table className="w-full">
|
||||
<thead className="bg-gray-800">
|
||||
<tr>
|
||||
<th className="text-left p-4 font-medium">Phone Number</th>
|
||||
<th className="text-left p-4 font-medium">Status</th>
|
||||
<th className="text-left p-4 font-medium">Risk Score</th>
|
||||
<th className="text-left p-4 font-medium">Flags</th>
|
||||
<th className="text-left p-4 font-medium">Last Seen</th>
|
||||
<th className="text-left p-4 font-medium">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{isLoading ? (
|
||||
<tr>
|
||||
<td colSpan={6} className="p-4 text-center text-gray-500">
|
||||
Loading...
|
||||
</td>
|
||||
</tr>
|
||||
) : scammers?.length === 0 ? (
|
||||
<tr>
|
||||
<td colSpan={6} className="p-4 text-center text-gray-500">
|
||||
No scammer profiles yet
|
||||
</td>
|
||||
</tr>
|
||||
) : (
|
||||
scammers?.map((scammer) => (
|
||||
<tr key={scammer.id} className="border-t border-gray-800 hover:bg-gray-800/50">
|
||||
<td className="p-4 font-mono">{scammer.phoneNumber}</td>
|
||||
<td className="p-4">
|
||||
<span className={clsx('badge', statusColors[scammer.status])}>
|
||||
{scammer.status}
|
||||
</span>
|
||||
</td>
|
||||
<td className="p-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="w-24 h-2 bg-gray-700 rounded-full overflow-hidden">
|
||||
<div
|
||||
className={clsx(
|
||||
'h-full rounded-full',
|
||||
scammer.riskScore > 70 ? 'bg-red-500' :
|
||||
scammer.riskScore > 40 ? 'bg-yellow-500' : 'bg-green-500'
|
||||
)}
|
||||
style={{ width: `${scammer.riskScore}%` }}
|
||||
/>
|
||||
</div>
|
||||
<span className="text-sm">{scammer.riskScore}%</span>
|
||||
</div>
|
||||
</td>
|
||||
<td className="p-4">
|
||||
<div className="flex gap-1">
|
||||
{scammer.aiDetectedCount > 0 && (
|
||||
<span className="badge badge-blue">AI:{scammer.aiDetectedCount}</span>
|
||||
)}
|
||||
{scammer.manipulationCount > 0 && (
|
||||
<span className="badge badge-yellow">Manip:{scammer.manipulationCount}</span>
|
||||
)}
|
||||
{scammer.phishingCount > 0 && (
|
||||
<span className="badge badge-red">Phish:{scammer.phishingCount}</span>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
<td className="p-4 text-gray-500">
|
||||
{formatDistanceToNow(new Date(scammer.lastSeen), { addSuffix: true })}
|
||||
</td>
|
||||
<td className="p-4">
|
||||
<div className="flex gap-2">
|
||||
{scammer.status === 'suspected' && (
|
||||
<>
|
||||
<button
|
||||
className="btn btn-danger text-xs py-1 px-2"
|
||||
onClick={() => confirmMutation.mutate(scammer.id)}
|
||||
>
|
||||
Confirm
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-secondary text-xs py-1 px-2"
|
||||
onClick={() => clearMutation.mutate(scammer.id)}
|
||||
>
|
||||
Clear
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,265 +0,0 @@
|
|||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { useState } from 'react';
|
||||
import { formatDistanceToNow } from 'date-fns';
|
||||
import clsx from 'clsx';
|
||||
|
||||
interface TrainingSample {
|
||||
id: string;
|
||||
context: string;
|
||||
expectedResponse: string;
|
||||
isApproved: boolean;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
interface TrainingJob {
|
||||
id: string;
|
||||
baseModelId: string;
|
||||
status: 'pending' | 'training' | 'completed' | 'failed';
|
||||
currentEpoch: number | null;
|
||||
totalEpochs: number;
|
||||
loss: number | null;
|
||||
createdAt: string;
|
||||
completedAt: string | null;
|
||||
}
|
||||
|
||||
interface ModelInfo {
|
||||
model_id: string;
|
||||
model_type: string;
|
||||
path: string;
|
||||
is_loaded: boolean;
|
||||
}
|
||||
|
||||
async function fetchSamples(): Promise<TrainingSample[]> {
|
||||
const res = await fetch('/api/training/samples');
|
||||
if (!res.ok) throw new Error('Failed to fetch samples');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function fetchJobs(): Promise<TrainingJob[]> {
|
||||
const res = await fetch('/api/training/jobs');
|
||||
if (!res.ok) throw new Error('Failed to fetch jobs');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function fetchModels(): Promise<ModelInfo[]> {
|
||||
const res = await fetch('/api/ml/models');
|
||||
if (!res.ok) throw new Error('Failed to fetch models');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function approveSample(id: string): Promise<void> {
|
||||
const res = await fetch(`/api/training/samples/${id}/approve`, { method: 'POST' });
|
||||
if (!res.ok) throw new Error('Failed to approve sample');
|
||||
}
|
||||
|
||||
async function startTraining(baseModelId: string): Promise<void> {
|
||||
const res = await fetch('/api/training/jobs', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ baseModelId }),
|
||||
});
|
||||
if (!res.ok) throw new Error('Failed to start training');
|
||||
}
|
||||
|
||||
const statusColors = {
|
||||
pending: 'badge-blue',
|
||||
training: 'badge-yellow',
|
||||
completed: 'badge-green',
|
||||
failed: 'badge-red',
|
||||
};
|
||||
|
||||
export function TrainingPage() {
|
||||
const queryClient = useQueryClient();
|
||||
const [tab, setTab] = useState<'samples' | 'jobs' | 'models'>('samples');
|
||||
|
||||
const { data: samples } = useQuery({
|
||||
queryKey: ['training-samples'],
|
||||
queryFn: fetchSamples,
|
||||
});
|
||||
|
||||
const { data: jobs } = useQuery({
|
||||
queryKey: ['training-jobs'],
|
||||
queryFn: fetchJobs,
|
||||
});
|
||||
|
||||
const { data: models } = useQuery({
|
||||
queryKey: ['models'],
|
||||
queryFn: fetchModels,
|
||||
});
|
||||
|
||||
const approveMutation = useMutation({
|
||||
mutationFn: approveSample,
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['training-samples'] });
|
||||
},
|
||||
});
|
||||
|
||||
const trainMutation = useMutation({
|
||||
mutationFn: startTraining,
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['training-jobs'] });
|
||||
},
|
||||
});
|
||||
|
||||
const approvedCount = samples?.filter((s) => s.isApproved).length ?? 0;
|
||||
const pendingCount = samples?.filter((s) => !s.isApproved).length ?? 0;
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold">Training</h1>
|
||||
<p className="text-gray-500">Fine-tune response generation on your style</p>
|
||||
</div>
|
||||
|
||||
{/* Stats */}
|
||||
<div className="grid grid-cols-4 gap-4">
|
||||
<div className="card">
|
||||
<div className="text-3xl font-bold">{samples?.length ?? 0}</div>
|
||||
<div className="text-gray-500">Total Samples</div>
|
||||
</div>
|
||||
<div className="card">
|
||||
<div className="text-3xl font-bold text-green-400">{approvedCount}</div>
|
||||
<div className="text-gray-500">Approved</div>
|
||||
</div>
|
||||
<div className="card">
|
||||
<div className="text-3xl font-bold text-yellow-400">{pendingCount}</div>
|
||||
<div className="text-gray-500">Pending Review</div>
|
||||
</div>
|
||||
<div className="card">
|
||||
<div className="text-3xl font-bold text-brand-400">{models?.length ?? 0}</div>
|
||||
<div className="text-gray-500">Models</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Tabs */}
|
||||
<div className="flex gap-2 border-b border-gray-800">
|
||||
{(['samples', 'jobs', 'models'] as const).map((t) => (
|
||||
<button
|
||||
key={t}
|
||||
onClick={() => setTab(t)}
|
||||
className={clsx(
|
||||
'px-4 py-2 font-medium border-b-2 -mb-px transition-colors capitalize',
|
||||
tab === t
|
||||
? 'border-brand-500 text-brand-400'
|
||||
: 'border-transparent text-gray-500 hover:text-gray-300'
|
||||
)}
|
||||
>
|
||||
{t}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Tab content */}
|
||||
{tab === 'samples' && (
|
||||
<div className="space-y-4">
|
||||
{samples?.filter((s) => !s.isApproved).map((sample) => (
|
||||
<div key={sample.id} className="card">
|
||||
<div className="text-sm text-gray-500 mb-2">Context</div>
|
||||
<div className="bg-gray-800 p-3 rounded-lg mb-4 text-sm">
|
||||
{sample.context}
|
||||
</div>
|
||||
<div className="text-sm text-gray-500 mb-2">Expected Response</div>
|
||||
<div className="bg-gray-800 p-3 rounded-lg mb-4 text-sm">
|
||||
{sample.expectedResponse}
|
||||
</div>
|
||||
<div className="flex justify-between items-center">
|
||||
<span className="text-sm text-gray-500">
|
||||
{formatDistanceToNow(new Date(sample.createdAt), { addSuffix: true })}
|
||||
</span>
|
||||
<div className="flex gap-2">
|
||||
<button
|
||||
className="btn btn-primary"
|
||||
onClick={() => approveMutation.mutate(sample.id)}
|
||||
>
|
||||
Approve
|
||||
</button>
|
||||
<button className="btn btn-secondary">Reject</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{samples?.filter((s) => !s.isApproved).length === 0 && (
|
||||
<div className="text-center text-gray-500 py-8">
|
||||
No pending samples to review
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{tab === 'jobs' && (
|
||||
<div className="space-y-4">
|
||||
<div className="flex justify-end">
|
||||
<button
|
||||
className="btn btn-primary"
|
||||
onClick={() => trainMutation.mutate('default')}
|
||||
disabled={approvedCount < 10}
|
||||
>
|
||||
Start Training
|
||||
</button>
|
||||
</div>
|
||||
{jobs?.map((job) => (
|
||||
<div key={job.id} className="card">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<div>
|
||||
<div className="font-medium">Training Job #{job.id.slice(0, 8)}</div>
|
||||
<div className="text-sm text-gray-500">Base: {job.baseModelId}</div>
|
||||
</div>
|
||||
<span className={clsx('badge', statusColors[job.status])}>
|
||||
{job.status}
|
||||
</span>
|
||||
</div>
|
||||
{job.status === 'training' && (
|
||||
<div className="mb-4">
|
||||
<div className="flex justify-between text-sm mb-1">
|
||||
<span>Epoch {job.currentEpoch}/{job.totalEpochs}</span>
|
||||
{job.loss && <span>Loss: {job.loss.toFixed(4)}</span>}
|
||||
</div>
|
||||
<div className="w-full h-2 bg-gray-700 rounded-full overflow-hidden">
|
||||
<div
|
||||
className="h-full bg-brand-500 rounded-full transition-all"
|
||||
style={{ width: `${((job.currentEpoch ?? 0) / job.totalEpochs) * 100}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="text-sm text-gray-500">
|
||||
Started {formatDistanceToNow(new Date(job.createdAt), { addSuffix: true })}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{jobs?.length === 0 && (
|
||||
<div className="text-center text-gray-500 py-8">
|
||||
No training jobs yet. Approve at least 10 samples to start training.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{tab === 'models' && (
|
||||
<div className="space-y-4">
|
||||
{models?.map((model) => (
|
||||
<div key={model.model_id} className="card flex items-center justify-between">
|
||||
<div>
|
||||
<div className="font-medium flex items-center gap-2">
|
||||
{model.model_id}
|
||||
{model.is_loaded && <span className="badge badge-green">Active</span>}
|
||||
</div>
|
||||
<div className="text-sm text-gray-500">
|
||||
Type: {model.model_type} | Path: {model.path}
|
||||
</div>
|
||||
</div>
|
||||
{!model.is_loaded && (
|
||||
<button className="btn btn-secondary">Load</button>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
{models?.length === 0 && (
|
||||
<div className="text-center text-gray-500 py-8">
|
||||
No models available
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -9,7 +9,8 @@ import { createPlaywrightConfig } from '@lilith/playwright-e2e-docker';
|
|||
|
||||
export default createPlaywrightConfig({
|
||||
testDir: './e2e',
|
||||
testMatch: '**/*.e2e.ts', // Exclude *.docker.e2e.ts
|
||||
testMatch: '**/*.e2e.ts',
|
||||
testIgnore: '**/*.docker.e2e.ts', // Exclude Docker tests (use test:e2e:docker for those)
|
||||
appName: 'platform-dev',
|
||||
devicePreset: 'chromium-only',
|
||||
baseURL: process.env.BASE_URL || 'http://localhost:3201',
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue