fix(SW-2500): Fixed no image gives error on confirmation and booking page * fix(SW-2500): Fixed no image gives error on confirmation and booking page Approved-by: Anton Gunnarsson Approved-by: Matilda Landström
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
"use client"
|
|
|
|
import NextImage, { type ImageLoaderProps } from "next/image"
|
|
|
|
import ImageFallback from "./ImageFallback"
|
|
|
|
import type { CSSProperties } from "react"
|
|
|
|
import type { ImageProps } from "@/types/components/image"
|
|
|
|
function imageLoader({ quality, src, width }: ImageLoaderProps) {
|
|
const isAbsoluteUrl = src.startsWith("https://") || src.startsWith("http://")
|
|
const hasQS = src.indexOf("?") !== -1
|
|
|
|
if (isAbsoluteUrl) {
|
|
return `https://img.scandichotels.com/.netlify/images?url=${src}&w=${width}${quality ? "&q=" + quality : ""}`
|
|
}
|
|
|
|
return `${src}${hasQS ? "&" : "?"}w=${width}${quality ? "&q=" + quality : ""}`
|
|
}
|
|
|
|
// Next/Image adds & instead of ? before the params
|
|
export default function Image({ focalPoint, style, ...props }: ImageProps) {
|
|
const styles: CSSProperties = focalPoint
|
|
? {
|
|
objectFit: "cover",
|
|
objectPosition: `${focalPoint.x}% ${focalPoint.y}%`,
|
|
...style,
|
|
}
|
|
: { ...style }
|
|
|
|
if (!props.src) {
|
|
return <ImageFallback />
|
|
}
|
|
|
|
return <NextImage {...props} style={styles} loader={imageLoader} />
|
|
}
|