11import type { MeGuild } from '@chatsift/api' ;
22import Image from 'next/image' ;
33import Link from 'next/link' ;
4- import { cn , getGuildAcronym } from '@/utils/util' ;
4+ import type { PropsWithChildren } from 'react' ;
5+ import { getGuildAcronym } from '@/utils/util' ;
56
67export interface GuildIconProps {
78 readonly data : MeGuild ;
89 readonly disableLink ?: boolean ;
910 readonly hasBots : boolean ;
1011}
1112
13+ interface ParentProps extends PropsWithChildren {
14+ readonly disableLink : boolean | undefined ;
15+ readonly url : string | undefined ;
16+ }
17+
18+ function Parent ( { children, disableLink, url } : ParentProps ) {
19+ if ( disableLink || ! url ) {
20+ return < > { children } </ > ;
21+ }
22+
23+ return < Link href = { url } > { children } </ Link > ;
24+ }
25+
1226export function GuildIcon ( { data, hasBots, disableLink } : GuildIconProps ) {
1327 const icon = data ?. icon ? `https://cdn.discordapp.com/icons/${ data . id } /${ data . icon } .png` : null ;
1428 const url = hasBots ? `/dashboard/${ data . id } ` : undefined ;
1529
1630 return (
1731 < div className = "flex flex-row items-center" >
18- < Link className = { cn ( ( disableLink || ! url ) && 'pointer-events-none' ) } href = { url ?? '#' } >
32+ < Parent disableLink = { disableLink } url = { url } >
1933 { icon ? (
2034 < Image
2135 alt = "Guild icon"
@@ -29,7 +43,7 @@ export function GuildIcon({ data, hasBots, disableLink }: GuildIconProps) {
2943 { getGuildAcronym ( data . name ) }
3044 </ p >
3145 ) }
32- </ Link >
46+ </ Parent >
3347 </ div >
3448 ) ;
3549}
0 commit comments