2026-05-22 17:11:56 +00:00
|
|
|
import { FormEvent, useMemo, useState } from 'react';
|
|
|
|
|
import { Link, useSearchParams } from 'react-router-dom';
|
|
|
|
|
import { useMutation, useQueries, useQueryClient } from '@tanstack/react-query';
|
2026-06-02 07:12:49 +00:00
|
|
|
import type { DiseaseSlug, DiagnosisStatus } from '@zeavis/shared';
|
2026-05-22 17:11:56 +00:00
|
|
|
import { Button } from '@/components/ui/button';
|
|
|
|
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
|
|
|
|
import { DiagnosisStatusBadge } from '@/components/diagnosis-status-badge';
|
|
|
|
|
import { apiClient } from '@/lib/api-client';
|
|
|
|
|
|
|
|
|
|
export function ExpertReviewsPage() {
|
|
|
|
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
|
|
|
const selectedId = searchParams.get('diagnosis');
|
|
|
|
|
const [verdict, setVerdict] = useState<'verified' | 'corrected'>('verified');
|
|
|
|
|
const [correctedDiseaseSlug, setCorrectedDiseaseSlug] = useState<DiseaseSlug | ''>('');
|
|
|
|
|
const [notes, setNotes] = useState('');
|
|
|
|
|
const queryClient = useQueryClient();
|
|
|
|
|
|
|
|
|
|
const [reviewsQuery, diseasesQuery] = useQueries({
|
|
|
|
|
queries: [
|
|
|
|
|
{ queryKey: ['expert-reviews'], queryFn: () => apiClient.getExpertReviews() },
|
|
|
|
|
{ queryKey: ['diseases'], queryFn: () => apiClient.getDiseases() },
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const reviews = reviewsQuery.data || [];
|
|
|
|
|
const diseases = diseasesQuery.data || [];
|
|
|
|
|
const selected = useMemo(() => reviews.find((item) => item.id === selectedId) ?? reviews[0] ?? null, [reviews, selectedId]);
|
|
|
|
|
|
|
|
|
|
const mutation = useMutation({
|
|
|
|
|
mutationFn: () => apiClient.reviewDiagnosis(selected!.id, {
|
|
|
|
|
verdict,
|
|
|
|
|
correctedDiseaseSlug: verdict === 'corrected' ? correctedDiseaseSlug || undefined : undefined,
|
|
|
|
|
notes,
|
|
|
|
|
}),
|
|
|
|
|
onSuccess: () => {
|
|
|
|
|
setNotes('');
|
|
|
|
|
setVerdict('verified');
|
|
|
|
|
setCorrectedDiseaseSlug('');
|
|
|
|
|
queryClient.invalidateQueries({ queryKey: ['expert-reviews'] });
|
|
|
|
|
queryClient.invalidateQueries({ queryKey: ['dashboard-summary'] });
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
async function handleSubmit(event: FormEvent<HTMLFormElement>) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
if (!selected) return;
|
|
|
|
|
await mutation.mutateAsync();
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-02 07:12:49 +00:00
|
|
|
const statusLabel = (status: DiagnosisStatus) => {
|
|
|
|
|
switch (status) {
|
|
|
|
|
case 'ai_verified': return 'Terverifikasi AI';
|
|
|
|
|
case 'needs_review': return 'Menunggu Review';
|
|
|
|
|
case 'expert_verified': return 'Diverifikasi Pakar';
|
|
|
|
|
case 'expert_corrected': return 'Dikoreksi Pakar';
|
|
|
|
|
case 'failed': return 'Gagal';
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-05-22 17:11:56 +00:00
|
|
|
return (
|
|
|
|
|
<main className="min-h-screen bg-background">
|
|
|
|
|
<header className="border-b bg-card">
|
|
|
|
|
<div className="mx-auto flex max-w-7xl items-center justify-between p-6">
|
2026-06-02 07:12:49 +00:00
|
|
|
<div>
|
|
|
|
|
<p className="text-sm font-medium text-primary">Review Pakar</p>
|
|
|
|
|
<h1 className="text-2xl font-bold">Diagnosis Menunggu Review</h1>
|
|
|
|
|
</div>
|
2026-05-22 17:11:56 +00:00
|
|
|
<Link to="/dashboard">
|
|
|
|
|
<Button variant="outline">Dashboard</Button>
|
|
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
<div className="mx-auto max-w-7xl p-6">
|
|
|
|
|
<div className="grid gap-6 lg:grid-cols-3">
|
|
|
|
|
{/* Left: List of reviews */}
|
|
|
|
|
<div className="space-y-3">
|
|
|
|
|
<div className="flex items-center justify-between">
|
2026-06-02 07:12:49 +00:00
|
|
|
<h2 className="font-semibold">Daftar Diagnosis</h2>
|
2026-05-22 17:11:56 +00:00
|
|
|
<span className="rounded-full bg-muted px-2.5 py-0.5 text-xs font-medium">{reviews.length}</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="space-y-2">
|
2026-05-22 17:17:24 +00:00
|
|
|
{reviewsQuery.isPending || diseasesQuery.isPending ? (
|
2026-06-02 07:12:49 +00:00
|
|
|
<p className="text-sm text-muted-foreground">Memuat diagnosis...</p>
|
2026-05-22 17:17:24 +00:00
|
|
|
) : reviews.length === 0 ? (
|
2026-06-02 07:12:49 +00:00
|
|
|
<p className="text-sm text-muted-foreground">Tidak ada diagnosis yang menunggu review</p>
|
2026-05-22 17:11:56 +00:00
|
|
|
) : (
|
|
|
|
|
reviews.map((review) => (
|
|
|
|
|
<button
|
|
|
|
|
key={review.id}
|
2026-05-22 17:17:24 +00:00
|
|
|
type="button"
|
2026-05-22 17:11:56 +00:00
|
|
|
onClick={() => setSearchParams({ diagnosis: review.id })}
|
|
|
|
|
className={`w-full text-left transition ${
|
|
|
|
|
selected?.id === review.id
|
|
|
|
|
? 'ring-2 ring-primary'
|
|
|
|
|
: 'hover:border-primary'
|
|
|
|
|
}`}
|
|
|
|
|
>
|
|
|
|
|
<Card className="transition hover:border-primary">
|
|
|
|
|
<CardContent className="flex gap-3 p-3">
|
|
|
|
|
<img
|
|
|
|
|
src={review.imageUrl}
|
|
|
|
|
alt="Daun jagung"
|
|
|
|
|
className="h-20 w-20 rounded-lg object-cover"
|
|
|
|
|
/>
|
|
|
|
|
<div className="min-w-0 flex-1 space-y-1">
|
|
|
|
|
<div className="flex flex-wrap items-center justify-between gap-1">
|
|
|
|
|
<h3 className="text-sm font-semibold">{review.disease?.commonName ?? 'Diagnosis gagal'}</h3>
|
|
|
|
|
<DiagnosisStatusBadge status={review.status} className="text-xs" />
|
|
|
|
|
</div>
|
|
|
|
|
<p className="text-xs text-muted-foreground">
|
|
|
|
|
{review.confidence === null ? 'Tidak ada confidence' : `${(review.confidence * 100).toFixed(1)}%`}
|
|
|
|
|
</p>
|
|
|
|
|
<p className="text-xs text-muted-foreground">{new Date(review.createdAt).toLocaleString('id-ID')}</p>
|
|
|
|
|
</div>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
</button>
|
|
|
|
|
))
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Right: Detail and form */}
|
|
|
|
|
<div className="lg:col-span-2 space-y-6">
|
2026-05-22 17:17:24 +00:00
|
|
|
{reviewsQuery.isPending || diseasesQuery.isPending ? (
|
|
|
|
|
<Card>
|
|
|
|
|
<CardContent className="p-6 text-center text-muted-foreground">
|
2026-06-02 07:12:49 +00:00
|
|
|
Memuat diagnosis...
|
2026-05-22 17:17:24 +00:00
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
) : selected ? (
|
2026-05-22 17:11:56 +00:00
|
|
|
<>
|
|
|
|
|
{/* Detail card */}
|
|
|
|
|
<Card>
|
|
|
|
|
<CardHeader>
|
|
|
|
|
<CardTitle>{selected.disease?.commonName ?? 'Diagnosis gagal'}</CardTitle>
|
|
|
|
|
<CardDescription>
|
|
|
|
|
{new Date(selected.createdAt).toLocaleString('id-ID')}
|
|
|
|
|
</CardDescription>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent className="space-y-4">
|
|
|
|
|
<img
|
|
|
|
|
src={selected.imageUrl}
|
2026-05-22 17:17:24 +00:00
|
|
|
alt={`Gambar daun jagung untuk ${selected.disease?.commonName ?? 'diagnosis'}`}
|
2026-05-22 17:11:56 +00:00
|
|
|
className="h-64 w-full rounded-lg object-cover"
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<span className="text-sm font-medium">Status</span>
|
|
|
|
|
<DiagnosisStatusBadge status={selected.status} />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<span className="text-sm font-medium">Confidence</span>
|
|
|
|
|
<span className="text-sm">
|
|
|
|
|
{selected.confidence === null ? 'N/A' : `${(selected.confidence * 100).toFixed(1)}%`}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Top predictions */}
|
|
|
|
|
{selected.predictions.length > 0 && (
|
|
|
|
|
<div className="space-y-2">
|
2026-06-02 07:12:49 +00:00
|
|
|
<h4 className="text-sm font-medium">Prediksi Teratas</h4>
|
2026-05-22 17:11:56 +00:00
|
|
|
<div className="space-y-1">
|
|
|
|
|
{selected.predictions.map((pred) => (
|
|
|
|
|
<div key={pred.id} className="flex items-center justify-between text-sm">
|
|
|
|
|
<span className="text-muted-foreground">{pred.modelLabel}</span>
|
|
|
|
|
<span className="font-medium">{(pred.confidence * 100).toFixed(1)}%</span>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
{/* Review form */}
|
|
|
|
|
<Card>
|
|
|
|
|
<CardHeader>
|
2026-06-02 07:12:49 +00:00
|
|
|
<CardTitle className="text-lg">Review Pakar</CardTitle>
|
2026-05-22 17:11:56 +00:00
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent>
|
|
|
|
|
<form onSubmit={handleSubmit} className="space-y-4">
|
|
|
|
|
{/* Verdict selection */}
|
|
|
|
|
<div className="space-y-2">
|
2026-06-02 07:12:49 +00:00
|
|
|
<label className="text-sm font-medium">Keputusan</label>
|
2026-05-22 17:11:56 +00:00
|
|
|
<div className="flex gap-3">
|
2026-05-22 17:17:24 +00:00
|
|
|
<label htmlFor="verdict-verified" className="flex items-center gap-2">
|
2026-05-22 17:11:56 +00:00
|
|
|
<input
|
2026-05-22 17:17:24 +00:00
|
|
|
id="verdict-verified"
|
2026-05-22 17:11:56 +00:00
|
|
|
type="radio"
|
|
|
|
|
name="verdict"
|
|
|
|
|
value="verified"
|
|
|
|
|
checked={verdict === 'verified'}
|
2026-05-22 17:17:24 +00:00
|
|
|
onChange={(e) => {
|
|
|
|
|
setVerdict(e.target.value as 'verified' | 'corrected');
|
|
|
|
|
setCorrectedDiseaseSlug('');
|
|
|
|
|
}}
|
2026-05-22 17:11:56 +00:00
|
|
|
className="h-4 w-4"
|
|
|
|
|
/>
|
2026-06-02 07:12:49 +00:00
|
|
|
<span className="text-sm">Terverifikasi</span>
|
2026-05-22 17:11:56 +00:00
|
|
|
</label>
|
2026-05-22 17:17:24 +00:00
|
|
|
<label htmlFor="verdict-corrected" className="flex items-center gap-2">
|
2026-05-22 17:11:56 +00:00
|
|
|
<input
|
2026-05-22 17:17:24 +00:00
|
|
|
id="verdict-corrected"
|
2026-05-22 17:11:56 +00:00
|
|
|
type="radio"
|
|
|
|
|
name="verdict"
|
|
|
|
|
value="corrected"
|
|
|
|
|
checked={verdict === 'corrected'}
|
|
|
|
|
onChange={(e) => setVerdict(e.target.value as 'verified' | 'corrected')}
|
|
|
|
|
className="h-4 w-4"
|
|
|
|
|
/>
|
2026-06-02 07:12:49 +00:00
|
|
|
<span className="text-sm">Dikoreksi</span>
|
2026-05-22 17:11:56 +00:00
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Disease selection (only if corrected) */}
|
|
|
|
|
{verdict === 'corrected' && (
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<label htmlFor="disease" className="text-sm font-medium">
|
2026-06-02 07:12:49 +00:00
|
|
|
Penyakit yang Benar
|
2026-05-22 17:11:56 +00:00
|
|
|
</label>
|
|
|
|
|
<select
|
|
|
|
|
id="disease"
|
|
|
|
|
value={correctedDiseaseSlug}
|
|
|
|
|
onChange={(e) => setCorrectedDiseaseSlug(e.target.value as DiseaseSlug | '')}
|
2026-05-22 17:17:24 +00:00
|
|
|
required={verdict === 'corrected'}
|
2026-05-22 17:11:56 +00:00
|
|
|
className="w-full rounded-md border border-border bg-background px-3 py-2 text-sm"
|
|
|
|
|
>
|
2026-06-02 07:12:49 +00:00
|
|
|
<option value="">Pilih penyakit...</option>
|
2026-05-22 17:11:56 +00:00
|
|
|
{diseases.map((disease) => (
|
|
|
|
|
<option key={disease.slug} value={disease.slug}>
|
|
|
|
|
{disease.commonName}
|
|
|
|
|
</option>
|
|
|
|
|
))}
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* Notes */}
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<label htmlFor="notes" className="text-sm font-medium">
|
2026-06-02 07:12:49 +00:00
|
|
|
Catatan <span className="text-red-500">*</span>
|
2026-05-22 17:11:56 +00:00
|
|
|
</label>
|
|
|
|
|
<textarea
|
|
|
|
|
id="notes"
|
|
|
|
|
value={notes}
|
|
|
|
|
onChange={(e) => setNotes(e.target.value)}
|
2026-06-02 07:12:49 +00:00
|
|
|
placeholder="Tulis catatan review Anda..."
|
2026-05-22 17:11:56 +00:00
|
|
|
required
|
|
|
|
|
className="w-full rounded-md border border-border bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-primary"
|
|
|
|
|
rows={4}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Submit button */}
|
|
|
|
|
<Button
|
|
|
|
|
type="submit"
|
|
|
|
|
disabled={mutation.isPending || (verdict === 'corrected' && !correctedDiseaseSlug) || !notes.trim()}
|
|
|
|
|
className="w-full"
|
|
|
|
|
>
|
2026-06-02 07:12:49 +00:00
|
|
|
{mutation.isPending ? 'Mengirim...' : 'Kirim Review'}
|
2026-05-22 17:11:56 +00:00
|
|
|
</Button>
|
|
|
|
|
|
|
|
|
|
{mutation.isError && (
|
|
|
|
|
<p className="text-sm text-red-500">
|
2026-06-02 07:12:49 +00:00
|
|
|
Error: {mutation.error instanceof Error ? mutation.error.message : 'Terjadi kesalahan'}
|
2026-05-22 17:11:56 +00:00
|
|
|
</p>
|
|
|
|
|
)}
|
|
|
|
|
</form>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<Card>
|
|
|
|
|
<CardContent className="p-6 text-center text-muted-foreground">
|
2026-06-02 07:12:49 +00:00
|
|
|
Tidak ada diagnosis yang tersedia untuk review
|
2026-05-22 17:11:56 +00:00
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</main>
|
|
|
|
|
);
|
|
|
|
|
}
|