chore: move function declarations
This commit is contained in:
@@ -16,6 +16,35 @@ import {
|
|||||||
} from "@/types/requests/myPages/navigation"
|
} from "@/types/requests/myPages/navigation"
|
||||||
import { GetNavigationMyPages } from "@/lib/graphql/Query/NavigationMyPages.graphql"
|
import { GetNavigationMyPages } from "@/lib/graphql/Query/NavigationMyPages.graphql"
|
||||||
|
|
||||||
|
function getURL(node: PageLink) {
|
||||||
|
switch (node.__typename) {
|
||||||
|
case PageLinkEnum.ContentPage:
|
||||||
|
return node.web.url
|
||||||
|
case PageLinkEnum.AccountPage:
|
||||||
|
case PageLinkEnum.LoyaltyPage:
|
||||||
|
case PageLinkEnum.CodeDefinedPage:
|
||||||
|
return node.url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function mapMenuItems(navigationItems: NavigationItem[]) {
|
||||||
|
return navigationItems.map(({ item }): MenuItem => {
|
||||||
|
const { node } = item.pageConnection.edges[0]
|
||||||
|
const {
|
||||||
|
title,
|
||||||
|
system: { uid },
|
||||||
|
} = node
|
||||||
|
|
||||||
|
return {
|
||||||
|
title,
|
||||||
|
uid,
|
||||||
|
url: getURL(node),
|
||||||
|
linkText: item.link_text,
|
||||||
|
subItems: item.sub_items ? mapMenuItems(item.sub_items) : null,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export default async function MyPagesLayout({
|
export default async function MyPagesLayout({
|
||||||
children,
|
children,
|
||||||
params,
|
params,
|
||||||
@@ -26,35 +55,6 @@ export default async function MyPagesLayout({
|
|||||||
locale: params.lang,
|
locale: params.lang,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
function mapMenuItems(navigationItems: NavigationItem[]) {
|
|
||||||
function getURL(node: PageLink) {
|
|
||||||
switch (node.__typename) {
|
|
||||||
case PageLinkEnum.ContentPage:
|
|
||||||
return node.web.url
|
|
||||||
case PageLinkEnum.AccountPage:
|
|
||||||
case PageLinkEnum.LoyaltyPage:
|
|
||||||
case PageLinkEnum.CodeDefinedPage:
|
|
||||||
return node.url
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return navigationItems.map(({ item }): MenuItem => {
|
|
||||||
const { node } = item.pageConnection.edges[0]
|
|
||||||
const {
|
|
||||||
title,
|
|
||||||
system: { uid },
|
|
||||||
} = node
|
|
||||||
|
|
||||||
return {
|
|
||||||
title,
|
|
||||||
uid,
|
|
||||||
url: getURL(node),
|
|
||||||
linkText: item.link_text,
|
|
||||||
subItems: item.sub_items ? mapMenuItems(item.sub_items) : null,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
// navigation_my_pages is of type Single, hence the hard [0]
|
// navigation_my_pages is of type Single, hence the hard [0]
|
||||||
const navigation = response.data.all_navigation_my_pages.items[0]
|
const navigation = response.data.all_navigation_my_pages.items[0]
|
||||||
const menuItems = mapMenuItems(navigation.items)
|
const menuItems = mapMenuItems(navigation.items)
|
||||||
|
|||||||
Reference in New Issue
Block a user