Skip to content

Commit

Permalink
Fix 404s (#105)
Browse files Browse the repository at this point in the history
* Fix error because accessing exited members

* Organize imports
  • Loading branch information
timoclsn authored Jan 5, 2025
1 parent 4be32d7 commit 925417f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions app/mitglieder/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from "lib/members";
import { createGenerateMetadata } from "lib/metadata";
import Image from "next/image";
import { notFound } from "next/navigation";

export const generateMetadata = createGenerateMetadata(async ({ params }) => {
const { slug } = await params;
Expand Down Expand Up @@ -39,6 +40,11 @@ interface Props {
const MemberPage = async ({ params }: Props) => {
const { slug } = await params;
const member = await getWebsiteMemberBySlug(slug);

if (!member) {
notFound();
}

const otherMembers = await getRandomOtherMembers(member, 5);

return (
Expand Down
4 changes: 4 additions & 0 deletions components/ContactSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { MemberImage } from "./MemberImage";
export const ContactSection = async () => {
const member = await getWebsiteMemberByName("Nina Kuch");

if (!member) {
return null;
}

return (
<section id="contact">
<div className="mb-14">
Expand Down
4 changes: 4 additions & 0 deletions components/TestimonialsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export const TestimonialsSection = async () => {
{testimonials.map(async (testimonial, index) => {
const member = await getWebsiteMemberByName(testimonial.data.name);

if (!member) {
return null;
}

return (
<li key={index} className="flex-1">
<article className="h-full">
Expand Down
7 changes: 3 additions & 4 deletions lib/members.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import kebabCase from "lodash/kebabCase";
import trim from "lodash/trim";
import z from "zod";
import { getCacheValue, setCacheValue } from "./cache";
import { customField, getActiveMembers, Member } from "./easyverein";
import { notFound } from "next/navigation";
import { customField, getActiveMembers } from "./easyverein";

const { NODE_ENV } = process.env;

Expand Down Expand Up @@ -166,7 +165,7 @@ export const getWebsiteMemberByName = async (name: string) => {

if (!member) {
console.error(`Member with name "${name}" not found`);
notFound();
return null;
}

return member;
Expand All @@ -178,7 +177,7 @@ export const getWebsiteMemberBySlug = async (slug: string) => {

if (!member) {
console.error(`Member with slug "${slug}" not found`);
notFound();
return null;
}

return member;
Expand Down

0 comments on commit 925417f

Please sign in to comment.