Skip to content
This repository was archived by the owner on Jun 28, 2025. It is now read-only.

Commit a4f0317

Browse files
author
Manuel Proß
committed
refactor(web): add better fallback message when fetching failed, replace if statement with switch case
1 parent 8291121 commit a4f0317

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

web/src/components/Strapi/Sections/Content.tsx

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Link from "next/link";
33
import NewsSection from "@/components/Strapi/Sections/NewsSection";
44
import Card from "@/components/Strapi/Common/Card";
55
import { CardContent, GenericContentEntry } from "@/types/strapi";
6+
import List from "../Common/List";
67

78
type ContentProps = {
89
entries: GenericContentEntry[];
@@ -12,31 +13,40 @@ export default function PageContent({ entries }: ContentProps) {
1213
if (!("type" in entry)) {
1314
return (
1415
<div key={uuid} className="text-white">
15-
sth. went wrong
16+
<p>The fetched component has no defined type. Pls have a look in the strapi backend and change your component definition accordingly</p>
1617
</div>
1718
);
1819
}
1920

20-
if (entry.type === "Card" || entry.type === "Plain" || entry.type === "Accordion") {
21-
return (
22-
<div key={uuid} className="[&:not(:last-child)]:mb-32">
23-
{renderTextSection(entry)}
24-
</div>
25-
);
26-
} else if (entry.type === "Primary" || entry.type === "CTA" || entry.type === "Secondary") {
27-
return (
28-
<div key={uuid} className="[&:not(:last-child)]:mb-32">
29-
<Link className="btn-primary block w-fit mr-0 ml-auto" href={entry.url}>
21+
switch (entry.type) {
22+
case "Card":
23+
case "Plain":
24+
case "Accordion":
25+
return (
26+
<div key={uuid} className="[&:not(:last-child)]:mb-32">
27+
{renderTextSection(entry)}
28+
</div>
29+
);
30+
case "News":
31+
return (
32+
<div key={uuid} className="[&:not(:last-child)]:mb-32">
33+
<NewsSection news={entry} />
34+
</div>
35+
);
36+
case "CTA":
37+
case "Primary":
38+
case "Secondary":
39+
return (
40+
<Link key={uuid} className="btn-primary [&:not(:last-child)]:mb-32" href={entry.url}>
3041
{entry.text}
3142
</Link>
32-
</div>
33-
);
34-
} else if (entry.type === "News") {
35-
return (
36-
<div key={uuid} className="[&:not(:last-child)]:mb-32">
37-
<NewsSection news={entry} />
38-
</div>
39-
);
43+
);
44+
case "List":
45+
return (
46+
<div className="[&:not(:last-child)]:mb-32">
47+
<List key={uuid} list={entry.items} />
48+
</div>
49+
);
4050
}
4151
};
4252

@@ -51,5 +61,5 @@ export default function PageContent({ entries }: ContentProps) {
5161
}
5262
};
5363

54-
return <>{entries.map(entry => renderContent(crypto.randomUUID(), entry))}</>;
64+
return entries.map(entry => renderContent(crypto.randomUUID(), entry));
5565
}

0 commit comments

Comments
 (0)