feat(WEB-304): remaning UI from design system primitives
This commit is contained in:
@@ -4,18 +4,47 @@ import { Lang } from "@/constants/languages"
|
||||
|
||||
import { PageLinkEnum } from "@/types/requests/pageLinks"
|
||||
|
||||
const node = z.object({
|
||||
system: z.object({
|
||||
locale: z.nativeEnum(Lang),
|
||||
uid: z.string(),
|
||||
}),
|
||||
title: z.string(),
|
||||
url: z.string(),
|
||||
})
|
||||
|
||||
const web = z.object({
|
||||
original_url: z.string().optional(),
|
||||
})
|
||||
|
||||
const accountPageLink = z
|
||||
.object({
|
||||
__typename: z.literal(PageLinkEnum.AccountPage),
|
||||
})
|
||||
.merge(node)
|
||||
|
||||
const contentPageLink = z
|
||||
.object({
|
||||
__typename: z.literal(PageLinkEnum.ContentPage),
|
||||
web,
|
||||
})
|
||||
.merge(node)
|
||||
|
||||
const loyaltyPageLink = z
|
||||
.object({
|
||||
__typename: z.literal(PageLinkEnum.LoyaltyPage),
|
||||
web,
|
||||
})
|
||||
.merge(node)
|
||||
|
||||
const pageConnection = z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
__typename: z.nativeEnum(PageLinkEnum),
|
||||
system: z.object({
|
||||
locale: z.nativeEnum(Lang),
|
||||
uid: z.string(),
|
||||
}),
|
||||
title: z.string(),
|
||||
url: z.string(),
|
||||
}),
|
||||
node: z.discriminatedUnion("__typename", [
|
||||
accountPageLink,
|
||||
contentPageLink,
|
||||
loyaltyPageLink,
|
||||
]),
|
||||
})
|
||||
),
|
||||
})
|
||||
@@ -36,78 +65,58 @@ const pageConnectionRefs = z.object({
|
||||
|
||||
export const navigationRefsPayloadSchema = z.object({
|
||||
all_navigation_my_pages: z.object({
|
||||
items: z
|
||||
.array(
|
||||
z.object({
|
||||
items: z.array(
|
||||
z.object({
|
||||
__typename: z.string(),
|
||||
item: z.object({
|
||||
sub_items: z.array(
|
||||
z.object({
|
||||
__typename: z.string(),
|
||||
item: z.object({
|
||||
pageConnection: pageConnectionRefs,
|
||||
}),
|
||||
})
|
||||
),
|
||||
pageConnection: pageConnectionRefs,
|
||||
}),
|
||||
})
|
||||
),
|
||||
system: z.object({
|
||||
content_type_uid: z.string(),
|
||||
uid: z.string(),
|
||||
}),
|
||||
})
|
||||
)
|
||||
.refine(
|
||||
(input) => {
|
||||
return input.length === 1
|
||||
},
|
||||
{
|
||||
message: `Expected all_navigation_my_pages items to only contain 1 in navigationRefsPayloadSchema`,
|
||||
}
|
||||
),
|
||||
items: z.array(
|
||||
z.object({
|
||||
menu_items: z.array(
|
||||
z.object({
|
||||
links: z.array(
|
||||
z.object({
|
||||
page: pageConnectionRefs,
|
||||
})
|
||||
),
|
||||
})
|
||||
),
|
||||
system: z.object({
|
||||
content_type_uid: z.string(),
|
||||
uid: z.string(),
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
|
||||
export type GetNavigationMyPagesRefsData = z.infer<
|
||||
typeof navigationRefsPayloadSchema
|
||||
>
|
||||
|
||||
const menuItems = z.array(
|
||||
z.object({
|
||||
display_sign_out_link: z.boolean(),
|
||||
links: z.array(
|
||||
z.object({
|
||||
link_text: z.string().default(""),
|
||||
page: pageConnection,
|
||||
})
|
||||
),
|
||||
})
|
||||
)
|
||||
|
||||
export type MenuItems = z.infer<typeof menuItems>
|
||||
|
||||
export const navigationPayloadSchema = z.object({
|
||||
all_navigation_my_pages: z.object({
|
||||
items: z
|
||||
.array(
|
||||
z.object({
|
||||
items: z.array(
|
||||
z.object({
|
||||
item: z.object({
|
||||
link_text: z.string().default(""),
|
||||
pageConnection,
|
||||
sub_items: z.array(
|
||||
z.object({
|
||||
item: z.object({
|
||||
link_text: z.string().default(""),
|
||||
pageConnection,
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
),
|
||||
title: z.string(),
|
||||
})
|
||||
)
|
||||
.refine(
|
||||
(input) => {
|
||||
return input.length === 1
|
||||
},
|
||||
{
|
||||
message: `Expected all_navigation_my_pages items to only contain 1 in navigationPayloadSchema`,
|
||||
}
|
||||
),
|
||||
items: z.array(
|
||||
z.object({
|
||||
menu_items: menuItems,
|
||||
title: z.string(),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
|
||||
const baseMenuItem = z.object({
|
||||
export type GetNavigationMyPagesData = z.infer<typeof navigationPayloadSchema>
|
||||
|
||||
const link = z.object({
|
||||
lang: z.nativeEnum(Lang),
|
||||
linkText: z.string(),
|
||||
uid: z.string(),
|
||||
@@ -116,12 +125,11 @@ const baseMenuItem = z.object({
|
||||
})
|
||||
|
||||
export const getNavigationSchema = z.object({
|
||||
items: z.array(
|
||||
z
|
||||
.object({
|
||||
subItems: z.array(baseMenuItem),
|
||||
})
|
||||
.merge(baseMenuItem)
|
||||
menuItems: z.array(
|
||||
z.object({
|
||||
display_sign_out_link: z.boolean(),
|
||||
links: z.array(link),
|
||||
})
|
||||
),
|
||||
title: z.string(),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user