-
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.
For JIRA: "EPO-8545 #IN-PROGRESS #comment add section break template"
- Loading branch information
Showing
23 changed files
with
2,282 additions
and
102 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,71 @@ | ||
import { PropsWithChildren } from "react"; | ||
import { RootLayoutParams } from "../../layout"; | ||
import { InvestigationParams } from "../layout"; | ||
import { graphql } from "@/gql/public-schema"; | ||
import { queryAPI } from "@/lib/fetch"; | ||
import { ProgressProvider } from "@/contexts/Progress"; | ||
import { notFound } from "next/navigation"; | ||
import Header from "@/components/page/Header/Header"; | ||
import Pager from "@/components/layout/Pager"; | ||
|
||
export interface UriSegmentsParams { | ||
uriSegments: string[]; | ||
} | ||
|
||
export interface UriSegmentsProps { | ||
params: RootLayoutParams & InvestigationParams & UriSegmentsParams; | ||
} | ||
|
||
const Query = graphql(` | ||
query InvestigationChildPage($site: [String], $uri: [String]) { | ||
entry(site: $site, uri: $uri) { | ||
...InvestigationChildPageTemplate | ||
...InvestigationSectionBreakTemplate | ||
} | ||
} | ||
`); | ||
|
||
const UriSegmentsLayout: ( | ||
props: PropsWithChildren<UriSegmentsProps> | ||
) => Promise<JSX.Element> = async ({ | ||
children, | ||
params: { locale, investigation, uriSegments }, | ||
}) => { | ||
const site = locale === "en" ? "default" : locale; | ||
const uri = `${investigation}/${uriSegments.join("/")}`; | ||
|
||
const { data } = await queryAPI({ | ||
query: Query, | ||
variables: { | ||
site: [site], | ||
uri: [uri], | ||
}, | ||
}); | ||
|
||
const { __typename } = data?.entry || {}; | ||
|
||
const isValidType = | ||
__typename === "investigations_default_Entry" || | ||
__typename === "investigations_investigationSectionBreakChild_Entry"; | ||
|
||
if (!isValidType) { | ||
notFound(); | ||
} | ||
|
||
const { id, parent, prev, next } = data?.entry || {}; | ||
|
||
const prevUrl = prev?.uri ? `/${prev.uri}` : "#"; | ||
const nextUrl = next?.uri ? `/${next.uri}` : "#"; | ||
|
||
const childPages = parent.children ?? []; | ||
|
||
return ( | ||
<ProgressProvider pages={childPages} currentPageId={id}> | ||
<Header /> | ||
{children} | ||
<Pager leftLink={prevUrl} rightLink={nextUrl} /> | ||
</ProgressProvider> | ||
); | ||
}; | ||
|
||
export default UriSegmentsLayout; |
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
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
Oops, something went wrong.