-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwhy.tsx
62 lines (55 loc) · 1.67 KB
/
why.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import dynamic from "next/dynamic";
import { Suspense } from "react";
import WhyCard from "../src/Components/Card/Why";
import { DefaultPageLayout } from "../src/Components/Layouts/DefaultPagelayout";
import Seo from "../src/Components/Seo";
import { urlQlient } from "../src/graphql/urql";
import {
WhyQueryDocument,
WhyQueryQuery,
WhyQueryQueryVariables,
} from "../src/graphql/why.generated";
import { ParseQuery } from "../src/helpers/types";
const WhyBanner = dynamic(
async () => await import("../src/Components/Banner/Why")
);
type Page = ParseQuery<WhyQueryQuery["page"]>;
export interface PageProps {
whyItems: Page["whyBlockCollection"];
heroData: Page["heroBlock"];
seo: Page["seo"];
}
export default function Why(props: PageProps) {
return (
<>
<Seo {...props.seo} />
<Suspense fallback={null}>
<WhyBanner {...props.heroData} />
</Suspense>
{props.whyItems?.items?.map((elem, index) => (
<Suspense key={`why-card-${index}`} fallback={null}>
<WhyCard number={index + 1} {...elem} key={`why-card-${index}`} />
</Suspense>
))}
</>
);
}
export async function getStaticProps() {
const queryResults = await urlQlient
.query<WhyQueryQuery, WhyQueryQueryVariables>(WhyQueryDocument, {
id: "7rT5EZIWOXMxoy8151P9WL",
locale: "es-CL",
isPreview: Boolean(process.env.NEXT_PUBLIC_CONTENTFUL_IS_PREVIEW),
})
.toPromise();
const page = queryResults.data?.page as Page;
const props: PageProps = {
heroData: page?.heroBlock || null,
whyItems: page?.whyBlockCollection || null,
seo: page?.seo || null,
};
return {
props,
};
}
Why.getLayout = DefaultPageLayout;