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:
@@ -12,7 +12,7 @@ import ContentCard from "@/components/ContentCard"
|
||||
|
||||
import styles from "./allCampaigns.module.css"
|
||||
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/trpc/types/imageVault"
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
interface AllCampaignsProps {
|
||||
heading: string
|
||||
|
||||
@@ -6,7 +6,7 @@ import Subtitle from "@scandic-hotels/design-system/Subtitle"
|
||||
|
||||
import styles from "./contentCard.module.css"
|
||||
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/trpc/types/imageVault"
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
interface ContentCardProps {
|
||||
link?: {
|
||||
|
||||
@@ -11,7 +11,7 @@ import { mapImageVaultImagesToGalleryImages } from "@/utils/imageGallery"
|
||||
|
||||
import styles from "./topImages.module.css"
|
||||
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/trpc/types/imageVault"
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
interface TopImageProps {
|
||||
images: ImageVaultAsset[]
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
import {
|
||||
type DeprecatedImageVaultAssetResponse,
|
||||
type ImageVaultAssetResponse,
|
||||
mapImageVaultAssetResponseToImageVaultAsset,
|
||||
mapInsertResponseToImageVaultAsset,
|
||||
} from "@scandic-hotels/common/utils/imageVault"
|
||||
import { removeMultipleSlashes } from "@scandic-hotels/common/utils/url"
|
||||
import Body from "@scandic-hotels/design-system/Body"
|
||||
import Caption from "@scandic-hotels/design-system/Caption"
|
||||
@@ -14,18 +20,15 @@ import {
|
||||
RTEItemTypeEnum,
|
||||
RTETypeEnum,
|
||||
} from "@scandic-hotels/trpc/types/RTEenums"
|
||||
import { insertResponseToImageVaultAsset } from "@scandic-hotels/trpc/utils/imageVault"
|
||||
|
||||
import BiroScript from "../TempDesignSystem/Text/BiroScript"
|
||||
import { hasAvailableParagraphFormat, hasAvailableULFormat } from "./utils"
|
||||
|
||||
import styles from "./jsontohtml.module.css"
|
||||
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/trpc/types/imageVault"
|
||||
|
||||
import type { EmbedByUid } from "@/types/components/deprecatedjsontohtml"
|
||||
import { EmbedEnum } from "@/types/requests/utils/embeds"
|
||||
import type { Attributes, RTEImageVaultAttrs } from "@/types/rte/attrs"
|
||||
import type { Attributes } from "@/types/rte/attrs"
|
||||
import {
|
||||
type RTEDefaultNode,
|
||||
type RTEImageNode,
|
||||
@@ -309,28 +312,11 @@ export const renderOptions: RenderOptions = {
|
||||
|
||||
if (entry?.node.__typename === EmbedEnum.ImageContainer) {
|
||||
if (entry.node.image_left && entry.node.image_right) {
|
||||
if ("dimensions" in entry.node.image_left) {
|
||||
// Only temp until all ImageVaultAssets are
|
||||
// handled in schema.transform()
|
||||
return (
|
||||
<ImageContainer
|
||||
leftImage={
|
||||
entry.node.image_left as unknown as ImageVaultAsset
|
||||
}
|
||||
rightImage={
|
||||
entry.node.image_right as unknown as ImageVaultAsset
|
||||
}
|
||||
/>
|
||||
)
|
||||
}
|
||||
const leftImage = insertResponseToImageVaultAsset(
|
||||
entry.node.image_left
|
||||
)
|
||||
const rightImage = insertResponseToImageVaultAsset(
|
||||
entry.node.image_right
|
||||
)
|
||||
return (
|
||||
<ImageContainer leftImage={leftImage} rightImage={rightImage} />
|
||||
<ImageContainer
|
||||
leftImage={entry.node.image_left}
|
||||
rightImage={entry.node.image_right}
|
||||
/>
|
||||
)
|
||||
}
|
||||
return null
|
||||
@@ -372,40 +358,46 @@ export const renderOptions: RenderOptions = {
|
||||
},
|
||||
|
||||
[RTETypeEnum.ImageVault]: (node: RTEImageNode) => {
|
||||
if ("attrs" in node) {
|
||||
const type = node.type
|
||||
if (type === RTETypeEnum.ImageVault) {
|
||||
const attrs = node.attrs as RTEImageVaultAttrs
|
||||
let image = undefined
|
||||
if ("dimensions" in attrs) {
|
||||
image = attrs
|
||||
} else {
|
||||
image = insertResponseToImageVaultAsset(attrs)
|
||||
}
|
||||
const alt = image.meta.alt ?? image.title
|
||||
|
||||
const width = attrs.width
|
||||
? parseInt(attrs.width.replaceAll("px", ""))
|
||||
: image.dimensions.width
|
||||
const props = extractPossibleAttributes(attrs)
|
||||
return (
|
||||
<section key={node.uid}>
|
||||
<Image
|
||||
alt={alt}
|
||||
className={styles.image}
|
||||
height={365}
|
||||
src={image.url}
|
||||
width={width}
|
||||
focalPoint={image.focalPoint}
|
||||
dimensions={image.dimensions}
|
||||
{...props}
|
||||
/>
|
||||
<Caption>{image.meta.caption}</Caption>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
const type = node.type
|
||||
if (!("attrs" in node) || type !== RTETypeEnum.ImageVault) {
|
||||
return null
|
||||
}
|
||||
|
||||
let image = undefined
|
||||
if ("imageVaultId" in node.attrs && "fileName" in node.attrs) {
|
||||
image = mapImageVaultAssetResponseToImageVaultAsset(
|
||||
node.attrs as unknown as ImageVaultAssetResponse
|
||||
)
|
||||
}
|
||||
|
||||
if ("Name" in node.attrs && "Id" in node.attrs) {
|
||||
image = mapInsertResponseToImageVaultAsset(
|
||||
node.attrs as unknown as DeprecatedImageVaultAssetResponse
|
||||
)
|
||||
}
|
||||
|
||||
if (!image) {
|
||||
return null
|
||||
}
|
||||
const alt = image.meta.alt ?? image.title
|
||||
const props = extractPossibleAttributes(node.attrs)
|
||||
|
||||
return (
|
||||
<section key={node.uid}>
|
||||
<Image
|
||||
alt={alt}
|
||||
className={styles.image}
|
||||
fill
|
||||
sizes="(min-width: 1367px) 800px, (max-width: 1366px) and (min-width: 1200px) 1200px, 100vw"
|
||||
src={image.url}
|
||||
focalPoint={image.focalPoint}
|
||||
dimensions={image.dimensions}
|
||||
{...props}
|
||||
/>
|
||||
<Caption>{image.meta.caption}</Caption>
|
||||
</section>
|
||||
)
|
||||
|
||||
return null
|
||||
},
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { FocalPoint, Image } from "@scandic-hotels/trpc/types/image"
|
||||
import type { FocalPoint } from "@scandic-hotels/common/utils/imageVault"
|
||||
import type { Image } from "@scandic-hotels/trpc/types/image"
|
||||
|
||||
export interface HeroProps {
|
||||
alt: string
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/trpc/types/imageVault"
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/common/utils/imageVault"
|
||||
import type { VariantProps } from "class-variance-authority"
|
||||
|
||||
import type { ApiImage } from "@/types/components/image"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/trpc/types/imageVault"
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/common/utils/imageVault"
|
||||
import type { VariantProps } from "class-variance-authority"
|
||||
|
||||
import type { loyaltyCardVariants } from "./variants"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/trpc/types/imageVault"
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/common/utils/imageVault"
|
||||
import type { VariantProps } from "class-variance-authority"
|
||||
|
||||
import type { CardProps } from "@/components/TempDesignSystem/Card/card"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { FocalPoint } from "@scandic-hotels/trpc/types/image"
|
||||
import type { FocalPoint } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
interface Dimensions {
|
||||
width: number
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/common/utils/imageVault"
|
||||
import type { TeaserCard } from "@scandic-hotels/trpc/types/blocks"
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/trpc/types/imageVault"
|
||||
import type { VariantProps } from "class-variance-authority"
|
||||
|
||||
import type { CardProps } from "@/components/TempDesignSystem/Card/card"
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { EmbedEnum } from "./utils/embeds"
|
||||
import { PageLink, PageLinkWithOriginalUrl } from "./utils/pageLink"
|
||||
import { TypenameInterface } from "./utils/typename"
|
||||
|
||||
import type { ImageContainer } from "./imageContainer"
|
||||
import type { SysAsset } from "./utils/asset"
|
||||
import type { EmbedEnum } from "./utils/embeds"
|
||||
import type { PageLink, PageLinkWithOriginalUrl } from "./utils/pageLink"
|
||||
import type { TypenameInterface } from "./utils/typename"
|
||||
|
||||
interface AccountPage
|
||||
extends TypenameInterface<EmbedEnum.AccountPage>,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/common/utils/imageVault"
|
||||
import type { System } from "@scandic-hotels/trpc/routers/contentstack/schemas/system"
|
||||
import type { ImageVaultAssetResponse } from "@scandic-hotels/trpc/types/imageVault"
|
||||
|
||||
import type { EmbedEnum } from "./utils/embeds"
|
||||
import type { TypenameInterface } from "./utils/typename"
|
||||
@@ -7,6 +7,6 @@ import type { TypenameInterface } from "./utils/typename"
|
||||
export interface ImageContainer
|
||||
extends TypenameInterface<EmbedEnum.ImageContainer>,
|
||||
System {
|
||||
image_left?: ImageVaultAssetResponse
|
||||
image_right?: ImageVaultAssetResponse
|
||||
image_left?: ImageVaultAsset
|
||||
image_right?: ImageVaultAsset
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import type {
|
||||
ImageVaultAsset,
|
||||
ImageVaultAssetResponse,
|
||||
} from "@scandic-hotels/trpc/types/imageVault"
|
||||
} from "@scandic-hotels/common/utils/imageVault"
|
||||
import type {
|
||||
EmbedTypesEnum,
|
||||
RTEItemType,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/trpc/types/imageVault"
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/common/utils/imageVault"
|
||||
|
||||
import type { EmbedTypesEnum, RTEItemType, RTEItemTypeEnum } from "./enums"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/common/utils/imageVault"
|
||||
import type { ApiImage } from "@scandic-hotels/trpc/types/hotel"
|
||||
import type { ImageVaultAsset } from "@scandic-hotels/trpc/types/imageVault"
|
||||
|
||||
import type { GalleryImage } from "@/types/components/imageGallery"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user