forked from saleor/storefront
-
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.
Add pages page and allow using pages as homepage blocks
- Loading branch information
1 parent
dc6ec65
commit 9eaeb1c
Showing
4 changed files
with
122 additions
and
4 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { GetStaticPropsContext, InferGetStaticPropsType } from "next"; | ||
import { usePageQuery } from "@/saleor/api"; | ||
import BaseTemplate from "@/components/BaseTemplate"; | ||
import RichText from "@/components/RichText"; | ||
|
||
export const getStaticProps = async (context: GetStaticPropsContext) => { | ||
return { | ||
props: { | ||
pageSlug: context.params?.slug?.toString(), | ||
}, | ||
}; | ||
}; | ||
|
||
const PagePage: React.VFC<InferGetStaticPropsType<typeof getStaticProps>> = ({ | ||
pageSlug, | ||
}) => { | ||
const { loading, error, data } = usePageQuery({ | ||
variables: { slug: pageSlug || "" }, | ||
skip: !pageSlug, | ||
}); | ||
|
||
if (loading) return <BaseTemplate isLoading={true} />; | ||
if (error) return <p>Error</p>; | ||
|
||
const page = data?.page; | ||
if (!page?.id) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<BaseTemplate> | ||
<main className="max-w-7xl mx-auto pt-8 px-8"> | ||
{!!page.content && <RichText jsonStringData={page.content} />} | ||
</main> | ||
</BaseTemplate> | ||
); | ||
}; | ||
|
||
export default PagePage; | ||
|
||
export async function getStaticPaths() { | ||
return { | ||
paths: [], | ||
fallback: true, | ||
}; | ||
} |
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