diff --git a/apps/scandic-web/components/ContentType/HotelPage/SidePeeks/WellnessAndExercise/Facility/utils.ts b/apps/scandic-web/components/ContentType/HotelPage/SidePeeks/WellnessAndExercise/Facility/utils.ts index bd5c9b7e6..9b693831d 100644 --- a/apps/scandic-web/components/ContentType/HotelPage/SidePeeks/WellnessAndExercise/Facility/utils.ts +++ b/apps/scandic-web/components/ContentType/HotelPage/SidePeeks/WellnessAndExercise/Facility/utils.ts @@ -41,40 +41,24 @@ export async function translateWellnessDetails({ case HealthFacilitiesEnum.OutdoorPool: case HealthFacilitiesEnum.IndoorPool: - return details - .map(({ name, value }) => { - switch (name) { - case IndoorPoolDetails.DepthFrom: - return intl.formatMessage( - { - defaultMessage: "Pool depth from: {value} m", - }, - { value: value } - ) - - case IndoorPoolDetails.DepthTo: - return intl.formatMessage( - { - defaultMessage: "Pool depth to: {value} m", - }, - { value: value } - ) - - case IndoorPoolDetails.Length: - return intl.formatMessage( - { - defaultMessage: "Pool length: {value} m", - }, - { value: value } - ) - case IndoorPoolDetails.Width: - return intl.formatMessage( - { - defaultMessage: "Pool width: {value} m", - }, - { value: value } - ) - /* TODO: Awaiting clarification from Content on how to handle these parts + const poolDepth = await getPoolDepthTranslation(details) + const poolTranslations = details.map(({ name, value }) => { + switch (name) { + case IndoorPoolDetails.Length: + return intl.formatMessage( + { + defaultMessage: "Pool length: {value} m", + }, + { value: value } + ) + case IndoorPoolDetails.Width: + return intl.formatMessage( + { + defaultMessage: "Pool width: {value} m", + }, + { value: value } + ) + /* TODO: Awaiting clarification from Content on how to handle these parts case OutdoorPoolDetails.OpenMonthFrom: if (type === HealthFacilitiesEnum.OutdoorPool) return intl.formatMessage( @@ -91,9 +75,13 @@ export async function translateWellnessDetails({ }, { value: value } )*/ - } - }) + } + }) + + return poolTranslations + .concat(poolDepth) .filter((d): d is string => !!d) + .sort() case HealthFacilitiesEnum.Gym: if ( @@ -121,8 +109,40 @@ export async function translateWellnessDetails({ } }) .filter((d): d is string => !!d) + .sort() default: console.warn(`Unsupported type given: ${type}`) } } + +async function getPoolDepthTranslation(details: WellnessDetails["details"]) { + const intl = await getIntl() + + const depthTo = details.find( + (d) => d.name === IndoorPoolDetails.DepthTo + )?.value + const depthFrom = details.find( + (d) => d.name === IndoorPoolDetails.DepthFrom + )?.value + + if (depthFrom && depthTo) { + return depthFrom !== depthTo + ? intl.formatMessage( + { defaultMessage: "Pool depth: {from}–{to} m" }, + { from: depthFrom, to: depthTo } + ) + : intl.formatMessage( + { defaultMessage: "Pool depth: {value} m" }, + { value: depthFrom } + ) + } + + if (depthFrom || depthTo) { + const value = depthFrom || depthTo + return intl.formatMessage( + { defaultMessage: "Pool depth: {value} m" }, + { value } + ) + } +}