This commit is contained in:
@@ -32,7 +32,7 @@ export default function MigrationErrorsPage() {
|
||||
const res = await migrationService.getErrors({ limit: 100 });
|
||||
setItems(res.items);
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch errors", error);
|
||||
// Failed to fetch errors - loading state handles display
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
} from "@/components/ui/table";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { format } from "date-fns";
|
||||
@@ -41,7 +42,7 @@ export default function MigrationReviewQueuePage() {
|
||||
setItems(res.items);
|
||||
setSelectedIds([]); // reset selection on fetch
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch queue", error);
|
||||
// Failed to fetch queue - loading state handles display
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -56,7 +57,7 @@ export default function MigrationReviewQueuePage() {
|
||||
};
|
||||
|
||||
const handleToggleSelect = (id: number) => {
|
||||
setSelectedIds((prev) =>
|
||||
setSelectedIds((prev) =>
|
||||
prev.includes(id) ? prev.filter((i) => i !== id) : [...prev, id]
|
||||
);
|
||||
};
|
||||
@@ -65,7 +66,7 @@ export default function MigrationReviewQueuePage() {
|
||||
if (selectedIds.length === 0) return;
|
||||
try {
|
||||
setSubmitting(true);
|
||||
|
||||
|
||||
const batchItems = items
|
||||
.filter((i) => selectedIds.includes(i.id))
|
||||
.map((item) => ({
|
||||
@@ -94,11 +95,10 @@ export default function MigrationReviewQueuePage() {
|
||||
{ items: batchItems, batchId },
|
||||
batchId
|
||||
);
|
||||
|
||||
|
||||
fetchData();
|
||||
} catch (error) {
|
||||
console.error("Batch commit failed", error);
|
||||
alert("Batch commit failed. See console for details.");
|
||||
toast.error("Batch commit failed.");
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
@@ -115,12 +115,12 @@ export default function MigrationReviewQueuePage() {
|
||||
</div>
|
||||
<div className="flex items-center gap-4">
|
||||
{selectedIds.length > 0 && (
|
||||
<Button
|
||||
variant="default"
|
||||
onClick={handleBatchApprove}
|
||||
<Button
|
||||
variant="default"
|
||||
onClick={handleBatchApprove}
|
||||
disabled={submitting}
|
||||
>
|
||||
<CheckSquareIcon className="mr-2 h-4 w-4" />
|
||||
<CheckSquareIcon className="mr-2 h-4 w-4" />
|
||||
{submitting ? "Processing..." : `Batch Approve (${selectedIds.length})`}
|
||||
</Button>
|
||||
)}
|
||||
@@ -158,7 +158,7 @@ export default function MigrationReviewQueuePage() {
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="w-[50px]">
|
||||
<Checkbox
|
||||
<Checkbox
|
||||
checked={items.length > 0 && selectedIds.length === items.length}
|
||||
onCheckedChange={handleToggleSelectAll}
|
||||
aria-label="Select all"
|
||||
@@ -176,7 +176,7 @@ export default function MigrationReviewQueuePage() {
|
||||
{items.map((item) => (
|
||||
<TableRow key={item.id}>
|
||||
<TableCell>
|
||||
<Checkbox
|
||||
<Checkbox
|
||||
checked={selectedIds.includes(item.id)}
|
||||
onCheckedChange={() => handleToggleSelect(item.id)}
|
||||
aria-label={`Select item ${item.id}`}
|
||||
@@ -185,14 +185,14 @@ export default function MigrationReviewQueuePage() {
|
||||
<TableCell className="font-medium">{item.documentNumber}</TableCell>
|
||||
<TableCell>{item.aiSuggestedCategory || "Unknown"}</TableCell>
|
||||
<TableCell>
|
||||
<Badge
|
||||
<Badge
|
||||
variant={
|
||||
!item.aiConfidence
|
||||
? "destructive"
|
||||
: item.aiConfidence > 0.8
|
||||
? "default"
|
||||
: item.aiConfidence > 0.5
|
||||
? "secondary"
|
||||
!item.aiConfidence
|
||||
? "destructive"
|
||||
: item.aiConfidence > 0.8
|
||||
? "default"
|
||||
: item.aiConfidence > 0.5
|
||||
? "secondary"
|
||||
: "destructive"
|
||||
}
|
||||
>
|
||||
|
||||
@@ -87,7 +87,6 @@ export default function MigrationReviewPage() {
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to load queue item", error);
|
||||
toast.error("Failed to load queue item");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -100,7 +99,7 @@ export default function MigrationReviewPage() {
|
||||
try {
|
||||
setSubmitting(true);
|
||||
const issues = item.aiIssues || {};
|
||||
|
||||
|
||||
const payload = {
|
||||
document_number: values.document_number,
|
||||
subject: values.subject,
|
||||
@@ -123,12 +122,12 @@ export default function MigrationReviewPage() {
|
||||
// Mock idempotency key based on timestamp to ensure uniqueness per approval retry
|
||||
const idempotencyKey = `review-${item.id}-${Date.now()}`;
|
||||
await migrationService.approveQueueItem(item.id, payload, idempotencyKey);
|
||||
|
||||
|
||||
toast.success("Document approved and imported successfully");
|
||||
router.push("/admin/migration");
|
||||
} catch (error: any) {
|
||||
console.error("Failed to approve item", error);
|
||||
toast.error(error?.response?.data?.message || "Failed to approve and import");
|
||||
} catch (error: unknown) {
|
||||
const err = error as { response?: { data?: { message?: string } } };
|
||||
toast.error(err?.response?.data?.message || "Failed to approve and import");
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
@@ -142,8 +141,7 @@ export default function MigrationReviewPage() {
|
||||
await migrationService.rejectQueueItem(item.id);
|
||||
toast.success("Document rejected");
|
||||
router.push("/admin/migration");
|
||||
} catch (error: any) {
|
||||
console.error("Failed to reject item", error);
|
||||
} catch (error: unknown) {
|
||||
toast.error("Failed to reject document");
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
@@ -158,7 +156,7 @@ export default function MigrationReviewPage() {
|
||||
return <div className="py-10 text-center text-red-500">Document not found</div>;
|
||||
}
|
||||
|
||||
const pdfUrl = item.aiIssues?.source_file_path
|
||||
const pdfUrl = item.aiIssues?.source_file_path
|
||||
? migrationService.getStagingFileUrl(item.aiIssues.source_file_path)
|
||||
: null;
|
||||
|
||||
@@ -240,7 +238,7 @@ export default function MigrationReviewPage() {
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
@@ -343,9 +341,9 @@ export default function MigrationReviewPage() {
|
||||
<XCircleIcon className="w-4 h-4 mr-2" />
|
||||
Reject
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
className="flex-1 bg-green-600 hover:bg-green-700 text-white"
|
||||
<Button
|
||||
type="submit"
|
||||
className="flex-1 bg-green-600 hover:bg-green-700 text-white"
|
||||
disabled={submitting || item.status !== 'PENDING'}
|
||||
>
|
||||
<CheckCircleIcon className="w-4 h-4 mr-2" />
|
||||
|
||||
Reference in New Issue
Block a user