1+ import { AlertTriangle , Code , ArrowRight } from "lucide-react"
2+ import { ZodIssue } from "zod" ;
3+
4+ interface ErrorDisplayProps {
5+ title ?: string
6+ description ?: string
7+ issues ?: ZodIssue [ ]
8+ }
9+
10+ export function ErrorDisplay ( {
11+ title = "Error" ,
12+ description = "Invalid report format. Please ensure the report is generated correctly." ,
13+ issues = [ ] ,
14+ } : ErrorDisplayProps ) {
15+
16+ const getIssueTypeColor = ( code : string ) => {
17+ switch ( code ) {
18+ case "invalid_type" :
19+ return "bg-red-50 border-red-200 text-red-800"
20+ default :
21+ return "bg-gray-50 border-gray-200 text-gray-800"
22+ }
23+ }
24+
25+ const getPathString = ( path : ( string | number ) [ ] ) => {
26+ return path . length > 0 ? path . join ( "." ) : "root"
27+ }
28+
29+ return (
30+ < div className = "max-w-4xl mx-auto p-6" >
31+ < div className = "text-center mb-6" >
32+ < div className = "flex items-center justify-center mb-3" >
33+ < AlertTriangle className = "w-12 h-12 text-red-500 mr-3" />
34+ < h1 className = "text-4xl font-bold text-gray-900" > { title } </ h1 >
35+ </ div >
36+ < p className = "text-lg text-gray-600" > { description } </ p >
37+ </ div >
38+
39+ { issues . length > 0 && (
40+ < div className = "space-y-4" >
41+ < div className = "flex items-center mb-4" >
42+ < div className = "h-px bg-gray-300 flex-1" > </ div >
43+ < span className = "px-4 text-sm font-medium text-gray-500" >
44+ { issues . length } Validation Issue{ issues . length !== 1 ? "s" : "" }
45+ </ span >
46+ < div className = "h-px bg-gray-300 flex-1" > </ div >
47+ </ div >
48+
49+ { issues . map ( ( issue , index ) => (
50+ < div
51+ key = { index }
52+ className = { `rounded-lg border-2 p-6 transition-all duration-200 hover:shadow-md ${ getIssueTypeColor ( issue . code ) } ` }
53+ >
54+ < div className = "grid grid-cols-1 lg:grid-cols-3 gap-6 items-center" >
55+ < div className = "space-y-2" >
56+ < div className = "flex items-center" >
57+ < Code className = "w-4 h-4 mr-2 opacity-70" />
58+ < span className = "font-mono text-sm font-semibold uppercase tracking-wide" >
59+ { issue . code . replace ( "_" , " " ) }
60+ </ span >
61+ </ div >
62+ < div className = "font-mono text-lg font-bold" > { getPathString ( issue . path ) } </ div >
63+ </ div >
64+ < div className = "flex justify-center" >
65+ < ArrowRight className = "w-6 h-6 opacity-50" />
66+ </ div >
67+ { issue . code === "invalid_type" &&
68+ < div className = "space-y-3" >
69+ < div className = "text-base font-medium" > { issue . message } </ div >
70+ < div
71+ className = "flex flex-col space-y-2" >
72+ < div className = "flex items-center" >
73+ < span className = "text-sm text-gray-600 mr-2" > Expected:</ span >
74+ < span
75+ className = "px-2 py-1 bg-green-100 text-green-800 rounded font-mono text-sm font-medium" >
76+ { issue . expected }
77+ </ span >
78+ </ div >
79+ < div className = "flex items-center" >
80+ < span className = "text-sm text-gray-600 mr-2" > Received:</ span >
81+ < span
82+ className = "px-2 py-1 bg-red-100 text-red-800 rounded font-mono text-sm font-medium" >
83+ { issue . received }
84+ </ span >
85+ </ div >
86+ </ div >
87+ </ div >
88+ }
89+ </ div >
90+ </ div >
91+ ) ) }
92+ </ div >
93+ ) }
94+
95+ { issues . length === 0 && (
96+ < div className = "text-center py-8" >
97+ < div className = "w-16 h-16 bg-gray-100 rounded-full flex items-center justify-center mx-auto mb-4" >
98+ < AlertTriangle className = "w-8 h-8 text-gray-400" />
99+ </ div >
100+ < p className = "text-gray-500" > No detailed validation issues available.</ p >
101+ </ div >
102+ ) }
103+ </ div >
104+ )
105+ }
0 commit comments