1- import React from 'react'
1+ import React from 'react' ;
22import { 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' ;
44
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
59
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 >
1316 < Typography color = "text.secondary" variant = "h5" >
14- { projectName }
17+ { projectName }
1518 </ Typography >
1619 </ CardContent >
1720 < CardMedia
1821 component = "img"
1922 height = "200"
20- image = { imageUrl }
23+ image = { imageUrl || 'defaultImageUrl.jpg' }
2124 alt = { altname }
2225 />
2326 < CardContent >
@@ -28,5 +31,5 @@ export default function Cards( {projectName, imageUrl, altname, description} ) {
2831 < CardActions disableSpacing >
2932 </ CardActions >
3033 </ Card >
31- )
34+ ) ;
3235}
0 commit comments