-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): split contact us and normal websites (#810)
- Loading branch information
Showing
13 changed files
with
224 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@bigcommerce/catalyst-core": patch | ||
--- | ||
|
||
split contact us and normal websites into individual pages |
68 changes: 0 additions & 68 deletions
68
apps/core/app/[locale]/(default)/(webpages)/[page]/page.tsx
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
apps/core/app/[locale]/(default)/(webpages)/_components/page-content.tsx
This file was deleted.
Oops, something went wrong.
File renamed without changes.
20 changes: 20 additions & 0 deletions
20
apps/core/app/[locale]/(default)/webpages/contact/[id]/contact-us/fragment.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { graphql } from '~/client/graphql'; | ||
|
||
export const ContactUsFragment = graphql(` | ||
fragment ContactUsFragment on Query { | ||
node(id: $id) { | ||
... on ContactPage { | ||
entityId | ||
contactFields | ||
} | ||
} | ||
site { | ||
settings { | ||
reCaptcha { | ||
isEnabledOnStorefront | ||
siteKey | ||
} | ||
} | ||
} | ||
} | ||
`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
apps/core/app/[locale]/(default)/webpages/contact/[id]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import type { Metadata } from 'next'; | ||
import { notFound } from 'next/navigation'; | ||
import { NextIntlClientProvider } from 'next-intl'; | ||
import { getMessages } from 'next-intl/server'; | ||
import { cache } from 'react'; | ||
|
||
import { client } from '~/client'; | ||
import { graphql } from '~/client/graphql'; | ||
import { revalidate } from '~/client/revalidate-target'; | ||
|
||
import { ContactUs } from './contact-us'; | ||
import { ContactUsFragment } from './contact-us/fragment'; | ||
|
||
interface Props { | ||
params: { id: string; locale: string }; | ||
} | ||
|
||
const WebPageQuery = graphql( | ||
` | ||
query WebPage($id: ID!) { | ||
...ContactUsFragment | ||
node(id: $id) { | ||
__typename | ||
... on ContactPage { | ||
name | ||
htmlBody | ||
seo { | ||
pageTitle | ||
metaKeywords | ||
metaDescription | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
[ContactUsFragment], | ||
); | ||
|
||
const getWebpageData = cache(async (variables: { id: string }) => { | ||
const { data } = await client.fetch({ | ||
document: WebPageQuery, | ||
variables, | ||
fetchOptions: { next: { revalidate } }, | ||
}); | ||
|
||
return data; | ||
}); | ||
|
||
export async function generateMetadata({ params }: Props): Promise<Metadata> { | ||
const data = await getWebpageData({ id: decodeURIComponent(params.id) }); | ||
const webpage = data.node?.__typename === 'ContactPage' ? data.node : null; | ||
|
||
if (!webpage) { | ||
notFound(); | ||
} | ||
|
||
const { seo } = webpage; | ||
|
||
return { | ||
title: seo.pageTitle, | ||
description: seo.metaDescription, | ||
keywords: seo.metaKeywords, | ||
}; | ||
} | ||
|
||
export default async function WebPage({ params: { locale, id } }: Props) { | ||
const data = await getWebpageData({ id: decodeURIComponent(id) }); | ||
const webpage = data.node?.__typename === 'ContactPage' ? data.node : null; | ||
|
||
if (!webpage) { | ||
notFound(); | ||
} | ||
|
||
const messages = await getMessages({ locale }); | ||
|
||
const { name, htmlBody } = webpage; | ||
|
||
return ( | ||
<> | ||
<div className="mx-auto mb-10 flex flex-col justify-center gap-8 lg:w-2/3"> | ||
<h1 className="text-4xl font-black lg:text-5xl">{name}</h1> | ||
<div dangerouslySetInnerHTML={{ __html: htmlBody }} /> | ||
</div> | ||
|
||
<NextIntlClientProvider locale={locale} messages={{ AboutUs: messages.AboutUs ?? {} }}> | ||
<ContactUs data={data} /> | ||
</NextIntlClientProvider> | ||
</> | ||
); | ||
} | ||
|
||
export const runtime = 'edge'; |
78 changes: 78 additions & 0 deletions
78
apps/core/app/[locale]/(default)/webpages/normal/[id]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import type { Metadata } from 'next'; | ||
import { notFound } from 'next/navigation'; | ||
import { cache } from 'react'; | ||
|
||
import { client } from '~/client'; | ||
import { graphql } from '~/client/graphql'; | ||
import { revalidate } from '~/client/revalidate-target'; | ||
|
||
interface Props { | ||
params: { id: string }; | ||
} | ||
|
||
const NormalPageQuery = graphql(` | ||
query NormalPage($id: ID!) { | ||
node(id: $id) { | ||
... on NormalPage { | ||
__typename | ||
name | ||
htmlBody | ||
entityId | ||
seo { | ||
pageTitle | ||
metaDescription | ||
metaKeywords | ||
} | ||
} | ||
} | ||
} | ||
`); | ||
|
||
const getWebpageData = cache(async (variables: { id: string }) => { | ||
const { data } = await client.fetch({ | ||
document: NormalPageQuery, | ||
variables, | ||
fetchOptions: { next: { revalidate } }, | ||
}); | ||
|
||
if (data.node?.__typename !== 'NormalPage') { | ||
return null; | ||
} | ||
|
||
return data.node; | ||
}); | ||
|
||
export async function generateMetadata({ params: { id } }: Props): Promise<Metadata> { | ||
const webpage = await getWebpageData({ id }); | ||
|
||
if (!webpage) { | ||
notFound(); | ||
} | ||
|
||
const { seo } = webpage; | ||
|
||
return { | ||
title: seo.pageTitle, | ||
description: seo.metaDescription, | ||
keywords: seo.metaKeywords, | ||
}; | ||
} | ||
|
||
export default async function WebPage({ params: { id } }: Props) { | ||
const webpage = await getWebpageData({ id }); | ||
|
||
if (!webpage) { | ||
notFound(); | ||
} | ||
|
||
const { name, htmlBody } = webpage; | ||
|
||
return ( | ||
<div className="mx-auto mb-10 flex flex-col justify-center gap-8 lg:w-2/3"> | ||
<h1 className="text-4xl font-black lg:text-5xl">{name}</h1> | ||
<div dangerouslySetInnerHTML={{ __html: htmlBody }} /> | ||
</div> | ||
); | ||
} | ||
|
||
export const runtime = 'edge'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.