feat(WEB-304): remaning UI from design system primitives
This commit is contained in:
@@ -4,7 +4,7 @@ import {
|
||||
} from "@/lib/graphql/Query/NavigationMyPages.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { internalServerError, notFound } from "@/server/errors/trpc"
|
||||
import { contentstackProcedure, publicProcedure, router } from "@/server/trpc"
|
||||
import { contentstackBaseProcedure, router } from "@/server/trpc"
|
||||
|
||||
import {
|
||||
generateRefsResponseTag,
|
||||
@@ -14,40 +14,46 @@ import {
|
||||
import { removeMultipleSlashes } from "@/utils/url"
|
||||
|
||||
import {
|
||||
type GetNavigationMyPagesData,
|
||||
type GetNavigationMyPagesRefsData,
|
||||
getNavigationSchema,
|
||||
type MenuItems,
|
||||
navigationPayloadSchema,
|
||||
navigationRefsPayloadSchema,
|
||||
} from "./output"
|
||||
import { getConnections } from "./utils"
|
||||
|
||||
import type {
|
||||
GetNavigationMyPagesData,
|
||||
GetNavigationMyPagesRefsData,
|
||||
MenuItem,
|
||||
NavigationItem,
|
||||
} from "@/types/requests/myPages/navigation"
|
||||
import { PageLinkEnum } from "@/types/requests/pageLinks"
|
||||
|
||||
export function mapMenuItems(navigationItems: NavigationItem[]) {
|
||||
return navigationItems.map(({ item }): MenuItem => {
|
||||
const { node } = item.pageConnection.edges[0]
|
||||
|
||||
const menuItem: MenuItem = {
|
||||
lang: node.system.locale,
|
||||
linkText: item.link_text || node.title,
|
||||
uid: node.system.uid,
|
||||
url: removeMultipleSlashes(`/${node.system.locale}/${node.url}`),
|
||||
export function mapMenuItems(menuItems: MenuItems) {
|
||||
return menuItems.map((menuItem) => {
|
||||
return {
|
||||
...menuItem,
|
||||
links: menuItem.links.map((link) => {
|
||||
const page = link.page.edges[0].node
|
||||
let originalUrl = undefined
|
||||
if (
|
||||
page.__typename === PageLinkEnum.ContentPage ||
|
||||
page.__typename === PageLinkEnum.LoyaltyPage
|
||||
) {
|
||||
if (page.web.original_url) {
|
||||
originalUrl = page.web.original_url
|
||||
}
|
||||
}
|
||||
return {
|
||||
lang: page.system.locale,
|
||||
linkText: link.link_text ? link.link_text : page.title,
|
||||
uid: page.system.uid,
|
||||
url: removeMultipleSlashes(`/${page.system.locale}/${page.url}`),
|
||||
originalUrl,
|
||||
}
|
||||
}),
|
||||
}
|
||||
|
||||
if ("sub_items" in item) {
|
||||
menuItem.subItems = mapMenuItems(item.sub_items)
|
||||
}
|
||||
|
||||
return menuItem
|
||||
})
|
||||
}
|
||||
|
||||
export const navigationQueryRouter = router({
|
||||
get: contentstackProcedure.query(async function ({ ctx }) {
|
||||
get: contentstackBaseProcedure.query(async function ({ ctx }) {
|
||||
const { lang } = ctx
|
||||
|
||||
const refsResponse = await request<GetNavigationMyPagesRefsData>(
|
||||
@@ -102,7 +108,7 @@ export const navigationQueryRouter = router({
|
||||
validatedMyPagesNavigation.data.all_navigation_my_pages.items[0]
|
||||
|
||||
const nav = {
|
||||
items: mapMenuItems(menuItem.items),
|
||||
menuItems: mapMenuItems(menuItem.menu_items),
|
||||
title: menuItem.title,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user