fix(LOY-400): made contentstack data optional so the whole page does not crash if it's empty. * fix(LOY-400): made contentstack data optional so the whole page does not crash if it's empty. * Merged in fix/LOY-400-make-contentstack-data-optional-2 (pull request #3269) Fix/LOY-400 make contentstack data optional 2 * Test * . * Correct ref tag * refactor * Correct key * fix(LOY-400): cleaned up Approved-by: Linus Flood Approved-by: Matilda Landström
73 lines
1.9 KiB
TypeScript
73 lines
1.9 KiB
TypeScript
import { z } from "zod"
|
|
|
|
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
|
import { IconName } from "@scandic-hotels/design-system/Icons/iconName"
|
|
|
|
import {
|
|
linkConnectionRefs,
|
|
linkConnectionSchema,
|
|
} from "../schemas/linkConnection"
|
|
import { systemSchema } from "../schemas/system"
|
|
|
|
export type UsePointsModalData = z.output<typeof usePointsModalSchema>
|
|
export type UsePointsModalRefsData = z.output<typeof usePointsModalRefsSchema>
|
|
type LinkGroupItem = z.infer<typeof linkGroupItemSchema>
|
|
|
|
const linkGroupItemSchema = z.intersection(
|
|
z.object({
|
|
link_text: z.string().default(""),
|
|
is_contentstack_link: z.boolean(),
|
|
illustration: z.nativeEnum(IconName).nullish(),
|
|
illustration_size: z
|
|
.enum(["small", "medium", "large"])
|
|
.nullish()
|
|
.default("large"),
|
|
external_link: z
|
|
.object({
|
|
href: z.string().default(""),
|
|
})
|
|
.optional(),
|
|
}),
|
|
linkConnectionSchema
|
|
)
|
|
|
|
const usePointsModalItemsSchema = z.object({
|
|
image: transformedImageVaultAssetSchema,
|
|
link_group: z.array(linkGroupItemSchema).transform((links: LinkGroupItem[]) =>
|
|
links.map((link) => ({
|
|
text: link.link_text || "",
|
|
isExternal: !link.is_contentstack_link,
|
|
href: link.is_contentstack_link
|
|
? link.link?.url || ""
|
|
: link.external_link?.href || "",
|
|
illustration: link.illustration
|
|
? {
|
|
illustration: link.illustration,
|
|
size: link.illustration_size || "large",
|
|
}
|
|
: undefined,
|
|
}))
|
|
),
|
|
})
|
|
|
|
export const usePointsModalSchema = z.object({
|
|
all_usepointsmodal: z
|
|
.object({
|
|
items: z.array(usePointsModalItemsSchema).optional(),
|
|
})
|
|
.optional(),
|
|
})
|
|
|
|
export const usePointsModalRefsSchema = z.object({
|
|
all_usepointsmodal: z
|
|
.object({
|
|
items: z.array(
|
|
z.object({
|
|
link_group: z.array(linkConnectionRefs),
|
|
system: systemSchema,
|
|
})
|
|
),
|
|
})
|
|
.optional(),
|
|
})
|