Feat/BOOK-240 hero video

Approved-by: Chuma Mcphoy (We Ahead)
Approved-by: Christel Westerberg
This commit is contained in:
Erik Tiekstra
2025-12-11 08:35:27 +00:00
parent cd8b30f2ec
commit f06e466827
33 changed files with 727 additions and 122 deletions

View File

@@ -11,3 +11,12 @@ export const systemSchema = z.object({
export interface System {
system: z.output<typeof systemSchema>
}
export const assetSystemSchema = z.object({
content_type_uid: z.string(),
uid: z.string(),
})
export interface AssetSystem {
system: z.output<typeof assetSystemSchema>
}

View File

@@ -0,0 +1,75 @@
import { z } from "zod"
import { Lang } from "@scandic-hotels/common/constants/language"
import { focalPointSchema } from "@scandic-hotels/common/utils/focalPoint"
import { assetSystemSchema } from "./system"
export const videoSchema = z.object({
sourceConnection: z.object({
edges: z.array(
z.object({
node: z.object({
url: z.string().url(),
}),
})
),
}),
focal_point: focalPointSchema.nullish(),
captions: z.array(
z.object({
is_default: z.boolean(),
fileConnection: z.object({
edges: z.array(
z.object({
node: z.object({
url: z.string().url(),
}),
})
),
}),
language: z.nativeEnum(Lang),
})
),
})
export const transformedVideoSchema = videoSchema
.nullish()
.transform((video) => {
const src = video?.sourceConnection.edges[0]?.node.url || ""
if (!video || !src) {
return null
}
const captions = video.captions
.filter((caption) => caption.fileConnection.edges[0]?.node.url)
.map((caption) => ({
src: caption.fileConnection.edges[0]?.node.url || "",
srcLang: caption.language,
isDefault: caption.is_default,
}))
return {
src,
focalPoint: video.focal_point
? { x: video.focal_point.x, y: video.focal_point.y }
: { x: 50, y: 50 },
captions,
}
})
export const videoRefSchema = z.object({
sourceConnection: z.object({
edges: z.array(
z.object({
node: z.object({
system: assetSystemSchema,
}),
})
),
}),
})
export type Video = z.output<typeof transformedVideoSchema>
export type VideoCaptions = NonNullable<Video>["captions"]