"use client" import * as React from "react" import { CheckCircle2, XCircle } from "lucide-react" import type { ImportFailureRow } from "@garage/api" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/shared/components/ui/dialog" import { Button } from "@/shared/components/ui/button" import { ScrollArea } from "@/shared/components/ui/scroll-area" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/shared/components/ui/table" export type { ImportFailureRow } export type ImportResultsDialogProps = { open: boolean onOpenChange: (open: boolean) => void importedCount: number failedCount: number failedRows: ImportFailureRow[] entityLabel?: string } function formatValue(value: unknown): string { if (value === null || value === undefined || value === "") return "—" if (typeof value === "string") return value if (typeof value === "number" || typeof value === "boolean") return String(value) try { return JSON.stringify(value) } catch { return String(value) } } export function ImportResultsDialog({ open, onOpenChange, importedCount, failedCount, failedRows, entityLabel = "Records", }: ImportResultsDialogProps) { const hasFailures = failedCount > 0 const flatFailures = failedRows.flatMap((r) => r.errors.map((e) => ({ row: r.row, ...e })), ) return ( Import results {hasFailures ? "Some rows could not be imported. Fix the issues below and re-upload only the failing rows." : `All ${entityLabel.toLowerCase()} imported successfully.`}
{importedCount} imported
{hasFailures && (
{failedCount} failed
)}
{hasFailures && ( Row Field Value Reason {flatFailures.map((f, idx) => ( {f.row} {f.label} {formatValue(f.value)}
{f.message}
{f.valid_examples && f.valid_examples.length > 0 && (
Try one of: {f.valid_examples.slice(0, 3).join(", ")} {f.valid_examples.length > 3 ? "…" : ""}
{f.valid_examples.join(", ")}
)}
))}
)}
) }