Fix exception thrown with zero links. Closes #2833

This commit is contained in:
Gabe Kangas 2023-03-18 11:49:20 -07:00
parent a2af4f5729
commit 7e4d147940
No known key found for this signature in database
GPG Key ID: 4345B2060657F330

View File

@ -1,31 +1,50 @@
import Image from 'next/image'; import Image from 'next/image';
import { FC } from 'react'; import { FC } from 'react';
import { ErrorBoundary } from 'react-error-boundary';
import { SocialLink } from '../../../interfaces/social-link.model'; import { SocialLink } from '../../../interfaces/social-link.model';
import { ComponentError } from '../ComponentError/ComponentError';
import styles from './SocialLinks.module.scss'; import styles from './SocialLinks.module.scss';
export type SocialLinksProps = { export type SocialLinksProps = {
links: SocialLink[]; links: SocialLink[];
}; };
export const SocialLinks: FC<SocialLinksProps> = ({ links }) => ( export const SocialLinks: FC<SocialLinksProps> = ({ links }) => {
<div className={styles.links}> if (!links?.length) {
{links.map(link => ( return null;
<a }
key={link.platform}
href={link.url} return (
className={styles.link} <ErrorBoundary
target="_blank" // eslint-disable-next-line react/no-unstable-nested-components
// eslint-disable-next-line react/no-invalid-html-attribute fallbackRender={({ error, resetErrorBoundary }) => (
rel="noreferrer me" <ComponentError
> componentName="SocialLinks"
<Image message={error.message}
src={link.icon || '/img/platformlogos/default.svg'} retryFunction={resetErrorBoundary}
alt={link.platform}
className={styles.link}
width="30"
height="30"
/> />
</a> )}
))} >
</div> <div className={styles.links}>
); {links?.map(link => (
<a
key={link.platform}
href={link.url}
className={styles.link}
target="_blank"
// eslint-disable-next-line react/no-invalid-html-attribute
rel="noreferrer me"
>
<Image
src={link.icon || '/img/platformlogos/default.svg'}
alt={link.platform}
className={styles.link}
width="30"
height="30"
/>
</a>
))}
</div>
</ErrorBoundary>
);
};