fix: validation for header
This commit is contained in:
@@ -2,43 +2,42 @@ import type {
|
||||
FooterLinkItem,
|
||||
FooterRefDataRaw,
|
||||
} from "@/types/components/footer/footer"
|
||||
import type { HeaderRefResponse } from "@/types/header"
|
||||
import { System } from "@/types/requests/system"
|
||||
import { Edges } from "@/types/requests/utils/edges"
|
||||
import { NodeRefs } from "@/types/requests/utils/refs"
|
||||
import type { HeaderRefs } from "@/types/trpc/routers/contentstack/header"
|
||||
|
||||
export function getConnections(refs: HeaderRefResponse) {
|
||||
const connections: Edges<NodeRefs>[] = []
|
||||
const headerData = refs.all_header.items[0]
|
||||
const topLink = headerData.top_link
|
||||
if (topLink) {
|
||||
connections.push(topLink.linkConnection)
|
||||
export function getConnections({ header }: HeaderRefs) {
|
||||
const connections: System["system"][] = [header.system]
|
||||
|
||||
if (header.top_link?.link) {
|
||||
connections.push(header.top_link.link)
|
||||
}
|
||||
|
||||
headerData.menu_items.forEach(
|
||||
({ linkConnection, see_all_link, cardConnection, submenu }) => {
|
||||
const card = cardConnection.edges[0]?.node
|
||||
connections.push(linkConnection)
|
||||
|
||||
if (see_all_link) {
|
||||
connections.push(see_all_link.linkConnection)
|
||||
if (header.menu_items.length) {
|
||||
header.menu_items.forEach((menuItem) => {
|
||||
if (menuItem.card) {
|
||||
connections.push(...menuItem.card)
|
||||
}
|
||||
|
||||
if (card) {
|
||||
if (card.primary_button) {
|
||||
connections.push(card.primary_button.linkConnection)
|
||||
}
|
||||
if (card.secondary_button) {
|
||||
connections.push(card.secondary_button.linkConnection)
|
||||
}
|
||||
if (menuItem.link) {
|
||||
connections.push(menuItem.link)
|
||||
}
|
||||
|
||||
submenu.forEach(({ links }) => {
|
||||
links.forEach(({ linkConnection }) => {
|
||||
connections.push(linkConnection)
|
||||
if (menuItem.see_all_link?.link) {
|
||||
connections.push(menuItem.see_all_link.link)
|
||||
}
|
||||
if (menuItem.submenu.length) {
|
||||
menuItem.submenu.forEach((subMenuItem) => {
|
||||
if (subMenuItem.links.length) {
|
||||
subMenuItem.links.forEach((link) => {
|
||||
if (link?.link) {
|
||||
connections.push(link.link)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return connections
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user