feat(SW-66, SW-348): search functionality and ui
This commit is contained in:
@@ -5,6 +5,7 @@ import { Lang } from "@/constants/languages"
|
||||
import { removeMultipleSlashes } from "@/utils/url"
|
||||
|
||||
import { imageVaultAssetTransformedSchema } from "../schemas/imageVault"
|
||||
import { systemSchema } from "../schemas/system"
|
||||
|
||||
import { Image } from "@/types/image"
|
||||
|
||||
@@ -68,74 +69,81 @@ export type ContactFields = {
|
||||
footnote: string | null
|
||||
}
|
||||
|
||||
export const validateCurrentHeaderConfigSchema = z.object({
|
||||
all_current_header: z.object({
|
||||
items: z.array(
|
||||
z.object({
|
||||
frontpage_link_text: z.string(),
|
||||
logoConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
description: z.string().optional().nullable(),
|
||||
dimension: z.object({
|
||||
height: z.number(),
|
||||
width: z.number(),
|
||||
export const validateCurrentHeaderConfigSchema = z
|
||||
.object({
|
||||
all_current_header: z.object({
|
||||
items: z.array(
|
||||
z.object({
|
||||
frontpage_link_text: z.string(),
|
||||
logoConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
description: z.string().optional().nullable(),
|
||||
dimension: z.object({
|
||||
height: z.number(),
|
||||
width: z.number(),
|
||||
}),
|
||||
metadata: z.any().nullable(),
|
||||
system: z.object({
|
||||
uid: z.string(),
|
||||
}),
|
||||
title: z.string().optional().default(""),
|
||||
url: z.string().optional().default(""),
|
||||
}),
|
||||
metadata: z.any().nullable(),
|
||||
system: z.object({
|
||||
uid: z.string(),
|
||||
}),
|
||||
title: z.string().nullable(),
|
||||
url: z.string().nullable(),
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
menu: z.object({
|
||||
links: z.array(
|
||||
z.object({
|
||||
href: z.string(),
|
||||
title: z.string(),
|
||||
})
|
||||
),
|
||||
}),
|
||||
top_menu: z.object({
|
||||
links: z.array(
|
||||
z.object({
|
||||
link: z.object({
|
||||
})
|
||||
),
|
||||
}),
|
||||
menu: z.object({
|
||||
links: z.array(
|
||||
z.object({
|
||||
href: z.string(),
|
||||
title: z.string(),
|
||||
}),
|
||||
show_on_mobile: z.boolean(),
|
||||
sort_order_mobile: z.number(),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
})
|
||||
),
|
||||
}),
|
||||
top_menu: z.object({
|
||||
links: z.array(
|
||||
z.object({
|
||||
link: z.object({
|
||||
href: z.string(),
|
||||
title: z.string(),
|
||||
}),
|
||||
show_on_mobile: z.boolean(),
|
||||
sort_order_mobile: z.number(),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
if (!data.all_current_header.items.length) {
|
||||
return {
|
||||
header: null,
|
||||
}
|
||||
}
|
||||
const header = data.all_current_header.items[0]
|
||||
return {
|
||||
header: {
|
||||
frontpageLinkText: header.frontpage_link_text,
|
||||
logo: header.logoConnection.edges[0].node,
|
||||
menu: header.menu,
|
||||
topMenu: header.top_menu,
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
export type CurrentHeaderDataRaw = z.infer<
|
||||
typeof validateCurrentHeaderConfigSchema
|
||||
>
|
||||
|
||||
export type CurrentHeaderData = Omit<
|
||||
CurrentHeaderDataRaw["all_current_header"]["items"][0],
|
||||
"logoConnection"
|
||||
> & {
|
||||
logo: Image
|
||||
}
|
||||
export interface GetCurrentHeaderData
|
||||
extends z.input<typeof validateCurrentHeaderConfigSchema> {}
|
||||
export type HeaderData = z.output<typeof validateCurrentHeaderConfigSchema>
|
||||
|
||||
const validateCurrentHeaderRefConfigSchema = z.object({
|
||||
all_current_header: z.object({
|
||||
items: z.array(
|
||||
z.object({
|
||||
system: z.object({
|
||||
content_type_uid: z.string(),
|
||||
uid: z.string(),
|
||||
}),
|
||||
system: systemSchema,
|
||||
})
|
||||
),
|
||||
}),
|
||||
@@ -257,10 +265,7 @@ const validateCurrentFooterRefConfigSchema = z.object({
|
||||
all_current_footer: z.object({
|
||||
items: z.array(
|
||||
z.object({
|
||||
system: z.object({
|
||||
content_type_uid: z.string(),
|
||||
uid: z.string(),
|
||||
}),
|
||||
system: systemSchema,
|
||||
})
|
||||
),
|
||||
}),
|
||||
@@ -387,10 +392,7 @@ const pageConnectionRefs = z.object({
|
||||
.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
system: z.object({
|
||||
content_type_uid: z.string(),
|
||||
uid: z.string(),
|
||||
}),
|
||||
system: systemSchema,
|
||||
}),
|
||||
})
|
||||
)
|
||||
@@ -421,10 +423,7 @@ export const validateFooterRefConfigSchema = z.object({
|
||||
pageConnection: pageConnectionRefs,
|
||||
})
|
||||
),
|
||||
system: z.object({
|
||||
content_type_uid: z.string(),
|
||||
uid: z.string(),
|
||||
}),
|
||||
system: systemSchema,
|
||||
})
|
||||
)
|
||||
.length(1),
|
||||
@@ -437,10 +436,7 @@ const linkConnectionNodeSchema = z
|
||||
.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
system: z.object({
|
||||
uid: z.string(),
|
||||
locale: z.nativeEnum(Lang),
|
||||
}),
|
||||
system: systemSchema,
|
||||
url: z.string(),
|
||||
title: z.string(),
|
||||
web: z.object({
|
||||
@@ -595,10 +591,7 @@ const linkConnectionRefs = z.object({
|
||||
.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
system: z.object({
|
||||
content_type_uid: z.string(),
|
||||
uid: z.string(),
|
||||
}),
|
||||
system: systemSchema,
|
||||
}),
|
||||
})
|
||||
)
|
||||
@@ -656,10 +649,7 @@ export const getHeaderRefSchema = z.object({
|
||||
),
|
||||
})
|
||||
),
|
||||
system: z.object({
|
||||
content_type_uid: z.string(),
|
||||
uid: z.string(),
|
||||
}),
|
||||
system: systemSchema,
|
||||
})
|
||||
)
|
||||
.length(1),
|
||||
|
||||
@@ -4,13 +4,19 @@ import { GetContactConfig } from "@/lib/graphql/Query/ContactConfig.graphql"
|
||||
import {
|
||||
GetCurrentFooter,
|
||||
GetCurrentFooterRef,
|
||||
} from "@/lib/graphql/Query/CurrentFooter.graphql"
|
||||
} from "@/lib/graphql/Query/Current/Footer.graphql"
|
||||
import {
|
||||
GetCurrentHeader,
|
||||
GetCurrentHeaderRef,
|
||||
} from "@/lib/graphql/Query/CurrentHeader.graphql"
|
||||
import { GetFooter, GetFooterRef } from "@/lib/graphql/Query/Footer.graphql"
|
||||
import { GetHeader, GetHeaderRef } from "@/lib/graphql/Query/Header.graphql"
|
||||
} from "@/lib/graphql/Query/Current/Header.graphql"
|
||||
import {
|
||||
GetFooter,
|
||||
GetFooterRef,
|
||||
} from "@/lib/graphql/Query/Footer.graphql"
|
||||
import {
|
||||
GetHeader,
|
||||
GetHeaderRef,
|
||||
} from "@/lib/graphql/Query/Header.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
import { contentstackBaseProcedure, router } from "@/server/trpc"
|
||||
@@ -23,19 +29,18 @@ import {
|
||||
|
||||
import { langInput } from "./input"
|
||||
import {
|
||||
type GetCurrentHeaderData,
|
||||
type ContactConfigData,
|
||||
CurrentFooterDataRaw,
|
||||
CurrentFooterRefDataRaw,
|
||||
CurrentHeaderData,
|
||||
CurrentHeaderDataRaw,
|
||||
CurrentHeaderRefDataRaw,
|
||||
getHeaderRefSchema,
|
||||
getHeaderSchema,
|
||||
validateContactConfigSchema,
|
||||
validateCurrentFooterConfigSchema,
|
||||
validateCurrentHeaderConfigSchema,
|
||||
validateFooterConfigSchema,
|
||||
validateFooterRefConfigSchema,
|
||||
validateCurrentHeaderConfigSchema,
|
||||
} from "./output"
|
||||
import { getConnections, getFooterConnections } from "./utils"
|
||||
|
||||
@@ -357,7 +362,7 @@ export const baseQueryRouter = router({
|
||||
const currentHeaderUID =
|
||||
responseRef.data.all_current_header.items[0].system.uid
|
||||
// There's currently no error handling/validation for the responseRef, should it be added?
|
||||
const response = await request<CurrentHeaderDataRaw>(
|
||||
const response = await request<GetCurrentHeaderData>(
|
||||
GetCurrentHeader,
|
||||
{ locale: input.lang },
|
||||
{
|
||||
@@ -415,14 +420,8 @@ export const baseQueryRouter = router({
|
||||
query: { lang: input.lang },
|
||||
})
|
||||
)
|
||||
const logo =
|
||||
validatedHeaderConfig.data.all_current_header.items[0].logoConnection
|
||||
.edges?.[0]?.node
|
||||
|
||||
return {
|
||||
...validatedHeaderConfig.data.all_current_header.items[0],
|
||||
logo,
|
||||
} as CurrentHeaderData
|
||||
return validatedHeaderConfig.data
|
||||
}),
|
||||
currentFooter: contentstackBaseProcedure
|
||||
.input(langInput)
|
||||
|
||||
Reference in New Issue
Block a user