-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
102 additions
and
0 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,75 @@ | ||
import { getClient } from '@/graphql/clients/serverSideClient'; | ||
import { GET_PAGE } from '@/graphql/queries/pages'; | ||
import { GetPageQuery } from '@/graphql/types/graphql'; | ||
import { Locale } from '@/navigation'; | ||
import { Container, Typography } from '@mui/material'; | ||
import { notFound } from 'next/navigation'; | ||
import React, { FC } from 'react'; | ||
|
||
type IPage = NonNullable<GetPageQuery['pages']>['edges'][number]['node']; | ||
|
||
const getPage = async ({ slug }: { slug: string }): Promise<IPage | null> => { | ||
if (!slug) { | ||
return null; | ||
} | ||
|
||
const { data } = await getClient().query<GetPageQuery>({ | ||
query: GET_PAGE, | ||
variables: { | ||
slug, | ||
}, | ||
}); | ||
return data?.pages?.edges?.[0].node || null; | ||
}; | ||
|
||
interface PageProps { | ||
params: { locale: Locale; slug: string[] }; | ||
searchParams: any[]; | ||
} | ||
|
||
export async function generateMetadata(props: PageProps) { | ||
const slug = props.params.slug?.[0]; | ||
|
||
const page = await getPage({ slug }); | ||
|
||
return { | ||
title: page?.title, | ||
}; | ||
} | ||
|
||
const page: FC<PageProps> = async ({ params }) => { | ||
const slug = params.slug?.[0]; | ||
|
||
const page = await getPage({ slug }); | ||
|
||
if (!page?.content) { | ||
notFound(); | ||
} | ||
|
||
return ( | ||
<Container maxWidth="xl" sx={{ mt: 10 }}> | ||
<Typography | ||
component="h1" | ||
variant="h5" | ||
sx={{ | ||
fontWeight: 'bold', | ||
}} | ||
> | ||
{page.title} | ||
</Typography> | ||
|
||
<Typography | ||
component="div" | ||
sx={{ | ||
textAlign: 'justify', | ||
lineHeight: 2, | ||
}} | ||
dangerouslySetInnerHTML={{ | ||
__html: page.content, | ||
}} | ||
/> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default page; |
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,14 @@ | ||
import { gql } from '@apollo/client'; | ||
|
||
export const GET_PAGE = gql` | ||
query GetPage($slug: String) { | ||
pages(where: { name: $slug, status: PUBLISH }) { | ||
edges { | ||
node { | ||
title | ||
content | ||
} | ||
} | ||
} | ||
} | ||
`; |
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
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