1
+ 'use client' ;
2
+
3
+ import { AlertCircle , Code , FileX , Terminal } from 'lucide-react' ;
4
+ import { Alert , AlertDescription , AlertTitle } from '@/components/ui/alert' ;
5
+ import { Badge } from '@/components/ui/badge' ;
6
+ import { ScrollArea } from '@/components/ui/scroll-area' ;
7
+
8
+ interface BuildError {
9
+ type : 'typescript' | 'build' | 'runtime' ;
10
+ message : string ;
11
+ file ?: string ;
12
+ line ?: number ;
13
+ column ?: number ;
14
+ }
15
+
16
+ interface ErrorDisplayProps {
17
+ errors : BuildError [ ] ;
18
+ }
19
+
20
+ export function ErrorDisplay ( { errors } : ErrorDisplayProps ) {
21
+ const getErrorIcon = ( type : BuildError [ 'type' ] ) => {
22
+ switch ( type ) {
23
+ case 'typescript' :
24
+ return < Code className = "h-4 w-4" /> ;
25
+ case 'build' :
26
+ return < Terminal className = "h-4 w-4" /> ;
27
+ case 'runtime' :
28
+ return < AlertCircle className = "h-4 w-4" /> ;
29
+ default :
30
+ return < FileX className = "h-4 w-4" /> ;
31
+ }
32
+ } ;
33
+
34
+ const getErrorColor = ( type : BuildError [ 'type' ] ) => {
35
+ switch ( type ) {
36
+ case 'typescript' :
37
+ return 'bg-blue-500/10 text-blue-700 dark:text-blue-400' ;
38
+ case 'build' :
39
+ return 'bg-orange-500/10 text-orange-700 dark:text-orange-400' ;
40
+ case 'runtime' :
41
+ return 'bg-red-500/10 text-red-700 dark:text-red-400' ;
42
+ default :
43
+ return 'bg-gray-500/10 text-gray-700 dark:text-gray-400' ;
44
+ }
45
+ } ;
46
+
47
+ const groupedErrors = errors . reduce ( ( acc , error ) => {
48
+ if ( ! acc [ error . type ] ) {
49
+ acc [ error . type ] = [ ] ;
50
+ }
51
+ acc [ error . type ] . push ( error ) ;
52
+ return acc ;
53
+ } , { } as Record < string , BuildError [ ] > ) ;
54
+
55
+ return (
56
+ < div className = "w-full h-full flex items-center justify-center rounded-md border bg-background p-6" >
57
+ < div className = "w-full max-w-2xl" >
58
+ < div className = "text-center mb-6" >
59
+ < AlertCircle className = "h-12 w-12 text-destructive mx-auto mb-4" />
60
+ < h3 className = "text-lg font-semibold mb-2" > Build Errors Detected</ h3 >
61
+ < p className = "text-muted-foreground text-sm" >
62
+ Your project has some issues that need to be fixed before it can run properly.
63
+ </ p >
64
+ </ div >
65
+
66
+ < ScrollArea className = "max-h-96" >
67
+ < div className = "space-y-4" >
68
+ { Object . entries ( groupedErrors ) . map ( ( [ type , typeErrors ] ) => (
69
+ < div key = { type } className = "space-y-2" >
70
+ < div className = "flex items-center gap-2 mb-3" >
71
+ { getErrorIcon ( type as BuildError [ 'type' ] ) }
72
+ < h4 className = "font-medium capitalize" > { type } Errors</ h4 >
73
+ < Badge variant = "secondary" className = "text-xs" >
74
+ { typeErrors . length }
75
+ </ Badge >
76
+ </ div >
77
+
78
+ { typeErrors . map ( ( error , index ) => (
79
+ < Alert key = { index } className = "border-l-4 border-destructive" >
80
+ < AlertTitle className = "flex items-center gap-2 text-sm" >
81
+ < Badge
82
+ variant = "outline"
83
+ className = { `text-xs ${ getErrorColor ( error . type ) } ` }
84
+ >
85
+ { error . type }
86
+ </ Badge >
87
+ { error . file && (
88
+ < span className = "text-muted-foreground" >
89
+ { error . file }
90
+ { error . line && `:${ error . line } ` }
91
+ { error . column && `:${ error . column } ` }
92
+ </ span >
93
+ ) }
94
+ </ AlertTitle >
95
+ < AlertDescription className = "mt-2 text-sm font-mono bg-muted/50 p-2 rounded text-wrap break-words" >
96
+ { error . message }
97
+ </ AlertDescription >
98
+ </ Alert >
99
+ ) ) }
100
+ </ div >
101
+ ) ) }
102
+ </ div >
103
+ </ ScrollArea >
104
+
105
+ < div className = "mt-6 p-4 bg-muted/50 rounded-lg" >
106
+ < h4 className = "text-sm font-medium mb-2" > 💡 Common Solutions:</ h4 >
107
+ < ul className = "text-sm text-muted-foreground space-y-1" >
108
+ < li > • Check for missing imports or typos in component names</ li >
109
+ < li > • Verify that all props are properly typed</ li >
110
+ < li > • Make sure all dependencies are correctly installed</ li >
111
+ < li > • Try regenerating the component with more specific requirements</ li >
112
+ </ ul >
113
+ </ div >
114
+ </ div >
115
+ </ div >
116
+ ) ;
117
+ }
0 commit comments