1
- import React from 'react'
1
+ import React from 'react' ;
2
2
import { red } from '@mui/material/colors' ;
3
- import { Avatar , Card , CardActions , CardContent , CardHeader , CardMedia , IconButton , Typography } from '@mui/material' ;
3
+ import { Avatar , Card , CardActions , CardContent , CardMedia , Typography } from '@mui/material' ;
4
4
5
+ export default function Cards ( { projectName = 'NA' , imageUrl, altname = 'Project Image' , description = 'No description available' } ) {
6
+ // Safely handle the match and join logic
7
+ const projectCodeArray = projectName ? projectName . match ( / [ 0 - 9 A - Z ] / g) : null ;
8
+ const projectCode = projectCodeArray ? projectCodeArray . join ( '' ) . slice ( 0 , 2 ) : 'NA' ; // Default if match is null
5
9
6
- export default function Cards ( { projectName, imageUrl, altname, description} ) {
7
- return (
8
- < Card sx = { { maxWidth : 345 } } >
9
- < CardContent sx = { { display : 'flex' , justifyContent :'start' } } >
10
- < Avatar sx = { { bgcolor : red [ 500 ] , mr : 2 } } aria-label = "leter" >
11
- { projectName . match ( / [ 0 - 9 A - Z ] / g) . join ( '' ) . slice ( 0 , 2 ) }
12
- </ Avatar >
10
+ return (
11
+ < Card sx = { { maxWidth : 345 } } >
12
+ < CardContent sx = { { display : 'flex' , justifyContent : 'start' } } >
13
+ < Avatar sx = { { bgcolor : red [ 500 ] , mr : 2 } } aria-label = "letter" >
14
+ { projectCode }
15
+ </ Avatar >
13
16
< Typography color = "text.secondary" variant = "h5" >
14
- { projectName }
17
+ { projectName }
15
18
</ Typography >
16
19
</ CardContent >
17
20
< CardMedia
18
21
component = "img"
19
22
height = "200"
20
- image = { imageUrl }
23
+ image = { imageUrl || 'defaultImageUrl.jpg' }
21
24
alt = { altname }
22
25
/>
23
26
< CardContent >
@@ -28,5 +31,5 @@ export default function Cards( {projectName, imageUrl, altname, description} ) {
28
31
< CardActions disableSpacing >
29
32
</ CardActions >
30
33
</ Card >
31
- )
34
+ ) ;
32
35
}
0 commit comments