feat(SW-2541): Adjust for ImageVault custom field return types changes
Approved-by: Bianca Widstam Approved-by: Matilda Landström
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
import { removeMultipleSlashes } from "@scandic-hotels/common/utils/url"
|
||||
|
||||
import { HotelPageEnum } from "../../../../types/hotelPageEnum"
|
||||
import { tempImageVaultAssetSchema } from "../imageVault"
|
||||
import {
|
||||
collectionPageRefSchema,
|
||||
collectionPageSchema,
|
||||
@@ -18,7 +18,7 @@ export const activitiesCardSchema = z.object({
|
||||
.default(HotelPageEnum.ContentStack.blocks.ActivitiesCard),
|
||||
upcoming_activities_card: z
|
||||
.object({
|
||||
background_image: tempImageVaultAssetSchema,
|
||||
background_image: transformedImageVaultAssetSchema,
|
||||
body_text: z.string(),
|
||||
cta_text: z.string(),
|
||||
sidepeek_cta_text: z.string(),
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
import { removeMultipleSlashes } from "@scandic-hotels/common/utils/url"
|
||||
|
||||
import { BlocksEnums } from "../../../../types/blocksEnum"
|
||||
import { tempImageVaultAssetSchema } from "../imageVault"
|
||||
import { campaignPageRefSchema } from "../pageLinks"
|
||||
|
||||
export const campaignPageCardSchema = z.object({
|
||||
image: tempImageVaultAssetSchema,
|
||||
image: transformedImageVaultAssetSchema,
|
||||
heading: z.string(),
|
||||
text: z.string(),
|
||||
})
|
||||
@@ -29,7 +29,7 @@ export const allCampaignsSchema = z.object({
|
||||
url: z.string(),
|
||||
card_content: z
|
||||
.object({
|
||||
image: tempImageVaultAssetSchema,
|
||||
image: transformedImageVaultAssetSchema,
|
||||
heading: z.string().nullish(),
|
||||
text: z.string().nullish(),
|
||||
})
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import { CardsEnum } from "../../../../../types/cardsEnum"
|
||||
import { tempImageVaultAssetSchema } from "../../imageVault"
|
||||
import { systemSchema } from "../../system"
|
||||
import { buttonSchema } from "../utils/buttonLinkSchema"
|
||||
import { linkConnectionRefsSchema } from "../utils/linkConnection"
|
||||
@@ -10,7 +11,7 @@ export const contentCardSchema = z.object({
|
||||
__typename: z.literal(CardsEnum.ContentCard),
|
||||
title: z.string(),
|
||||
heading: z.string(),
|
||||
image: tempImageVaultAssetSchema,
|
||||
image: transformedImageVaultAssetSchema,
|
||||
body_text: z.string(),
|
||||
promo_text: z.string().optional(),
|
||||
has_card_link: z.boolean(),
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import { CardsEnum } from "../../../../../types/cardsEnum"
|
||||
import { tempImageVaultAssetSchema } from "../../imageVault"
|
||||
import { systemSchema } from "../../system"
|
||||
import { buttonSchema } from "../utils/buttonLinkSchema"
|
||||
import { linkConnectionRefsSchema } from "../utils/linkConnection"
|
||||
@@ -19,7 +20,7 @@ export const infoCardBlockSchema = z.object({
|
||||
scripted_top_title: z.string().optional(),
|
||||
heading: z.string().optional().default(""),
|
||||
body_text: z.string().optional().default(""),
|
||||
image: tempImageVaultAssetSchema,
|
||||
image: transformedImageVaultAssetSchema,
|
||||
theme: z.enum(INFO_CARD_THEMES).nullable(),
|
||||
title: z.string().optional(),
|
||||
primary_button: buttonSchema.optional().nullable(),
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import { CardsEnum } from "../../../../../types/cardsEnum"
|
||||
import { tempImageVaultAssetSchema } from "../../imageVault"
|
||||
import { systemSchema } from "../../system"
|
||||
import { buttonSchema } from "../utils/buttonLinkSchema"
|
||||
import { linkConnectionRefsSchema } from "../utils/linkConnection"
|
||||
@@ -11,7 +12,7 @@ export const loyaltyCardBlockSchema = z.object({
|
||||
body_text: z.string().optional(),
|
||||
heading: z.string().optional().default(""),
|
||||
// JSON - ImageVault Image
|
||||
image: tempImageVaultAssetSchema,
|
||||
image: transformedImageVaultAssetSchema,
|
||||
link: buttonSchema,
|
||||
system: systemSchema,
|
||||
title: z.string().optional(),
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import { CardsEnum } from "../../../../../types/cardsEnum"
|
||||
import { tempImageVaultAssetSchema } from "../../imageVault"
|
||||
import {
|
||||
accountPageSchema,
|
||||
campaignOverviewPageSchema,
|
||||
@@ -26,7 +27,7 @@ export const teaserCardBlockSchema = z.object({
|
||||
__typename: z.literal(CardsEnum.TeaserCard),
|
||||
heading: z.string().default(""),
|
||||
body_text: z.string().default(""),
|
||||
image: tempImageVaultAssetSchema,
|
||||
image: transformedImageVaultAssetSchema,
|
||||
primary_button: buttonSchema,
|
||||
secondary_button: buttonSchema,
|
||||
has_primary_button: z.boolean().default(false),
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import { scriptedCardThemeEnum } from "../../../../enums/scriptedCard"
|
||||
import { BlocksEnums } from "../../../../types/blocksEnum"
|
||||
import {
|
||||
CardsGridEnum,
|
||||
CardsGridLayoutEnum,
|
||||
} from "../../../../types/cardsGridEnum"
|
||||
import { tempImageVaultAssetSchema } from "../imageVault"
|
||||
import { systemSchema } from "../system"
|
||||
import {
|
||||
infoCardBlockRefsSchema,
|
||||
@@ -28,7 +29,7 @@ import { linkConnectionRefsSchema } from "./utils/linkConnection"
|
||||
export const cardBlockSchema = z.object({
|
||||
__typename: z.literal(CardsGridEnum.cards.Card),
|
||||
// JSON - ImageVault Image
|
||||
background_image: tempImageVaultAssetSchema,
|
||||
background_image: transformedImageVaultAssetSchema,
|
||||
body_text: z.string().optional().default(""),
|
||||
has_primary_button: z.boolean().default(false),
|
||||
has_secondary_button: z.boolean().default(false),
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import * as pageLinks from "../../../../routers/contentstack/schemas/pageLinks"
|
||||
import { BlocksEnums } from "../../../../types/blocksEnum"
|
||||
import { tempImageVaultAssetSchema } from "../imageVault"
|
||||
import { systemSchema } from "../system"
|
||||
import { buttonSchema } from "./utils/buttonLinkSchema"
|
||||
|
||||
@@ -13,7 +14,7 @@ export const fullWidthCampaignSchema = z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
background_image: tempImageVaultAssetSchema,
|
||||
background_image: transformedImageVaultAssetSchema,
|
||||
heading: z.string().optional(),
|
||||
body_text: z.string().optional(),
|
||||
scripted_top_title: z.string().optional(),
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import { ContentEnum } from "../../../../types/content"
|
||||
import { tempImageVaultAssetSchema } from "../imageVault"
|
||||
import { systemSchema } from "../system"
|
||||
|
||||
export const imageContainerSchema = z.object({
|
||||
__typename: z.literal(ContentEnum.blocks.ImageContainer),
|
||||
// JSON - ImageVault Image
|
||||
image_left: tempImageVaultAssetSchema,
|
||||
// JSON - ImageVault Image
|
||||
image_right: tempImageVaultAssetSchema,
|
||||
image_left: transformedImageVaultAssetSchema,
|
||||
image_right: transformedImageVaultAssetSchema,
|
||||
system: systemSchema,
|
||||
title: z.string().optional(),
|
||||
})
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import { BlocksEnums } from "../../../../types/blocksEnum"
|
||||
import { tempImageVaultAssetSchema } from "../imageVault"
|
||||
import { buttonSchema } from "./utils/buttonLinkSchema"
|
||||
import { linkConnectionRefsSchema } from "./utils/linkConnection"
|
||||
|
||||
@@ -11,7 +12,7 @@ export const joinScandicFriendsSchema = z.object({
|
||||
scripted_top_title: z.string(),
|
||||
title: z.string(),
|
||||
preamble: z.string(),
|
||||
image: tempImageVaultAssetSchema,
|
||||
image: transformedImageVaultAssetSchema,
|
||||
show_usp: z.boolean().default(false),
|
||||
usp: z.array(z.string()),
|
||||
has_primary_button: z.boolean().default(false),
|
||||
|
||||
@@ -1,163 +0,0 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { insertResponseToImageVaultAsset } from "../../../utils/imageVault"
|
||||
|
||||
import type { ImageVaultAssetResponse } from "../../../types/imageVault"
|
||||
|
||||
const metaData = z.object({
|
||||
DefinitionType: z.number().nullable().optional(),
|
||||
Description: z.string().nullable(),
|
||||
LanguageId: z.number().nullable(),
|
||||
MetadataDefinitionId: z.number(),
|
||||
Name: z.string(),
|
||||
Value: z.string().nullable(),
|
||||
})
|
||||
|
||||
export const focalPointSchema = z.object({
|
||||
x: z.number(),
|
||||
y: z.number(),
|
||||
})
|
||||
|
||||
/**
|
||||
* Defines a media asset, original or conversion
|
||||
*/
|
||||
const mediaConversion = z.object({
|
||||
/**
|
||||
* Aspect ratio of the conversion
|
||||
*/
|
||||
AspectRatio: z.number(),
|
||||
/**
|
||||
* Content type of the conversion
|
||||
*/
|
||||
ContentType: z.string(),
|
||||
/**
|
||||
* Aspect ratio of the selected/requested format
|
||||
*/
|
||||
FormatAspectRatio: z.number(),
|
||||
/**
|
||||
* Height of the selected/requested format
|
||||
*/
|
||||
FormatHeight: z.number(),
|
||||
/**
|
||||
* Width of the selected/requested format
|
||||
*/
|
||||
FormatWidth: z.number(),
|
||||
/**
|
||||
* Height, in pixels, of the conversion
|
||||
*/
|
||||
Height: z.number(),
|
||||
/**
|
||||
* Html representing the conversion
|
||||
*/
|
||||
Html: z.string(),
|
||||
/**
|
||||
* Id of the selected media format
|
||||
*/
|
||||
MediaFormatId: z.number(),
|
||||
/**
|
||||
* Name of the media format
|
||||
*/
|
||||
MediaFormatName: z.string(),
|
||||
/**
|
||||
* Name of the conversion
|
||||
*/
|
||||
Name: z.string(),
|
||||
/**
|
||||
* The url to the conversion
|
||||
*/
|
||||
Url: z.string(),
|
||||
/**
|
||||
* Width, in pixels, of the conversion
|
||||
*/
|
||||
Width: z.number(),
|
||||
})
|
||||
|
||||
/**
|
||||
* The response from ImageVault when inserting an asset
|
||||
*/
|
||||
export const imageVaultAssetSchema = z.object({
|
||||
/**
|
||||
* The media item id of the asset
|
||||
*/
|
||||
Id: z.number(),
|
||||
/**
|
||||
* The id of the vault where the asset resides
|
||||
*/
|
||||
VaultId: z.number(),
|
||||
/**
|
||||
* The name of the asset
|
||||
*/
|
||||
Name: z.string(),
|
||||
/**
|
||||
* The conversion selected by the user. Is an array but will only contain one object
|
||||
*/
|
||||
MediaConversions: z.array(mediaConversion),
|
||||
Metadata: z.array(metaData),
|
||||
/**
|
||||
* Date when the asset was added to ImageVault
|
||||
*/
|
||||
DateAdded: z.string(),
|
||||
/**
|
||||
* Name of the user that added the asset to ImageVault
|
||||
*/
|
||||
AddedBy: z.string(),
|
||||
FocalPoint: focalPointSchema.optional(),
|
||||
})
|
||||
|
||||
export const imageVaultAssetTransformedSchema = imageVaultAssetSchema.transform(
|
||||
(rawData) => {
|
||||
const alt = rawData.Metadata?.find((meta) =>
|
||||
meta.Name.includes("AltText_")
|
||||
)?.Value
|
||||
|
||||
const caption = rawData.Metadata?.find((meta) =>
|
||||
meta.Name.includes("Title_")
|
||||
)?.Value
|
||||
const mediaConversion = rawData.MediaConversions[0]
|
||||
const aspectRatio =
|
||||
mediaConversion.FormatAspectRatio ||
|
||||
mediaConversion.AspectRatio ||
|
||||
mediaConversion.Width / mediaConversion.Height
|
||||
|
||||
return {
|
||||
url: mediaConversion.Url,
|
||||
id: rawData.Id,
|
||||
meta: {
|
||||
alt,
|
||||
caption,
|
||||
},
|
||||
title: rawData.Name,
|
||||
dimensions: {
|
||||
width: mediaConversion.Width,
|
||||
height: mediaConversion.Height,
|
||||
aspectRatio,
|
||||
},
|
||||
focalPoint: rawData.FocalPoint || { x: 50, y: 50 },
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
export const tempImageVaultAssetSchema = imageVaultAssetSchema
|
||||
.nullable()
|
||||
.optional()
|
||||
.or(
|
||||
// Temp since there is a bug in Contentstack
|
||||
// sending empty objects when there has been an
|
||||
// image selected previously but has since been
|
||||
// deleted
|
||||
z.object({})
|
||||
)
|
||||
.transform((data) => {
|
||||
if (data) {
|
||||
if ("Name" in data) {
|
||||
return makeImageVaultImage(data)
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
})
|
||||
|
||||
function makeImageVaultImage(image: any) {
|
||||
return image && !!Object.keys(image).length
|
||||
? insertResponseToImageVaultAsset(image as ImageVaultAssetResponse)
|
||||
: undefined
|
||||
}
|
||||
Reference in New Issue
Block a user