{children}
diff --git a/apps/storyblok/src/components/DataContext/types.ts b/apps/storyblok/src/components/DataContext/types.ts
index f66ef89..0d4b761 100644
--- a/apps/storyblok/src/components/DataContext/types.ts
+++ b/apps/storyblok/src/components/DataContext/types.ts
@@ -4,7 +4,7 @@ import type { IResolvedLink } from "@/lib/api";
export interface IDataContextValues {
allResolvedLinks: IResolvedLink[];
- headersAndFooters: ISbStoryData[];
+ globalComponentsStories: ISbStoryData[];
}
export interface IDataContextProviderProps extends IDataContextValues {
diff --git a/apps/storyblok/src/components/Page/index.tsx b/apps/storyblok/src/components/Page/index.tsx
index e4658aa..96fcbc5 100644
--- a/apps/storyblok/src/components/Page/index.tsx
+++ b/apps/storyblok/src/components/Page/index.tsx
@@ -2,30 +2,25 @@ import { StoryblokComponent, StoryblokStory } from "@storyblok/react/rsc";
import { cn, CookieBanner } from "@shared/ui";
-import { useDataContext } from "../DataContext";
+import { useGlobalComponentData } from "@/lib/hooks/useGlobalComponentData";
+
import type { IPageContainerProps } from "./types";
-import { getHeaderAndFooterStories } from "./utils";
export default function PageContainer({ blok }: IPageContainerProps) {
- const { headersAndFooters } = useDataContext();
+ const globalHeader = useGlobalComponentData(blok.header as string);
+ const globalFooter = useGlobalComponentData(blok.footer as string);
const { sections, showCookieBanner, theme } = blok;
if (!sections) return null;
- const { header, footer } = getHeaderAndFooterStories(
- headersAndFooters,
- blok.header,
- blok.footer,
- );
-
return (
-
+ {globalHeader && }
{sections.map((s) => (
))}
-
+ {globalFooter && }
{showCookieBanner && }
);
diff --git a/apps/storyblok/src/components/Page/utils.ts b/apps/storyblok/src/components/Page/utils.ts
deleted file mode 100644
index 5f37efe..0000000
--- a/apps/storyblok/src/components/Page/utils.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import type { ISbStoryData } from "@storyblok/react/rsc";
-
-export function getHeaderAndFooterStories(
- stories: ISbStoryData[],
- header: string | ISbStoryData,
- footer: string | ISbStoryData,
-) {
- let resolvedHeader: ISbStoryData | undefined;
- let resolvedFooter: ISbStoryData | undefined;
-
- if (typeof header === "string") {
- resolvedHeader = stories.find((s) => s.uuid === header);
- } else {
- resolvedHeader = header;
- }
-
- if (typeof footer === "string") {
- resolvedFooter = stories.find((s) => s.uuid === footer);
- } else {
- resolvedFooter = footer;
- }
-
- return {
- header: resolvedHeader,
- footer: resolvedFooter,
- };
-}
diff --git a/apps/storyblok/src/contentSections/Hero/index.tsx b/apps/storyblok/src/contentSections/Hero/index.tsx
index e57b5d1..e7b58c2 100644
--- a/apps/storyblok/src/contentSections/Hero/index.tsx
+++ b/apps/storyblok/src/contentSections/Hero/index.tsx
@@ -5,16 +5,38 @@ import { Hero as HeroUI } from "@shared/ui";
import { prepareImageProps } from "@/lib/adapters/prepareImageProps";
import { prepareLinkProps } from "@/lib/adapters/prepareLinkProps";
import { prepareRichTextProps } from "@/lib/adapters/prepareRichTextProps";
+import { useGlobalComponentData } from "@/lib/hooks/useGlobalComponentData";
import SectionContainer from "@/components/SectionContainer";
import type { IHeroProps } from "./types";
export default function Hero({ blok }: IHeroProps) {
- const { title, text, image, links } = blok;
+ const { title, text, image, links, globalData } = blok;
+ const globalBlok = useGlobalComponentData(globalData as string);
if (image.length === 0 && links.length === 0 && text?.length === 0 && !title)
return ;
+ if (globalBlok) {
+ const {
+ title: globalTitle,
+ text: globalText,
+ image: globalImage,
+ links: globalLinks,
+ } = globalBlok.content;
+
+ return (
+
+
+
+ );
+ }
+
return (
| string;
title?: string;
text?: RichTextStoryblok[];
image: ImageStoryblok[];
diff --git a/apps/storyblok/src/lib/api.ts b/apps/storyblok/src/lib/api.ts
index b447c26..183221d 100644
--- a/apps/storyblok/src/lib/api.ts
+++ b/apps/storyblok/src/lib/api.ts
@@ -51,7 +51,7 @@ export interface IResolvedLink {
export async function fetchStoryBySlug(
isDraftMode: boolean,
slug: string[] = ["home"],
- params?: { cv?: number; resolve_relations?: string },
+ params?: { cv?: number },
): Promise<{ story: ISbStoryData; links: IResolvedLink[] }> {
const cv = await getSBcacheCVparameter(isDraftMode);
@@ -69,20 +69,11 @@ export async function fetchStoryBySlug(
searchParamsData as Record,
);
- const { story, links, rels } = await fetch(
+ const { story, links } = await fetch(
`${API_GATE}/stories/${slug?.join("/") || ""}?${searchParams.toString()}`,
).then((res) => res.json());
- // REST storyblok API doesnt resolve relations in the response, only uuid
- // So we need to resolve them manually
- // using this function it should be done automatically
- if (params?.resolve_relations) {
- const relations = params.resolve_relations.split(",");
-
- relations.forEach((relation) => {
- story.content[relation] = findRelation(rels, story.content[relation]);
- });
- }
+ console.log("links length: ", links.length);
return {
story,
@@ -90,10 +81,6 @@ export async function fetchStoryBySlug(
};
}
-function findRelation(rels: any, id: string) {
- return rels.find((rel: any) => rel.uuid === id);
-}
-
// This function uses only on a build lvl to generate a sitemap
export async function fetchAllPages() {
const cv = await getSBcacheCVparameter(false);
diff --git a/apps/storyblok/src/lib/hooks/useGlobalComponentData.tsx b/apps/storyblok/src/lib/hooks/useGlobalComponentData.tsx
new file mode 100644
index 0000000..8bf40f8
--- /dev/null
+++ b/apps/storyblok/src/lib/hooks/useGlobalComponentData.tsx
@@ -0,0 +1,19 @@
+"use client";
+
+import type { ISbStoryData } from "@storyblok/react/rsc";
+
+import { useDataContext } from "@/components/DataContext";
+
+export const useGlobalComponentData = (
+ globalComponent: string,
+): ISbStoryData | null => {
+ const { globalComponentsStories } = useDataContext();
+
+ if (!globalComponent) return null;
+
+ const globalComponentData = globalComponentsStories.find(
+ (s) => s.uuid === globalComponent,
+ );
+
+ return globalComponentData || null;
+};
diff --git a/packages/ui/components/sections/hero/index.tsx b/packages/ui/components/sections/hero/index.tsx
index 8ba65a2..013429d 100644
--- a/packages/ui/components/sections/hero/index.tsx
+++ b/packages/ui/components/sections/hero/index.tsx
@@ -5,7 +5,7 @@ import type { IHeroProps } from "./types";
export function Hero({ title, text, image, links }: IHeroProps) {
return (
-