Skip to content

Commit

Permalink
fix: fix issue with crash when missing image (hide employee)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelbr committed May 6, 2024
1 parent db9c385 commit b126f82
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/employees/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ const blurDataUrl =
export const EmployeeTile = ({
employee: { name, telephone, email, imageUrl, officeName },
}: PropsWithChildren<{ employee: EmployeeItem }>) => {
if (!imageUrl) {
return null;
}

return (
<div
className={style.employee}
Expand Down
2 changes: 1 addition & 1 deletion src/employees/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ export type EmployeeItem = {
name: string;
email: string;
telephone: string | null;
imageUrl: string;
imageUrl: string | null;
officeName: string;
};
22 changes: 12 additions & 10 deletions src/index/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,18 @@ const Home = ({ randomEmployee, randomCases, feeds }: HomeProps) => {
<section className={style.employees}>
{randomEmployee ? (
<div className={style.employees__random}>
<div className={style.employees__random__image}>
<Image
width={300}
height={300}
alt={`Bilde av ${randomEmployee.name}`}
src={randomEmployee.imageUrl}
loading="lazy"
decoding="async"
/>
</div>
{randomEmployee.imageUrl && (
<div className={style.employees__random__image}>
<Image
width={300}
height={300}
alt={`Bilde av ${randomEmployee.name}`}
src={randomEmployee.imageUrl}
loading="lazy"
decoding="async"
/>
</div>
)}

<p>Dette er {randomEmployee.name}. En av oss som jobber her.</p>

Expand Down
9 changes: 5 additions & 4 deletions src/jobs/listing/listing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ const Listing: NextPage<InferGetStaticPropsType<typeof getStaticProps>> =
export const ContactTile = ({
contact: { name, email, telephone, imageUrl },
}: PropsWithChildren<{ contact: EmployeeItem }>) => {
if (!imageUrl) {
return null;
}

return (
<div className={style.contact}>
<div className={style.contact__img}>
Expand All @@ -148,10 +152,7 @@ export const ContactTile = ({
📬 {email}
</a>
{telephone && (
<a
href={`tel:${telephone}`}
className={style.contact__type}
>
<a href={`tel:${telephone}`} className={style.contact__type}>
📞 {formatTelephone(telephone)}
</a>
)}
Expand Down

0 comments on commit b126f82

Please sign in to comment.